From b8a70c20e05c7d996883c00af560b6046fef7aea Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Wed, 26 Oct 2022 10:09:24 -0600 Subject: [PATCH] use Utils\*_option() --- includes/classes/AdminNotices.php | 8 ++------ includes/classes/Command.php | 12 ++---------- includes/classes/Features.php | 24 ++++-------------------- includes/classes/Upgrades.php | 12 ++---------- includes/dashboard.php | 19 +++++++------------ 5 files changed, 17 insertions(+), 58 deletions(-) diff --git a/includes/classes/AdminNotices.php b/includes/classes/AdminNotices.php index 601cf2f181..8a4ea23bc8 100644 --- a/includes/classes/AdminNotices.php +++ b/includes/classes/AdminNotices.php @@ -10,7 +10,7 @@ namespace ElasticPress; -use ElasticPress\Utils; +use ElasticPress\Utils as Utils; use ElasticPress\Elasticsearch; use ElasticPress\Screen; use ElasticPress\Features; @@ -772,11 +772,7 @@ public function dismiss_notice( $notice ) { if ( in_array( $notice, [ 'maybe_wrong_mapping' ], true ) ) { $value = Elasticsearch::factory()->get_elasticsearch_version( false ); } - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - update_site_option( 'ep_hide_' . $notice . '_notice', $value ); - } else { - update_option( 'ep_hide_' . $notice . '_notice', $value ); - } + Utils\update_option( 'ep_hide_' . $notice . '_notice', $value ); } /** diff --git a/includes/classes/Command.php b/includes/classes/Command.php index 18902931ee..ff097e25ee 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -1198,17 +1198,9 @@ public function set_search_algorithm_version( $args, $assoc_args ) { } if ( ! empty( $assoc_args['default'] ) ) { - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - delete_site_option( 'ep_search_algorithm_version' ); - } else { - delete_option( 'ep_search_algorithm_version' ); - } + Utils\delete_option( 'ep_search_algorithm_version' ); } else { - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - update_site_option( 'ep_search_algorithm_version', $assoc_args['version'] ); - } else { - update_option( 'ep_search_algorithm_version', $assoc_args['version'], false ); - } + Utils\update_option( 'ep_search_algorithm_version', $assoc_args['version'] ); } /** diff --git a/includes/classes/Features.php b/includes/classes/Features.php index 7335b393d9..73b268b73b 100644 --- a/includes/classes/Features.php +++ b/includes/classes/Features.php @@ -133,11 +133,7 @@ public function update_feature( $slug, $settings, $force = true ) { $sanitize_feature_settings = apply_filters( 'ep_sanitize_feature_settings', $feature_settings, $feature ); - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - update_site_option( 'ep_feature_settings', $sanitize_feature_settings ); - } else { - update_option( 'ep_feature_settings', $sanitize_feature_settings ); - } + Utils\update_option( 'ep_feature_settings', $sanitize_feature_settings ); $data = array( 'active' => $sanitize_feature_settings[ $slug ]['active'], @@ -194,11 +190,7 @@ public function handle_feature_activation() { $is_wp_cli = defined( 'WP_CLI' ) && \WP_CLI; if ( $is_wp_cli || is_admin() ) { - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - update_site_option( 'ep_feature_requirement_statuses', $new_requirement_statuses ); - } else { - update_option( 'ep_feature_requirement_statuses', $new_requirement_statuses ); - } + Utils\update_option( 'ep_feature_requirement_statuses', $new_requirement_statuses ); } /** @@ -242,11 +234,7 @@ public function handle_feature_activation() { $this->activate_feature( $slug ); if ( $feature->requires_install_reindex ) { - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - update_site_option( 'ep_feature_auto_activated_sync', sanitize_text_field( $slug ) ); - } else { - update_option( 'ep_feature_auto_activated_sync', sanitize_text_field( $slug ) ); - } + Utils\update_option( 'ep_feature_auto_activated_sync', sanitize_text_field( $slug ) ); } } } else { @@ -259,11 +247,7 @@ public function handle_feature_activation() { // Need to activate and maybe set a sync notice if ( $feature->requires_install_reindex ) { - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - update_site_option( 'ep_feature_auto_activated_sync', sanitize_text_field( $slug ) ); - } else { - update_option( 'ep_feature_auto_activated_sync', sanitize_text_field( $slug ) ); - } + Utils\update_option( 'ep_feature_auto_activated_sync', sanitize_text_field( $slug ) ); } } elseif ( $feature->is_active() && ! $active ) { // Just deactivate, don't force diff --git a/includes/classes/Upgrades.php b/includes/classes/Upgrades.php index 6c6a315da1..a3d966307a 100644 --- a/includes/classes/Upgrades.php +++ b/includes/classes/Upgrades.php @@ -60,11 +60,7 @@ public function setup() { * Note: if a upgrade routine method is hooked to some action, * this code will be executed *earlier* than the routine method. */ - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - update_site_option( 'ep_version', sanitize_text_field( EP_VERSION ) ); - } else { - update_option( 'ep_version', sanitize_text_field( EP_VERSION ) ); - } + Utils\update_option( 'ep_version', sanitize_text_field( EP_VERSION ) ); add_filter( 'ep_admin_notices', [ $this, 'resync_notice_4_0_0_instant_results' ] ); } @@ -289,11 +285,7 @@ public function check_reindex_needed() { } if ( $need_upgrade_sync ) { - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - update_site_option( 'ep_need_upgrade_sync', true ); - } else { - update_option( 'ep_need_upgrade_sync', true ); - } + Utils\update_option( 'ep_need_upgrade_sync', true ); } } diff --git a/includes/dashboard.php b/includes/dashboard.php index f70a68e8f8..95b6df9737 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -203,11 +203,10 @@ function maybe_skip_install() { 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 ); } + Utils\update_option( 'ep_skip_install', true ); wp_safe_redirect( $redirect_url ); exit; @@ -439,11 +438,7 @@ function action_wp_ajax_ep_save_feature() { // Since we deactivated, delete auto activate notice. if ( empty( $_POST['settings']['active'] ) ) { - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { - delete_site_option( 'ep_feature_auto_activated_sync' ); - } else { - delete_option( 'ep_feature_auto_activated_sync' ); - } + Utils\delete_option( 'ep_feature_auto_activated_sync' ); } wp_send_json_success( $data ); @@ -604,16 +599,16 @@ function action_admin_init() { check_admin_referer( 'elasticpress-options' ); $language = sanitize_text_field( $_POST['ep_language'] ); - update_site_option( 'ep_language', $language ); + Utils\update_option( 'ep_language', $language ); if ( isset( $_POST['ep_host'] ) ) { $host = esc_url_raw( trim( $_POST['ep_host'] ) ); - update_site_option( 'ep_host', $host ); + Utils\update_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 ); + Utils\update_option( 'ep_prefix', $prefix ); } if ( isset( $_POST['ep_credentials'] ) ) { @@ -622,11 +617,11 @@ function action_admin_init() { 'token' => '', ]; - update_site_option( 'ep_credentials', $credentials ); + Utils\update_option( 'ep_credentials', $credentials ); } if ( isset( $_POST['ep_bulk_setting'] ) ) { - update_site_option( 'ep_bulk_setting', intval( $_POST['ep_bulk_setting'] ) ); + Utils\update_option( 'ep_bulk_setting', intval( $_POST['ep_bulk_setting'] ) ); } } else { register_setting( 'elasticpress', 'ep_host', 'esc_url_raw' );