Skip to content

Commit dd2d70e

Browse files
feat: add internal pages (#1058)
1 parent 9c3d0d7 commit dd2d70e

File tree

5 files changed

+133
-105
lines changed

5 files changed

+133
-105
lines changed

.wp-env.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"env": {
99
"tests": {
1010
"config": {
11-
"CYPRESS_TESTING": true
11+
"E2E_TESTING": true
1212
},
1313
"mappings": {
1414
"wp-content/themes/gutenberg-test-themes/twentytwentyone": "https://downloads.wordpress.org/theme/twentytwentyone.2.1.zip",

feedzy-rss-feed.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ function feedzy_import_job_logs( $name, $msg, $type ) {
284284
}
285285
add_action( 'themeisle_log_event', 'feedzy_import_job_logs', 20, 3 );
286286

287-
add_filter( 'themeisle_sdk_enable_telemetry', '__return_true' );
288-
289287
add_filter(
290288
'feedzy_rss_feeds_float_widget_metadata', function () {
291289
return array(

includes/admin/feedzy-rss-feeds-admin.php

Lines changed: 128 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,50 @@ class Feedzy_Rss_Feeds_Admin extends Feedzy_Rss_Feeds_Admin_Abstract {
5959
public function __construct( $plugin_name, $version ) {
6060
$this->plugin_name = $plugin_name;
6161
$this->version = $version;
62+
63+
if ( ! defined( 'E2E_TESTING' ) ) {
64+
add_filter(
65+
'themeisle-sdk/survey/' . $this->plugin_name,
66+
function( $data, $page_slug ) {
67+
68+
// Show survey only on `Help us improve` tab on Support page.
69+
if ( strpos( $page_slug, 'support' ) !== false && $page_slug !== 'support-improve' ) {
70+
return $data;
71+
}
72+
73+
return $this->get_survey_data();
74+
},
75+
10,
76+
2
77+
);
78+
}
79+
80+
/**
81+
* Load SDK dependencies.
82+
*/
83+
add_filter( 'themeisle_internal_page', function( $product_name, $page_slug ) {
84+
if ( $product_name !== $this->plugin_name ) {
85+
return;
86+
}
87+
88+
if ( in_array( $page_slug, array( 'imports', 'categories' ), true ) ) {
89+
$this->add_banner_anchor();
90+
}
91+
92+
if ( in_array( $page_slug, array( 'imports', 'categories', 'settings' ), true ) ) {
93+
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
94+
if ( self::plan_category( $license_data ) <= 1 ) {
95+
do_action( 'themeisle_sdk_load_banner', 'feedzy' );
96+
}
97+
}
98+
99+
if (
100+
in_array( $page_slug, array( 'imports', 'new-category', 'settings' ), true )
101+
&& 'yes' === get_option( 'feedzy_rss_feeds_logger_flag', false )
102+
) {
103+
$this->enable_telemetry();
104+
}
105+
}, 10, 2 );
62106
}
63107

64108
/**
@@ -116,21 +160,8 @@ public function enqueue_styles_admin() {
116160
return;
117161
}
118162

119-
$telemetry_enabled = get_option( 'feedzy_rss_feeds_logger_flag', false );
120-
if ( ! defined( 'TI_CYPRESS_TESTING' ) &&
121-
! empty( $telemetry_enabled ) &&
122-
(
123-
'feedzy_categories' === $screen->post_type ||
124-
'feedzy_page_feedzy-settings' === $screen->base ||
125-
'feedzy_imports' === $screen->post_type
126-
)
127-
) {
128-
wp_enqueue_script( $this->plugin_name . '_telemetry', FEEDZY_ABSURL . 'js/telemetry.js', array(), $this->version, true );
129-
}
130-
131163
if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base ) {
132-
$this->register_survey();
133-
$this->add_banner_anchor();
164+
$this->do_internal_page( 'imports' );
134165
}
135166

136167
if ( 'feedzy_categories' === $screen->post_type ) {
@@ -157,9 +188,6 @@ public function enqueue_styles_admin() {
157188
),
158189
)
159190
);
160-
161-
$this->register_survey();
162-
$this->add_banner_anchor();
163191
}
164192

165193
if ( 'feedzy_page_feedzy-settings' === $screen->base || 'feedzy_page_feedzy-integration' === $screen->base ) {
@@ -179,19 +207,6 @@ public function enqueue_styles_admin() {
179207
),
180208
)
181209
);
182-
183-
$this->register_survey();
184-
}
185-
186-
if (
187-
'feedzy_page_feedzy-settings' === $screen->base ||
188-
'feedzy_categories' === $screen->post_type ||
189-
( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base )
190-
) {
191-
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
192-
if ( self::plan_category( $license_data ) <= 1 ) {
193-
do_action( 'themeisle_sdk_load_banner', 'feedzy' );
194-
}
195210
}
196211

197212
$upsell_screens = array( 'feedzy-rss_page_feedzy-settings', 'feedzy-rss_page_feedzy-admin-menu-pro-upsell' );
@@ -238,13 +253,25 @@ public function enqueue_styles_admin() {
238253
wp_enqueue_style( 'wp-block-editor' );
239254

240255
wp_set_script_translations( $this->plugin_name . '_conditions', 'feedzy-rss-feeds' );
241-
242-
$this->register_survey();
256+
$this->enable_telemetry();
243257
}
244258
if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && feedzy_show_import_tour() ) ) {
245259
$asset_file = include FEEDZY_ABSPATH . '/build/onboarding/index.asset.php';
246260
wp_enqueue_script( $this->plugin_name . '_on_boarding', FEEDZY_ABSURL . 'build/onboarding/index.js', array_merge( $asset_file['dependencies'], array( 'wp-editor', 'wp-api' ) ), $asset_file['version'], true );
247261
wp_set_script_translations( $this->plugin_name . '_on_boarding', 'feedzy-rss-feeds' );
262+
$this->enable_telemetry();
263+
}
264+
265+
if ( 'feedzy_page_feedzy-settings' === $screen->base ) {
266+
$this->do_internal_page( 'settings' );
267+
}
268+
269+
if ( 'feedzy_page_feedzy-integration' === $screen->base ) {
270+
$this->do_internal_page( 'integrations' );
271+
}
272+
273+
if ( 'feedzy_categories' === $screen->post_type ) {
274+
$this->do_internal_page( 'add' === $screen->action ? 'new-category' : 'categories' );
248275
}
249276

250277
if ( ! in_array( $screen->base, $upsell_screens, true ) && strpos( $screen->id, 'feedzy' ) === false ) {
@@ -254,8 +281,6 @@ public function enqueue_styles_admin() {
254281
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
255282
if ( 'feedzy_page_feedzy-support' === $screen->base && ( isset( $_GET['tab'] ) && 'improve' === $_GET['tab'] ) || ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) {
256283

257-
$this->register_survey();
258-
259284
$asset_file = include FEEDZY_ABSPATH . '/build/feedback/index.asset.php';
260285
wp_enqueue_script( $this->plugin_name . '_feedback', FEEDZY_ABSURL . 'build/feedback/index.js', array_merge( $asset_file['dependencies'], array( 'wp-editor', 'wp-api', 'lodash' ) ), $asset_file['version'], true );
261286
wp_enqueue_style( 'wp-block-editor' );
@@ -272,6 +297,17 @@ public function enqueue_styles_admin() {
272297
wp_set_script_translations( $this->plugin_name . '_feedback', 'feedzy-rss-feeds' );
273298
}
274299

300+
if ( 'feedzy_page_feedzy-support' === $screen->base ) {
301+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
302+
$tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
303+
$suffix = ! empty( $tab ) ? '-' . $tab : '';
304+
$this->do_internal_page( 'support' . $suffix );
305+
}
306+
307+
if ( ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) {
308+
$this->do_internal_page( 'new-import' );
309+
}
310+
275311
if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base && feedzy_show_review_notice() ) {
276312
$asset_file = include FEEDZY_ABSPATH . '/build/review/index.asset.php';
277313
wp_enqueue_script( $this->plugin_name . '_review', FEEDZY_ABSURL . 'build/review/index.js', $asset_file['dependencies'], $asset_file['version'], true );
@@ -2026,70 +2062,53 @@ public static function plan_category( $license_data ) {
20262062
* @return array
20272063
* @see survey.js
20282064
*/
2029-
public function get_survery_metadata() {
2065+
public function get_survey_data() {
2066+
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
2067+
$integration_status = $this->api_license_status();
20302068

2031-
$user_id = 'feedzy_';
2032-
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
2069+
$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', time() ) ) / DAY_IN_SECONDS );
20332070

2034-
if ( ! empty( $license_data->key ) ) {
2035-
$user_id .= $license_data->key;
2036-
} else {
2037-
$user_id .= preg_replace( '/[^\w\d]*/', '', get_site_url() ); // Use a normalized version of the site URL as a user ID for free users.
2038-
}
2071+
$import_jobs_num = get_transient( 'feedzy_import_jobs_num' );
20392072

2040-
$integration_status = $this->api_license_status();
2073+
if ( false === $import_jobs_num ) {
2074+
$args = array(
2075+
'post_type' => 'feedzy_imports',
2076+
'posts_per_page' => 50,
2077+
'post_status' => array( 'publish', 'draft' ),
2078+
'fields' => 'ids',
2079+
'no_found_rows' => true,
2080+
'update_post_meta_cache' => false,
2081+
'update_post_term_cache' => false,
2082+
);
20412083

2042-
$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', 0 ) ) / DAY_IN_SECONDS );
2043-
$install_category = 0;
2044-
if ( 0 === $days_since_install || 1 === $days_since_install ) {
2045-
$install_category = 0;
2046-
} elseif ( 1 < $days_since_install && 8 > $days_since_install ) {
2047-
$install_category = 7;
2048-
} elseif ( 8 <= $days_since_install && 31 > $days_since_install ) {
2049-
$install_category = 30;
2050-
} elseif ( 30 < $days_since_install && 90 > $days_since_install ) {
2051-
$install_category = 90;
2052-
} elseif ( 90 <= $days_since_install ) {
2053-
$install_category = 91;
2054-
}
2055-
2056-
return array(
2057-
'userId' => $user_id,
2058-
'attributes' => array(
2059-
'free_version' => $this->version,
2060-
'pro_version' => defined( 'FEEDZY_PRO_VERSION' ) ? FEEDZY_PRO_VERSION : '',
2061-
'openai' => $integration_status['openaiStatus'] ? 'valid' : 'invalid',
2062-
'amazon' => $integration_status['amazonStatus'] ? 'valid' : 'invalid',
2063-
'spinnerchief' => $integration_status['spinnerChiefStatus'] ? 'valid' : 'invalid',
2064-
'wordai' => $integration_status['wordaiStatus'] ? 'valid' : 'invalid',
2065-
'plan' => $this->plan_category( $license_data ),
2066-
'days_since_install' => $install_category,
2067-
'license_status' => ! empty( $license_data->license ) ? $license_data->license : 'invalid',
2068-
),
2084+
$query = new WP_Query( $args );
2085+
$import_jobs_num = count( $query->posts );
2086+
set_transient( 'feedzy_import_jobs_num', $import_jobs_num, 50 >= $import_jobs_num ? WEEK_IN_SECONDS : HOUR_IN_SECONDS );
2087+
} else {
2088+
$import_jobs_num = intval( $import_jobs_num );
2089+
}
2090+
2091+
$survey_data = array(
2092+
'environmentId' => 'clskgehf78eu5podwdrnzciti',
2093+
'attributes' => array(
2094+
'free_version' => $this->version,
2095+
'pro_version' => defined( 'FEEDZY_PRO_VERSION' ) ? FEEDZY_PRO_VERSION : '',
2096+
'openai' => $integration_status['openaiStatus'] ? 'valid' : 'invalid',
2097+
'amazon' => $integration_status['amazonStatus'] ? 'valid' : 'invalid',
2098+
'spinnerchief' => $integration_status['spinnerChiefStatus'] ? 'valid' : 'invalid',
2099+
'wordai' => $integration_status['wordaiStatus'] ? 'valid' : 'invalid',
2100+
'plan' => $this->plan_category( $license_data ),
2101+
'install_days_number' => $days_since_install,
2102+
'license_status' => ! empty( $license_data->license ) ? $license_data->license : 'invalid',
2103+
'import_jobs_num' => $import_jobs_num
2104+
),
20692105
);
2070-
}
20712106

2072-
/**
2073-
* Register the survey script.
2074-
*
2075-
* It does register if we are in CI environment.
2076-
*
2077-
* @return void
2078-
*/
2079-
public function register_survey() {
2080-
2081-
if ( defined( 'CYPRESS_TESTING' ) ) {
2082-
return;
2107+
if ( isset( $license_data->key ) ) {
2108+
$survey_data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', $license_data->key );
20832109
}
20842110

2085-
$survey_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'survey' );
2086-
if ( empty( $survey_handler ) ) {
2087-
return;
2088-
}
2089-
2090-
do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );
2091-
wp_enqueue_script( $this->plugin_name . '_survey', FEEDZY_ABSURL . 'js/survey.js', array( $survey_handler ), $this->version, true );
2092-
wp_localize_script( $this->plugin_name . '_survey', 'feedzySurveyData', $this->get_survery_metadata() );
2111+
return $survey_data;
20932112
}
20942113

20952114
/**
@@ -2332,4 +2351,23 @@ public function register_settings() {
23322351
)
23332352
);
23342353
}
2354+
2355+
/**
2356+
* Mark the page as internal.
2357+
*/
2358+
private function do_internal_page( $page_slug ) {
2359+
do_action( 'themeisle_internal_page', $this->plugin_name, $page_slug );
2360+
}
2361+
2362+
/**
2363+
* Enable the loading of telemetry script in page.
2364+
*/
2365+
private function enable_telemetry() {
2366+
if ( defined( 'E2E_TESTING' ) ) {
2367+
return;
2368+
}
2369+
2370+
add_filter( 'themeisle_sdk_enable_telemetry', '__return_true' );
2371+
wp_enqueue_script( $this->plugin_name . '_telemetry', FEEDZY_ABSURL . 'js/telemetry.js', array(), $this->version, true );
2372+
}
23352373
}

includes/gutenberg/feedzy-rss-feeds-gutenberg-block.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function feedzy_gutenberg_scripts() {
8181
// Enqueue editor block styles
8282
wp_enqueue_style( 'feedzy-block-css', FEEDZY_ABSURL . 'css/feedzy-rss-feeds.css', array(), $this->version );
8383
wp_enqueue_style( 'feedzy-gutenberg-block-css', FEEDZY_ABSURL . 'build/block/style-index.css', array(), $this->version );
84+
85+
if ( ! defined( 'TE2E_TESTING' ) ) {
86+
add_filter( 'themeisle_sdk_enable_telemetry', '__return_true' );
87+
}
8488
}
8589

8690
/**

js/survey.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)