Skip to content

Commit 5efbdd5

Browse files
refactor: load survey via internal pages
1 parent fe75c9f commit 5efbdd5

File tree

3 files changed

+72
-68
lines changed

3 files changed

+72
-68
lines changed

.wp-env.json

+1-1
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",

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

+71-55
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ 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+
}
6279
}
6380

6481
/**
@@ -129,7 +146,8 @@ public function enqueue_styles_admin() {
129146
}
130147

131148
if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base ) {
132-
$this->register_survey();
149+
$this->do_internal_page( 'imports' );
150+
133151
$this->add_banner_anchor();
134152
}
135153

@@ -157,8 +175,6 @@ public function enqueue_styles_admin() {
157175
),
158176
)
159177
);
160-
161-
$this->register_survey();
162178
$this->add_banner_anchor();
163179
}
164180

@@ -179,8 +195,6 @@ public function enqueue_styles_admin() {
179195
),
180196
)
181197
);
182-
183-
$this->register_survey();
184198
}
185199

186200
if (
@@ -238,24 +252,32 @@ public function enqueue_styles_admin() {
238252
wp_enqueue_style( 'wp-block-editor' );
239253

240254
wp_set_script_translations( $this->plugin_name . '_conditions', 'feedzy-rss-feeds' );
241-
242-
$this->register_survey();
243255
}
244256
if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && feedzy_show_import_tour() ) ) {
245257
$asset_file = include FEEDZY_ABSPATH . '/build/onboarding/index.asset.php';
246258
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 );
247259
wp_set_script_translations( $this->plugin_name . '_on_boarding', 'feedzy-rss-feeds' );
248260
}
249261

262+
if ( 'feedzy_page_feedzy-settings' === $screen->base ) {
263+
$this->do_internal_page( 'settings' );
264+
}
265+
266+
if ( 'feedzy_page_feedzy-integration' === $screen->base ) {
267+
$this->do_internal_page( 'integrations' );
268+
}
269+
270+
if ( 'feedzy_categories' === $screen->post_type ) {
271+
$this->do_internal_page( 'add' === $screen->action ? 'new-category' : 'categories' );
272+
}
273+
250274
if ( ! in_array( $screen->base, $upsell_screens, true ) && strpos( $screen->id, 'feedzy' ) === false ) {
251275
return;
252276
}
253277

254278
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
255279
if ( 'feedzy_page_feedzy-support' === $screen->base && ( isset( $_GET['tab'] ) && 'improve' === $_GET['tab'] ) || ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) {
256280

257-
$this->register_survey();
258-
259281
$asset_file = include FEEDZY_ABSPATH . '/build/feedback/index.asset.php';
260282
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 );
261283
wp_enqueue_style( 'wp-block-editor' );
@@ -272,6 +294,17 @@ public function enqueue_styles_admin() {
272294
wp_set_script_translations( $this->plugin_name . '_feedback', 'feedzy-rss-feeds' );
273295
}
274296

297+
if ( 'feedzy_page_feedzy-support' === $screen->base ) {
298+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
299+
$tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
300+
$suffix = ! empty( $tab ) ? '-' . $tab : '';
301+
$this->do_internal_page( 'support' . $suffix );
302+
}
303+
304+
if ( ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) {
305+
$this->do_internal_page( 'new-import' );
306+
}
307+
275308
if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base && feedzy_show_review_notice() ) {
276309
$asset_file = include FEEDZY_ABSPATH . '/build/review/index.asset.php';
277310
wp_enqueue_script( $this->plugin_name . '_review', FEEDZY_ABSURL . 'build/review/index.js', $asset_file['dependencies'], $asset_file['version'], true );
@@ -2026,20 +2059,11 @@ public static function plan_category( $license_data ) {
20262059
* @return array
20272060
* @see survey.js
20282061
*/
2029-
public function get_survery_metadata() {
2030-
2031-
$user_id = 'feedzy_';
2032-
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
2033-
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-
}
2039-
2062+
public function get_survey_data() {
2063+
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
20402064
$integration_status = $this->api_license_status();
20412065

2042-
$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', 0 ) ) / DAY_IN_SECONDS );
2066+
$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', time() ) ) / DAY_IN_SECONDS );
20432067
$install_category = 0;
20442068
if ( 0 === $days_since_install || 1 === $days_since_install ) {
20452069
$install_category = 0;
@@ -2053,45 +2077,30 @@ public function get_survery_metadata() {
20532077
$install_category = 91;
20542078
}
20552079

2080+
$masked_key_license = null;
2081+
if ( isset( $license_data->key) ) {
2082+
$masked_key_license = str_repeat( '*', strlen( $license_data->key ) / 2 ) . substr( $license_data->key, strlen( $license_data->key ) / 2 );
2083+
}
2084+
20562085
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',
2086+
'environmentId' => 'clskgehf78eu5podwdrnzciti',
2087+
'apiHost' => 'https://app.formbricks.com',
2088+
'attributes' => array(
2089+
'free_version' => $this->version,
2090+
'pro_version' => defined( 'FEEDZY_PRO_VERSION' ) ? FEEDZY_PRO_VERSION : '',
2091+
'openai' => $integration_status['openaiStatus'] ? 'valid' : 'invalid',
2092+
'amazon' => $integration_status['amazonStatus'] ? 'valid' : 'invalid',
2093+
'spinnerchief' => $integration_status['spinnerChiefStatus'] ? 'valid' : 'invalid',
2094+
'wordai' => $integration_status['wordaiStatus'] ? 'valid' : 'invalid',
2095+
'plan' => $this->plan_category( $license_data ),
2096+
'days_since_install' => $install_category,
2097+
'install_days_number' => $days_since_install,
2098+
'license_status' => ! empty( $license_data->license ) ? $license_data->license : 'invalid',
2099+
'license_key' => $masked_key_license
20682100
),
20692101
);
20702102
}
20712103

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;
2083-
}
2084-
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() );
2093-
}
2094-
20952104
/**
20962105
* Add banner anchor for promotions.
20972106
*/
@@ -2332,4 +2341,11 @@ public function register_settings() {
23322341
)
23332342
);
23342343
}
2344+
2345+
/**
2346+
* Mark the page as internal.
2347+
*/
2348+
private function do_internal_page( $page_slug ) {
2349+
do_action( 'themeisle_internal_page', $this->plugin_name, $page_slug );
2350+
}
23352351
}

js/survey.js

-12
This file was deleted.

0 commit comments

Comments
 (0)