From 2a554b22090937dd1916adb4447804e83c9d15a5 Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Thu, 10 Oct 2024 16:06:51 -0600 Subject: [PATCH] Move hooks out of Waf_Runner class --- .../packages/waf/src/class-waf-initializer.php | 6 ++++++ projects/packages/waf/src/class-waf-runner.php | 14 ++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/packages/waf/src/class-waf-initializer.php b/projects/packages/waf/src/class-waf-initializer.php index 57a64306d1812..1433dcfe14090 100644 --- a/projects/packages/waf/src/class-waf-initializer.php +++ b/projects/packages/waf/src/class-waf-initializer.php @@ -42,6 +42,9 @@ public static function init() { // Update the WAF after installing or upgrading a relevant Jetpack plugin add_action( 'upgrader_process_complete', __CLASS__ . '::update_waf_after_plugin_upgrade', 10, 2 ); + // Update the WAF after updating the rules settings + Waf_Rules_Manager::add_hooks(); + // Check for compatibility updates add_action( 'admin_init', __CLASS__ . '::check_for_updates' ); @@ -49,6 +52,9 @@ public static function init() { add_action( 'jetpack_activate_module_waf', __CLASS__ . '::on_waf_activation' ); add_action( 'jetpack_deactivate_module_waf', __CLASS__ . '::on_waf_deactivation' ); + // Update the WAF rule files on a schedule + Waf_Rules_Manager::schedule_rules_cron(); + // Brute force protection activation/deactivation hooks add_action( 'jetpack_activate_module_protect', __CLASS__ . '::on_brute_force_protection_activation' ); add_action( 'jetpack_deactivate_module_protect', __CLASS__ . '::on_brute_force_protection_deactivation' ); diff --git a/projects/packages/waf/src/class-waf-runner.php b/projects/packages/waf/src/class-waf-runner.php index a4275ae7e43b4..d1f6accfff282 100644 --- a/projects/packages/waf/src/class-waf-runner.php +++ b/projects/packages/waf/src/class-waf-runner.php @@ -37,12 +37,7 @@ public static function initialize() { if ( ! self::is_allowed_mode( JETPACK_WAF_MODE ) ) { return; } - // Don't run if in standalone mode - if ( function_exists( 'add_action' ) ) { - self::add_hooks(); - Waf_Rules_Manager::add_hooks(); - Waf_Rules_Manager::schedule_rules_cron(); - } + if ( ! self::did_run() ) { self::run(); } @@ -52,11 +47,10 @@ public static function initialize() { * Set action hooks * * @return void + * + * @deprecated $$next-version$$ Hooks have been moved to Waf_Initializer class. */ - public static function add_hooks() { - // Register REST routes. - add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) ); - } + public static function add_hooks() {} /** * Did the WAF run yet or not?