From e0b9580d3a5e45cf0fafeeb2dd6b3bef4750af55 Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Thu, 28 Apr 2022 16:30:36 +1000 Subject: [PATCH 1/6] Fix text domain typo. --- includes/partials/install-page.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/partials/install-page.php b/includes/partials/install-page.php index a1ad2153bf..46d05885ad 100644 --- a/includes/partials/install-page.php +++ b/includes/partials/install-page.php @@ -39,7 +39,7 @@
-

+

From 93dead50f66927d69096b58d3e774e4b97b09b83 Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Mon, 2 May 2022 22:21:20 +1000 Subject: [PATCH 2/6] Deactivate any features not selected during install. --- includes/classes/Installer.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/includes/classes/Installer.php b/includes/classes/Installer.php index 2d12fb945a..0b31414733 100644 --- a/includes/classes/Installer.php +++ b/includes/classes/Installer.php @@ -121,13 +121,19 @@ public function maybe_set_features() { return; } - if ( empty( $_POST['features'] ) || ! is_array( $_POST['features'] ) ) { + if ( ! isset( $_POST['features'] ) || ! is_array( $_POST['features'] ) ) { return; } - $features = array_map( 'sanitize_text_field', $_POST['features'] ); - foreach ( $features as $feature ) { - \ElasticPress\Features::factory()->activate_feature( $feature ); + $registered_features = \ElasticPress\Features::factory()->registered_features; + $activation_features = wp_list_filter( $registered_features, array( 'available_during_installation' => true ) ); + + foreach ( $activation_features as $slug => $feature ) { + if ( in_array( $slug, $_POST['features'], true ) ) { + \ElasticPress\Features::factory()->activate_feature( $slug ); + } else { + \ElasticPress\Features::factory()->deactivate_feature( $slug ); + } } $this->install_status = 4; @@ -150,4 +156,3 @@ public static function factory() { return $instance; } } - From fcdf6bc6c72bf9bcd8dce4be6440f05f4e180746 Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Mon, 2 May 2022 22:22:00 +1000 Subject: [PATCH 3/6] When skipping install deactivate all features. --- includes/dashboard.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index dbcbd445dc..0434b04698 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -193,13 +193,22 @@ function maybe_skip_install() { return; } + $features = \ElasticPress\Features::factory()->registered_features; + + foreach ( $features as $slug => $feature ) { + \ElasticPress\Features::factory()->deactivate_feature( $slug ); + } + if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { + $redirect_url = network_admin_url( 'admin.php?page=elasticpress' ); update_site_option( 'ep_skip_install', true ); } else { + $redirect_url = admin_url( 'admin.php?page=elasticpress' ); update_option( 'ep_skip_install', true ); } - wp_safe_redirect( admin_url( 'admin.php?page=elasticpress' ) ); + wp_safe_redirect( $redirect_url ); + exit; } /** From 00bd965cdaf2b9ce89fc654a1ab9b17ad462dc1b Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Mon, 2 May 2022 22:24:12 +1000 Subject: [PATCH 4/6] Skip install if no features selected, after confirmation. --- assets/js/dashboard.js | 47 +++++++++++++++++++++++++++++++++++++++++- includes/dashboard.php | 13 +++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/assets/js/dashboard.js b/assets/js/dashboard.js index b7f0b1f511..f16d164310 100644 --- a/assets/js/dashboard.js +++ b/assets/js/dashboard.js @@ -13,7 +13,7 @@ import { __ } from '@wordpress/i18n'; */ const { ajaxurl, - epDash: { syncUrl }, + epDash: { skipUrl, syncUrl }, } = window; /** @@ -118,6 +118,45 @@ const onClick = (event) => { } }; +/** + * Handle setup form submission. + * + * Asks for confirmation if the user doesn't select any features to activate. + * If the user wants to continue then skip installation. + * + * @param {Event} event Submit event. + * @returns {void} + */ +const onSubmitSetup = (event) => { + const features = new FormData(event.target).getAll('features[]'); + + /** + * If any features are selected continue as normal... + */ + if (features.length > 0) { + return; + } + + /** + * ...otherwise stop submission and ask for confirmation. + */ + event.preventDefault(); + + const confirm = window.confirm( + __( + 'It looks like you’re trying to use ElasticPress’s advanced features only. If you’d like to activate basic search, please select Cancel and activate the Post Search Feature. Otherwise, please click Ok to configure advanced features.', + 'elasticpress', + ), + ); + + /** + * If the user wants to proceed, skip installation. + */ + if (confirm) { + window.location = skipUrl; + } +}; + /** * Bind events. */ @@ -129,6 +168,12 @@ if (featuresEl) { featuresEl.addEventListener('click', onClick); } +const submitEl = document.querySelector('button.setup-button'); + +if (submitEl) { + submitEl.form.addEventListener('submit', onSubmitSetup); +} + /** * Tooltips. */ diff --git a/includes/dashboard.php b/includes/dashboard.php index 0434b04698..4060a2bf62 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -492,10 +492,21 @@ function action_admin_enqueue_dashboard_scripts() { ); $sync_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? - admin_url( 'network/admin.php?page=elasticpress-sync&do_sync' ) : + network_admin_url( 'admin.php?page=elasticpress-sync&do_sync' ) : admin_url( 'admin.php?page=elasticpress-sync&do_sync' ); + $skip_url = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? + network_admin_url( 'admin.php?page=elasticpress' ) : + admin_url( 'admin.php?page=elasticpress' ); + $data = array( + 'skipUrl' => add_query_arg( + array( + 'ep-skip-install' => 1, + 'nonce' => wp_create_nonce( 'ep-skip-install' ), + ), + $skip_url, + ), 'syncUrl' => $sync_url, ); From 625a5b8f008bf336a451c6f931dd2d6595638187 Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Mon, 2 May 2022 22:53:31 +1000 Subject: [PATCH 5/6] Don't deactivate features when skipping indexing. --- includes/dashboard.php | 13 ++++++++----- includes/partials/install-page.php | 9 ++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 4060a2bf62..49fe6ed80c 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -193,10 +193,12 @@ function maybe_skip_install() { return; } - $features = \ElasticPress\Features::factory()->registered_features; + if ( ! empty( $_GET['ep-skip-features'] ) ) { + $features = \ElasticPress\Features::factory()->registered_features; - foreach ( $features as $slug => $feature ) { - \ElasticPress\Features::factory()->deactivate_feature( $slug ); + foreach ( $features as $slug => $feature ) { + \ElasticPress\Features::factory()->deactivate_feature( $slug ); + } } if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { @@ -502,8 +504,9 @@ function action_admin_enqueue_dashboard_scripts() { $data = array( 'skipUrl' => add_query_arg( array( - 'ep-skip-install' => 1, - 'nonce' => wp_create_nonce( 'ep-skip-install' ), + 'ep-skip-install' => 1, + 'ep-skip-features' => 1, + 'nonce' => wp_create_nonce( 'ep-skip-install' ), ), $skip_url, ), diff --git a/includes/partials/install-page.php b/includes/partials/install-page.php index 46d05885ad..e3eb051654 100644 --- a/includes/partials/install-page.php +++ b/includes/partials/install-page.php @@ -22,10 +22,13 @@ $skip_install_url = add_query_arg( [ - 'ep-skip-install' => 1, - 'nonce' => wp_create_nonce( 'ep-skip-install' ), + 'ep-skip-install' => 1, + 'ep-skip-features' => 1, + 'nonce' => wp_create_nonce( 'ep-skip-install' ), ] ); + +$skip_index_url = remove_query_arg( 'ep-skip-features', $skip_install_url ); ?> @@ -150,7 +153,7 @@
-

+

From 69c505e6e2bdcca547834da354ecc42ea5075a09 Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Mon, 2 May 2022 23:14:28 +1000 Subject: [PATCH 6/6] Remove stray comma. --- includes/dashboard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 49fe6ed80c..09f8331cfe 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -508,7 +508,7 @@ function action_admin_enqueue_dashboard_scripts() { 'ep-skip-features' => 1, 'nonce' => wp_create_nonce( 'ep-skip-install' ), ), - $skip_url, + $skip_url ), 'syncUrl' => $sync_url, );