From 5cb95bfaa8a833c2679ea697f8d0a6d97eee814d Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Fri, 19 Jul 2024 13:45:40 -0600 Subject: [PATCH] Minor adjustments --- projects/packages/waf/src/class-compatibility.php | 10 +++++----- projects/packages/waf/src/class-waf-rules-manager.php | 10 ++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/projects/packages/waf/src/class-compatibility.php b/projects/packages/waf/src/class-compatibility.php index 89480b13b88b0..1f818cc23e822 100644 --- a/projects/packages/waf/src/class-compatibility.php +++ b/projects/packages/waf/src/class-compatibility.php @@ -244,6 +244,11 @@ public static function is_brute_force_running_in_jetpack() { * @return mixed The default value to return if the option does not exist in the database. */ public static function default_option_waf_ip_allow_list_enabled( $default, $option, $passed_default ) { + // Allow get_option() to override this default value + if ( $passed_default ) { + return $default; + } + // If the deprecated IP lists option was set to false, disable the allow list. // @phan-suppress-next-line PhanDeprecatedClassConstant -- Needed for backwards compatibility. $deprecated_option = Jetpack_Options::get_raw_option( Waf_Rules_Manager::IP_LISTS_ENABLED_OPTION_NAME, true ); @@ -256,11 +261,6 @@ public static function default_option_waf_ip_allow_list_enabled( $default, $opti return false; } - // Allow get_option() to override this default value - if ( $passed_default ) { - return $default; - } - // Default to enabling the allow list. return true; } diff --git a/projects/packages/waf/src/class-waf-rules-manager.php b/projects/packages/waf/src/class-waf-rules-manager.php index bada7d0f4ed3f..d657538138a12 100644 --- a/projects/packages/waf/src/class-waf-rules-manager.php +++ b/projects/packages/waf/src/class-waf-rules-manager.php @@ -53,15 +53,13 @@ public static function add_hooks() { // Re-activate the WAF any time an option is added or updated. add_action( 'add_option_' . self::AUTOMATIC_RULES_ENABLED_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); add_action( 'update_option_' . self::AUTOMATIC_RULES_ENABLED_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); - // @phan-suppress-next-line PhanDeprecatedClassConstant -- Needed for backwards compatibility. - add_action( 'add_option_' . self::IP_LISTS_ENABLED_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); - // @phan-suppress-next-line PhanDeprecatedClassConstant -- Needed for backwards compatibility. - add_action( 'update_option_' . self::IP_LISTS_ENABLED_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); - add_action( 'add_option_' . self::IP_ALLOW_LIST_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); add_action( 'add_option_' . self::IP_ALLOW_LIST_ENABLED_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); + add_action( 'update_option_' . self::IP_ALLOW_LIST_ENABLED_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); + add_action( 'add_option_' . self::IP_ALLOW_LIST_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); add_action( 'update_option_' . self::IP_ALLOW_LIST_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); - add_action( 'add_option_' . self::IP_BLOCK_LIST_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); add_action( 'add_option_' . self::IP_BLOCK_LIST_ENABLED_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); + add_action( 'update_option_' . self::IP_BLOCK_LIST_ENABLED_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); + add_action( 'add_option_' . self::IP_BLOCK_LIST_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); add_action( 'update_option_' . self::IP_BLOCK_LIST_OPTION_NAME, array( static::class, 'reactivate_on_rules_option_change' ), 10, 0 ); // Register the cron job. add_action( 'jetpack_waf_rules_update_cron', array( static::class, 'update_rules_cron' ) );