Skip to content

Commit

Permalink
Merge pull request #3078 from rebeccahum/ep_index_meta
Browse files Browse the repository at this point in the history
Use Utils\get_option() when possible
  • Loading branch information
felipeelia committed Oct 26, 2022
2 parents 4822957 + 5beaa50 commit a160a5a
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 173 deletions.
114 changes: 19 additions & 95 deletions includes/classes/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ protected function process_using_autosuggest_defaults_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$last_sync = get_site_option( 'ep_last_sync', false );
} else {
$last_sync = get_option( 'ep_last_sync', false );
}
$last_sync = Utils\get_option( 'ep_last_sync', false );

if ( empty( $last_sync ) ) {
return false;
Expand All @@ -107,11 +103,7 @@ protected function process_using_autosuggest_defaults_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_using_autosuggest_defaults_notice', false );
} else {
$dismiss = get_option( 'ep_hide_using_autosuggest_defaults_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_using_autosuggest_defaults_notice', false );

if ( $dismiss ) {
return false;
Expand Down Expand Up @@ -147,32 +139,20 @@ protected function process_using_autosuggest_defaults_notice() {
* @return array|bool
*/
protected function process_auto_activate_sync_notice() {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$need_upgrade_sync = get_site_option( 'ep_need_upgrade_sync', false );
} else {
$need_upgrade_sync = get_option( 'ep_need_upgrade_sync', false );
}
$need_upgrade_sync = Utils\get_option( 'ep_need_upgrade_sync', false );

// need_upgrade_sync takes priority over this notice
if ( $need_upgrade_sync ) {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$auto_activate_sync = get_site_option( 'ep_feature_auto_activated_sync', false );
} else {
$auto_activate_sync = get_option( 'ep_feature_auto_activated_sync', false );
}
$auto_activate_sync = Utils\get_option( 'ep_feature_auto_activated_sync', false );

if ( ! $auto_activate_sync ) {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$last_sync = get_site_option( 'ep_last_sync', false );
} else {
$last_sync = get_option( 'ep_last_sync', false );
}
$last_sync = Utils\get_option( 'ep_last_sync', false );

if ( empty( $last_sync ) ) {
return false;
Expand All @@ -184,11 +164,7 @@ protected function process_auto_activate_sync_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_auto_activate_sync_notice', false );
} else {
$dismiss = get_option( 'ep_hide_auto_activate_sync_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_auto_activate_sync_notice', false );

$screen = Screen::factory()->get_current_screen();

Expand Down Expand Up @@ -236,21 +212,13 @@ protected function process_auto_activate_sync_notice() {
* @return array|bool
*/
protected function process_upgrade_sync_notice() {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$need_upgrade_sync = get_site_option( 'ep_need_upgrade_sync', false );
} else {
$need_upgrade_sync = get_option( 'ep_need_upgrade_sync', false );
}
$need_upgrade_sync = Utils\get_option( 'ep_need_upgrade_sync', false );

if ( ! $need_upgrade_sync ) {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$last_sync = get_site_option( 'ep_last_sync', false );
} else {
$last_sync = get_option( 'ep_last_sync', false );
}
$last_sync = Utils\get_option( 'ep_last_sync', false );

if ( empty( $last_sync ) ) {
return false;
Expand All @@ -262,11 +230,7 @@ protected function process_upgrade_sync_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_upgrade_sync_notice', false );
} else {
$dismiss = get_option( 'ep_hide_upgrade_sync_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_upgrade_sync_notice', false );

$screen = Screen::factory()->get_current_screen();

Expand Down Expand Up @@ -314,11 +278,7 @@ protected function process_upgrade_sync_notice() {
* @return array|bool
*/
protected function process_no_sync_notice() {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$last_sync = get_site_option( 'ep_last_sync', false );
} else {
$last_sync = get_option( 'ep_last_sync', false );
}
$last_sync = Utils\get_option( 'ep_last_sync', false );

if ( ! empty( $last_sync ) ) {
return false;
Expand All @@ -330,11 +290,7 @@ protected function process_no_sync_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_no_sync_notice', false );
} else {
$dismiss = get_option( 'ep_hide_no_sync_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_no_sync_notice', false );

$screen = Screen::factory()->get_current_screen();

Expand Down Expand Up @@ -386,11 +342,7 @@ protected function process_need_setup_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_need_setup_notice', false );
} else {
$dismiss = get_option( 'ep_hide_need_setup_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_need_setup_notice', false );

$screen = Screen::factory()->get_current_screen();

Expand Down Expand Up @@ -442,11 +394,7 @@ protected function process_es_below_compat_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_es_below_compat_notice', false );
} else {
$dismiss = get_option( 'ep_hide_es_below_compat_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_es_below_compat_notice', false );

if ( $dismiss ) {
return false;
Expand Down Expand Up @@ -502,11 +450,7 @@ protected function process_es_above_compat_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_es_above_compat_notice', false );
} else {
$dismiss = get_option( 'ep_hide_es_above_compat_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_es_above_compat_notice', false );

if ( $dismiss ) {
return false;
Expand Down Expand Up @@ -602,11 +546,7 @@ protected function process_host_error_notice() {

// Only dismissable on non-EP screens
if ( ! in_array( $screen, [ 'settings', 'dashboard' ], true ) ) {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_host_error_notice', false );
} else {
$dismiss = get_option( 'ep_hide_host_error_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_host_error_notice', false );

if ( $dismiss ) {
return false;
Expand Down Expand Up @@ -660,11 +600,7 @@ protected function process_maybe_wrong_mapping_notice() {
}

// we might have this dismissed
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_maybe_wrong_mapping_notice', false );
} else {
$dismiss = get_option( 'ep_hide_maybe_wrong_mapping_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_maybe_wrong_mapping_notice', false );

// we need a host
$host = Utils\get_host();
Expand All @@ -680,11 +616,7 @@ protected function process_maybe_wrong_mapping_notice() {
}

// we also likely need a sync to have a mapping
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$last_sync = get_site_option( 'ep_last_sync', false );
} else {
$last_sync = get_option( 'ep_last_sync', false );
}
$last_sync = Utils\get_option( 'ep_last_sync', false );

if ( empty( $last_sync ) ) {
return false;
Expand Down Expand Up @@ -737,21 +669,13 @@ protected function process_yellow_health_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$last_sync = get_site_option( 'ep_last_sync', false );
} else {
$last_sync = get_option( 'ep_last_sync', false );
}
$last_sync = Utils\get_option( 'ep_last_sync', false );

if ( empty( $last_sync ) ) {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$dismiss = get_site_option( 'ep_hide_yellow_health_notice', false );
} else {
$dismiss = get_option( 'ep_hide_yellow_health_notice', false );
}
$dismiss = Utils\get_option( 'ep_hide_yellow_health_notice', false );

$screen = Screen::factory()->get_current_screen();

Expand Down
19 changes: 4 additions & 15 deletions includes/classes/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ public function deactivate_feature( $args, $assoc_args ) {
WP_CLI::error( esc_html__( 'No feature with that slug is registered', 'elasticpress' ) );
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$active_features = get_site_option( 'ep_feature_settings', [] );
} else {
$active_features = get_option( 'ep_feature_settings', [] );
}
$active_features = Utils\get_option( 'ep_feature_settings', [] );

$key = array_search( $feature->slug, array_keys( $active_features ), true );

Expand Down Expand Up @@ -173,11 +169,8 @@ public function deactivate_feature( $args, $assoc_args ) {
public function list_features( $args, $assoc_args ) {

if ( empty( $assoc_args['all'] ) ) {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$features = get_site_option( 'ep_feature_settings', [] );
} else {
$features = get_option( 'ep_feature_settings', [] );
}
$features = Utils\get_option( 'ep_feature_settings', [] );

WP_CLI::line( esc_html__( 'Active features:', 'elasticpress' ) );

foreach ( array_keys( $features ) as $feature_slug ) {
Expand Down Expand Up @@ -1237,11 +1230,7 @@ public function set_search_algorithm_version( $args, $assoc_args ) {
* @param array $assoc_args Associative CLI args.
*/
public function get_search_algorithm_version( $args, $assoc_args ) {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$value = get_site_option( 'ep_search_algorithm_version', '' );
} else {
$value = get_option( 'ep_search_algorithm_version', '' );
}
$value = Utils\get_option( 'ep_search_algorithm_version', '' );

if ( empty( $value ) ) {
WP_CLI::line( 'default' );
Expand Down
13 changes: 3 additions & 10 deletions includes/classes/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ElasticPress;

use ElasticPress\FeatureRequirementsStatus as FeatureRequirementsStatus;
use ElasticPress\Utils as Utils;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
Expand Down Expand Up @@ -162,11 +163,7 @@ public function requirements_status() {
* @return array|bool
*/
public function get_settings() {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$feature_settings = get_site_option( 'ep_feature_settings', [] );
} else {
$feature_settings = get_option( 'ep_feature_settings', [] );
}
$feature_settings = Utils\get_option( 'ep_feature_settings', [] );

return ( ! empty( $feature_settings[ $this->slug ] ) ) ? $feature_settings[ $this->slug ] : false;
}
Expand All @@ -178,11 +175,7 @@ public function get_settings() {
* @return boolean
*/
public function is_active() {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$feature_settings = get_site_option( 'ep_feature_settings', [] );
} else {
$feature_settings = get_option( 'ep_feature_settings', [] );
}
$feature_settings = Utils\get_option( 'ep_feature_settings', [] );

$active = false;

Expand Down
20 changes: 5 additions & 15 deletions includes/classes/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace ElasticPress;

use ElasticPress\Utils as Utils;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand Down Expand Up @@ -105,11 +107,7 @@ public function update_feature( $slug, $settings, $force = true ) {

$original_state = $feature->is_active();

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$feature_settings = get_site_option( 'ep_feature_settings', [] );
} else {
$feature_settings = get_option( 'ep_feature_settings', [] );
}
$feature_settings = Utils\get_option( 'ep_feature_settings', [] );

if ( empty( $feature_settings[ $slug ] ) ) {
// If doesn't exist, merge with feature defaults
Expand Down Expand Up @@ -184,11 +182,7 @@ public function handle_feature_activation() {
* Save our current requirement statuses for later
*/

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$old_requirement_statuses = get_site_option( 'ep_feature_requirement_statuses', false );
} else {
$old_requirement_statuses = get_option( 'ep_feature_requirement_statuses', false );
}
$old_requirement_statuses = Utils\get_option( 'ep_feature_requirement_statuses', false );

$new_requirement_statuses = [];

Expand All @@ -211,11 +205,7 @@ public function handle_feature_activation() {
* If feature settings aren't created, let's create them and finish
*/

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$feature_settings = get_site_option( 'ep_feature_settings', false );
} else {
$feature_settings = get_option( 'ep_feature_settings', false );
}
$feature_settings = Utils\get_option( 'ep_feature_settings', false );

if ( false === $feature_settings ) {
$registered_features = $this->registered_features;
Expand Down
8 changes: 2 additions & 6 deletions includes/classes/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,15 @@ public function filter_admin_title( $admin_title, $title ) {
* @since 3.0
*/
public function calculate_install_status() {
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$skip_install = get_site_option( 'ep_skip_install', false );
} else {
$skip_install = get_option( 'ep_skip_install', false );
}
$skip_install = Utils\get_option( 'ep_skip_install', false );

if ( $skip_install ) {
$this->install_status = true;

return;
}

$last_sync = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? get_site_option( 'ep_last_sync', false ) : get_option( 'ep_last_sync', false );
$last_sync = Utils\get_option( 'ep_last_sync', false );
if ( ! empty( $last_sync ) ) {
$this->install_status = true;

Expand Down
3 changes: 1 addition & 2 deletions includes/classes/Screen/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,12 @@ public function admin_enqueue_scripts() {

$data = array( 'nonce' => wp_create_nonce( 'ep_dashboard_nonce' ) );
$index_meta = Utils\get_indexing_status();
$last_sync = Utils\get_option( 'ep_last_sync', false );

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$install_complete_url = admin_url( 'network/admin.php?page=elasticpress&install_complete' );
$last_sync = get_site_option( 'ep_last_sync', false );
} else {
$install_complete_url = admin_url( 'admin.php?page=elasticpress&install_complete' );
$last_sync = get_option( 'ep_last_sync', false );
}

if ( isset( $_GET['do_sync'] ) && ( ! defined( 'EP_DASHBOARD_SYNC' ) || EP_DASHBOARD_SYNC ) ) { // phpcs:ignore WordPress.Security.NonceVerification
Expand Down
Loading

0 comments on commit a160a5a

Please sign in to comment.