@@ -59,6 +59,50 @@ class Feedzy_Rss_Feeds_Admin extends Feedzy_Rss_Feeds_Admin_Abstract {
59
59
public function __construct ( $ plugin_name , $ version ) {
60
60
$ this ->plugin_name = $ plugin_name ;
61
61
$ 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 );
62
106
}
63
107
64
108
/**
@@ -116,21 +160,8 @@ public function enqueue_styles_admin() {
116
160
return ;
117
161
}
118
162
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
-
131
163
if ( 'feedzy_imports ' === $ screen ->post_type && 'edit ' === $ screen ->base ) {
132
- $ this ->register_survey ();
133
- $ this ->add_banner_anchor ();
164
+ $ this ->do_internal_page ( 'imports ' );
134
165
}
135
166
136
167
if ( 'feedzy_categories ' === $ screen ->post_type ) {
@@ -157,9 +188,6 @@ public function enqueue_styles_admin() {
157
188
),
158
189
)
159
190
);
160
-
161
- $ this ->register_survey ();
162
- $ this ->add_banner_anchor ();
163
191
}
164
192
165
193
if ( 'feedzy_page_feedzy-settings ' === $ screen ->base || 'feedzy_page_feedzy-integration ' === $ screen ->base ) {
@@ -179,19 +207,6 @@ public function enqueue_styles_admin() {
179
207
),
180
208
)
181
209
);
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
- }
195
210
}
196
211
197
212
$ 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() {
238
253
wp_enqueue_style ( 'wp-block-editor ' );
239
254
240
255
wp_set_script_translations ( $ this ->plugin_name . '_conditions ' , 'feedzy-rss-feeds ' );
241
-
242
- $ this ->register_survey ();
256
+ $ this ->enable_telemetry ();
243
257
}
244
258
if ( ! defined ( 'TI_CYPRESS_TESTING ' ) && ( 'edit ' !== $ screen ->base && 'feedzy_imports ' === $ screen ->post_type && feedzy_show_import_tour () ) ) {
245
259
$ asset_file = include FEEDZY_ABSPATH . '/build/onboarding/index.asset.php ' ;
246
260
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 );
247
261
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 ' );
248
275
}
249
276
250
277
if ( ! in_array ( $ screen ->base , $ upsell_screens , true ) && strpos ( $ screen ->id , 'feedzy ' ) === false ) {
@@ -254,8 +281,6 @@ public function enqueue_styles_admin() {
254
281
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
255
282
if ( 'feedzy_page_feedzy-support ' === $ screen ->base && ( isset ( $ _GET ['tab ' ] ) && 'improve ' === $ _GET ['tab ' ] ) || ( 'edit ' !== $ screen ->base && 'feedzy_imports ' === $ screen ->post_type ) ) {
256
283
257
- $ this ->register_survey ();
258
-
259
284
$ asset_file = include FEEDZY_ABSPATH . '/build/feedback/index.asset.php ' ;
260
285
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 );
261
286
wp_enqueue_style ( 'wp-block-editor ' );
@@ -272,6 +297,17 @@ public function enqueue_styles_admin() {
272
297
wp_set_script_translations ( $ this ->plugin_name . '_feedback ' , 'feedzy-rss-feeds ' );
273
298
}
274
299
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
+
275
311
if ( 'feedzy_imports ' === $ screen ->post_type && 'edit ' === $ screen ->base && feedzy_show_review_notice () ) {
276
312
$ asset_file = include FEEDZY_ABSPATH . '/build/review/index.asset.php ' ;
277
313
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 ) {
2026
2062
* @return array
2027
2063
* @see survey.js
2028
2064
*/
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 ();
2030
2068
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 );
2033
2070
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 ' );
2039
2072
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
+ );
2041
2083
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
+ ),
2069
2105
);
2070
- }
2071
2106
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 );
2083
2109
}
2084
2110
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 ;
2093
2112
}
2094
2113
2095
2114
/**
@@ -2332,4 +2351,23 @@ public function register_settings() {
2332
2351
)
2333
2352
);
2334
2353
}
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
+ }
2335
2373
}
0 commit comments