Skip to content

Commit 18c8792

Browse files
refactor: load survey via internal pages
1 parent fe75c9f commit 18c8792

File tree

3 files changed

+67
-68
lines changed

3 files changed

+67
-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

+66-55
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ 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( $config, $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 $config;
71+
}
72+
73+
$config['data'] = $this->get_survey_data();
74+
return $config;
75+
},
76+
10,
77+
2
78+
);
79+
}
6280
}
6381

6482
/**
@@ -129,7 +147,8 @@ public function enqueue_styles_admin() {
129147
}
130148

131149
if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base ) {
132-
$this->register_survey();
150+
$this->do_internal_page( 'imports' );
151+
133152
$this->add_banner_anchor();
134153
}
135154

@@ -157,8 +176,6 @@ public function enqueue_styles_admin() {
157176
),
158177
)
159178
);
160-
161-
$this->register_survey();
162179
$this->add_banner_anchor();
163180
}
164181

@@ -179,8 +196,6 @@ public function enqueue_styles_admin() {
179196
),
180197
)
181198
);
182-
183-
$this->register_survey();
184199
}
185200

186201
if (
@@ -238,24 +253,32 @@ 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();
243256
}
244257
if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && feedzy_show_import_tour() ) ) {
245258
$asset_file = include FEEDZY_ABSPATH . '/build/onboarding/index.asset.php';
246259
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 );
247260
wp_set_script_translations( $this->plugin_name . '_on_boarding', 'feedzy-rss-feeds' );
248261
}
249262

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

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

257-
$this->register_survey();
258-
259282
$asset_file = include FEEDZY_ABSPATH . '/build/feedback/index.asset.php';
260283
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 );
261284
wp_enqueue_style( 'wp-block-editor' );
@@ -272,6 +295,17 @@ public function enqueue_styles_admin() {
272295
wp_set_script_translations( $this->plugin_name . '_feedback', 'feedzy-rss-feeds' );
273296
}
274297

298+
if ( 'feedzy_page_feedzy-support' === $screen->base ) {
299+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
300+
$tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
301+
$suffix = ! empty( $tab ) ? '-' . $tab : '';
302+
$this->do_internal_page( 'support' . $suffix );
303+
}
304+
305+
if ( ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) {
306+
$this->do_internal_page( 'new-import' );
307+
}
308+
275309
if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base && feedzy_show_review_notice() ) {
276310
$asset_file = include FEEDZY_ABSPATH . '/build/review/index.asset.php';
277311
wp_enqueue_script( $this->plugin_name . '_review', FEEDZY_ABSURL . 'build/review/index.js', $asset_file['dependencies'], $asset_file['version'], true );
@@ -2026,20 +2060,11 @@ public static function plan_category( $license_data ) {
20262060
* @return array
20272061
* @see survey.js
20282062
*/
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-
2063+
public function get_survey_data() {
2064+
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
20402065
$integration_status = $this->api_license_status();
20412066

2042-
$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', 0 ) ) / DAY_IN_SECONDS );
2067+
$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', time() ) ) / DAY_IN_SECONDS );
20432068
$install_category = 0;
20442069
if ( 0 === $days_since_install || 1 === $days_since_install ) {
20452070
$install_category = 0;
@@ -2054,44 +2079,23 @@ public function get_survery_metadata() {
20542079
}
20552080

20562081
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',
2082+
'environmentId' => 'clskgehf78eu5podwdrnzciti',
2083+
'apiHost' => 'https://app.formbricks.com',
2084+
'attributes' => array(
2085+
'free_version' => $this->version,
2086+
'pro_version' => defined( 'FEEDZY_PRO_VERSION' ) ? FEEDZY_PRO_VERSION : '',
2087+
'openai' => $integration_status['openaiStatus'] ? 'valid' : 'invalid',
2088+
'amazon' => $integration_status['amazonStatus'] ? 'valid' : 'invalid',
2089+
'spinnerchief' => $integration_status['spinnerChiefStatus'] ? 'valid' : 'invalid',
2090+
'wordai' => $integration_status['wordaiStatus'] ? 'valid' : 'invalid',
2091+
'plan' => $this->plan_category( $license_data ),
2092+
'days_since_install' => $install_category,
2093+
'install_days_number' => $days_since_install,
2094+
'license_status' => ! empty( $license_data->license ) ? $license_data->license : 'invalid',
20682095
),
20692096
);
20702097
}
20712098

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-
20952099
/**
20962100
* Add banner anchor for promotions.
20972101
*/
@@ -2332,4 +2336,11 @@ public function register_settings() {
23322336
)
23332337
);
23342338
}
2339+
2340+
/**
2341+
* Mark the page as internal.
2342+
*/
2343+
private function do_internal_page( $page_slug ) {
2344+
do_action( 'themeisle_internal_page', $this->plugin_name, $page_slug );
2345+
}
23352346
}

js/survey.js

-12
This file was deleted.

0 commit comments

Comments
 (0)