From 510fc2ed7531f56691073ba697018fbd1aead74f Mon Sep 17 00:00:00 2001 From: Mohammed Razzaq Date: Fri, 2 Sep 2022 06:23:19 +0530 Subject: [PATCH 1/5] Merge subscription username and subscription id --- assets/css/dashboard.css | 8 ++ includes/partials/settings-page.php | 127 ++++++++++++---------------- 2 files changed, 62 insertions(+), 73 deletions(-) diff --git a/assets/css/dashboard.css b/assets/css/dashboard.css index 95597b6b5a..4fb4231f7e 100644 --- a/assets/css/dashboard.css +++ b/assets/css/dashboard.css @@ -995,6 +995,14 @@ h2 .nav-tab.ep-credentials-tab { border-top: 1px solid #ccc; } +.ep-settings .ep-credentials-general { + padding: 0 1rem; +} + +.ep-settings .button-primary { + margin: 0 1rem; +} + .ep-settings .description { font-size: 0.75rem; font-style: italic; diff --git a/includes/partials/settings-page.php b/includes/partials/settings-page.php index 4230d4142e..0f0f272e82 100644 --- a/includes/partials/settings-page.php +++ b/includes/partials/settings-page.php @@ -1,4 +1,5 @@ - - - - - - - disabled type="text" value="" name="ep_prefix" id="ep_prefix"> - - -

- -

- - - @@ -148,14 +125,15 @@

-

+

- + + - - - - - - - - - +
- - - 'ep_language', - 'name' => 'ep_language', - 'selected' => $ep_language, - ] - ); - ?> -

-
- - - - - - - - — - +
+ + + + + + + + + + + + + + + - - - - - - - - - -
+ + + 'ep_language', + 'name' => 'ep_language', + 'selected' => $ep_language, + ] + ); + ?> +

