-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default option for automatic rules enabled for backwards compat
- Loading branch information
1 parent
db9681e
commit d9ae22e
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Class used to manage backwards-compatibility of the package | ||
* | ||
* @package automattic/jetpack-waf | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Waf; | ||
|
||
/** | ||
* Defines methods for ensuring backwards compatibility. | ||
*/ | ||
class Waf_Compatibility { | ||
|
||
/** | ||
* Add compatibilty hooks | ||
* | ||
* @since 0.8.0 | ||
* | ||
* @return void | ||
*/ | ||
public static function add_compatibility_hooks() { | ||
add_filter( 'default_option_' . Waf_Runner::AUTOMATIC_RULES_ENABLED_OPTION_NAME, __CLASS__ . '::default_option_waf_automatic_rules', 10, 3 ); | ||
} | ||
|
||
/** | ||
* Provides a default value for sites that installed the WAF | ||
* before the automatic rules option was introduced. | ||
* | ||
* @since 0.8.0 | ||
* | ||
* @param mixed $default The default value to return if the option does not exist in the database. | ||
* @param string $option Option name. | ||
* @param bool $passed_default Was get_option() passed a default value. | ||
* | ||
* @return mixed The default value to return if the option does not exist in the database. | ||
*/ | ||
public static function default_option_waf_automatic_rules( $default, $option, $passed_default ) { | ||
// Allow get_option() to override this default value | ||
if ( $passed_default ) { | ||
return $default; | ||
} | ||
|
||
return self::get_default_automatic_rules_option(); | ||
} | ||
|
||
/** | ||
* If the option is not available, use the WAF module status | ||
* to determine whether or not to run automatic rules | ||
*/ | ||
public static function get_default_automatic_rules_option() { | ||
return Waf_Runner::is_enabled(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters