From 86a7647998c7d1a156f9f3ae36d9e1428b950648 Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Tue, 15 Oct 2024 11:18:01 -0600 Subject: [PATCH] Use update_option to ensure empty/falsey options are updated --- projects/packages/waf/src/class-waf-runner.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/projects/packages/waf/src/class-waf-runner.php b/projects/packages/waf/src/class-waf-runner.php index d1f6accfff282..7747335ac5c82 100644 --- a/projects/packages/waf/src/class-waf-runner.php +++ b/projects/packages/waf/src/class-waf-runner.php @@ -300,7 +300,7 @@ public static function initialize_filesystem() { } /** - * Activates the WAF by generating the rules script and setting the version + * Activates the WAF by generating the rules script and setting the related options. * * @throws Waf_Exception If the firewall mode is invalid. * @throws Waf_Exception If the activation fails. @@ -308,16 +308,15 @@ public static function initialize_filesystem() { * @return void */ public static function activate() { - $version = get_option( Waf_Rules_Manager::VERSION_OPTION_NAME ); - if ( ! $version ) { - add_option( Waf_Rules_Manager::VERSION_OPTION_NAME, Waf_Rules_Manager::RULES_VERSION ); + // Ensure version and mode options exist and have non-empty values. + if ( ! get_option( Waf_Rules_Manager::VERSION_OPTION_NAME ) ) { + update_option( Waf_Rules_Manager::VERSION_OPTION_NAME, Waf_Rules_Manager::RULES_VERSION ); } - - $mode = get_option( self::MODE_OPTION_NAME ); - if ( ! $mode ) { - add_option( self::MODE_OPTION_NAME, 'normal' ); + if ( ! get_option( self::MODE_OPTION_NAME ) ) { + update_option( self::MODE_OPTION_NAME, 'normal' ); } + // Ensure options exist. add_option( Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME, false ); add_option( self::SHARE_DATA_OPTION_NAME, true );