+
+ + + + + + + + + — + + +
+ + + +
- - - -
+
+ Date: Tue, 13 Sep 2022 15:48:04 +0530 Subject: [PATCH 2/5] Update prefix with username --- includes/dashboard.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 7d1a14d851..3a4e1bef0e 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -597,11 +597,6 @@ function action_admin_init() { update_site_option( 'ep_host', $host ); } - if ( isset( $_POST['ep_prefix'] ) ) { - $prefix = ( isset( $_POST['ep_prefix'] ) ) ? sanitize_text_field( wp_unslash( $_POST['ep_prefix'] ) ) : ''; - update_site_option( 'ep_prefix', $prefix ); - } - if ( isset( $_POST['ep_credentials'] ) ) { $credentials = ( isset( $_POST['ep_credentials'] ) ) ? Utils\sanitize_credentials( $_POST['ep_credentials'] ) : [ 'username' => '', @@ -609,6 +604,9 @@ function action_admin_init() { ]; update_site_option( 'ep_credentials', $credentials ); + // Update prefix with username as both are same + $prefix = $credentials['username']; + update_site_option( 'ep_prefix', $prefix ); } if ( isset( $_POST['ep_bulk_setting'] ) ) { @@ -616,7 +614,6 @@ function action_admin_init() { } } else { register_setting( 'elasticpress', 'ep_host', 'esc_url_raw' ); - register_setting( 'elasticpress', 'ep_prefix', 'sanitize_text_field' ); register_setting( 'elasticpress', 'ep_credentials', 'ep_sanitize_credentials' ); register_setting( 'elasticpress', 'ep_language', 'sanitize_text_field' ); register_setting( From 56185855c8b0abaac24adcf7ff9e5e1440189173 Mon Sep 17 00:00:00 2001 From: Mohammed Razzaq Date: Tue, 20 Sep 2022 05:25:28 +0530 Subject: [PATCH 3/5] Code improvement --- includes/dashboard.php | 2 +- includes/partials/settings-page.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index 3a4e1bef0e..6b63ca6c97 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -605,7 +605,7 @@ function action_admin_init() { update_site_option( 'ep_credentials', $credentials ); // Update prefix with username as both are same - $prefix = $credentials['username']; + $prefix = sanitize_text_field( wp_unslash( $credentials['username'] ) ); update_site_option( 'ep_prefix', $prefix ); } diff --git a/includes/partials/settings-page.php b/includes/partials/settings-page.php index 0f0f272e82..e75e42168b 100644 --- a/includes/partials/settings-page.php +++ b/includes/partials/settings-page.php @@ -1,5 +1,4 @@ Date: Wed, 9 Nov 2022 10:10:57 -0300 Subject: [PATCH 4/5] Fix SVGs This was broken with the changes introduced in #3082 --- images/logo-elasticpress-io.svg | 2 +- images/logo-icon.svg | 2 +- images/logo.svg | 2 +- images/warning.svg | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/images/logo-elasticpress-io.svg b/images/logo-elasticpress-io.svg index d913c0f9ff..8f09945710 100644 --- a/images/logo-elasticpress-io.svg +++ b/images/logo-elasticpress-io.svg @@ -1,4 +1,4 @@ - + ElasticPress.io Logo diff --git a/images/logo-icon.svg b/images/logo-icon.svg index 4c102db77c..d3b4c7616f 100644 --- a/images/logo-icon.svg +++ b/images/logo-icon.svg @@ -1 +1 @@ -logo \ No newline at end of file +logo \ No newline at end of file diff --git a/images/logo.svg b/images/logo.svg index 2dad352f59..9be5250e95 100644 --- a/images/logo.svg +++ b/images/logo.svg @@ -1 +1 @@ -logo \ No newline at end of file +logo \ No newline at end of file diff --git a/images/warning.svg b/images/warning.svg index 6765fab1ca..fe60e7d28e 100644 --- a/images/warning.svg +++ b/images/warning.svg @@ -1,3 +1,3 @@ - + From d1505989cb4c8caa6ab80363d94eeb0bac58107d Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 9 Nov 2022 10:14:24 -0300 Subject: [PATCH 5/5] Remove ep_prefix entirely --- includes/classes/Upgrades.php | 14 +++++++++++++- includes/dashboard.php | 8 -------- includes/partials/settings-page.php | 10 +++++----- includes/utils.php | 15 ++++++++------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/includes/classes/Upgrades.php b/includes/classes/Upgrades.php index a3d966307a..82e1da3ac6 100644 --- a/includes/classes/Upgrades.php +++ b/includes/classes/Upgrades.php @@ -8,7 +8,7 @@ namespace ElasticPress; -use ElasticPress\Utils as Utils; +use ElasticPress\Utils; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. @@ -46,6 +46,7 @@ public function setup() { '3.5.3' => [ 'upgrade_3_5_3', 'init' ], '3.6.6' => [ 'upgrade_3_6_6', 'init' ], '4.2.2' => [ 'upgrade_4_2_2', 'init' ], + '4.4.0' => [ 'upgrade_4_4_0', 'init' ], ]; array_walk( $routines, [ $this, 'run_upgrade_routine' ] ); @@ -179,6 +180,17 @@ public function upgrade_4_2_2() { } } + /** + * Upgrade routine of v4.4.0. + * + * Delete the ep_prefix option, as that is now obtained via ep_credentials + * + * @see https://github.com/10up/ElasticPress/issues/2739 + */ + public function upgrade_4_4_0() { + Utils\delete_option( 'ep_prefix' ); + } + /** * Adjust the upgrade sync notice to warn users about Instant Results. * diff --git a/includes/dashboard.php b/includes/dashboard.php index fd56271314..06f1814ae2 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -606,20 +606,12 @@ function action_admin_init() { Utils\update_option( 'ep_host', $host ); } - if ( isset( $_POST['ep_prefix'] ) ) { - $prefix = ( isset( $_POST['ep_prefix'] ) ) ? sanitize_text_field( wp_unslash( $_POST['ep_prefix'] ) ) : ''; - Utils\update_option( 'ep_prefix', $prefix ); - } - if ( isset( $_POST['ep_credentials'] ) ) { $credentials = ( isset( $_POST['ep_credentials'] ) ) ? Utils\sanitize_credentials( $_POST['ep_credentials'] ) : [ 'username' => '', 'token' => '', ]; - // Update prefix with username as both are same - $prefix = sanitize_text_field( wp_unslash( $credentials['username'] ) ); - Utils\update_option( 'ep_prefix', $prefix ); Utils\update_option( 'ep_credentials', $credentials ); } diff --git a/includes/partials/settings-page.php b/includes/partials/settings-page.php index 7e4e080f85..088a7ee0a6 100644 --- a/includes/partials/settings-page.php +++ b/includes/partials/settings-page.php @@ -90,9 +90,9 @@

-

+

-

+

@@ -101,7 +101,7 @@ - + disabled type="text" value="" name="ep_credentials[username]" id="ep_username"> -

+

-

+

diff --git a/includes/utils.php b/includes/utils.php index fabfcf5f59..3199f30098 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -77,14 +77,15 @@ function get_shield_credentials() { * @return string|bool */ function get_index_prefix() { - if ( defined( 'EP_INDEX_PREFIX' ) && EP_INDEX_PREFIX ) { - $prefix = EP_INDEX_PREFIX; - } elseif ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK && is_epio() ) { - $prefix = get_site_option( 'ep_prefix', false ); + if ( defined( 'EP_INDEX_PREFIX' ) && \EP_INDEX_PREFIX ) { + $prefix = \EP_INDEX_PREFIX; } elseif ( is_epio() ) { - $prefix = get_option( 'ep_prefix', false ); - - if ( '-' !== substr( $prefix, - 1 ) ) { + $credentials = get_epio_credentials(); + $prefix = $credentials['username']; + if ( + ( ! defined( 'EP_IS_NETWORK' ) || ! EP_IS_NETWORK ) && + ( '-' !== substr( $prefix, - 1 ) ) + ) { $prefix .= '-'; } } else {