Skip to content

Commit

Permalink
Use update_option to ensure empty/falsey options are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller committed Oct 29, 2024
1 parent 36ce871 commit 86a7647
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions projects/packages/waf/src/class-waf-runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,23 @@ 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.
*
* @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 );

Expand Down

0 comments on commit 86a7647

Please sign in to comment.