← All changes
|
jetpack_vendor/automattic/jetpack-waf/src/class-waf-initializer.php
+9
-9
13.4.5
→
16.3
View file →
| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | */ |
| 17 | 17 | class Waf_Initializer { |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Option for storing whether or not the WAF files are potentially out of date. | |
| 20 | + * Option for storing whether the WAF files are potentially out of date. | |
| 21 | 21 | * |
| 22 | 22 | * @var string NEEDS_UPDATE_OPTION_NAME |
| 23 | 23 | */ |
| 24 | 24 | const NEEDS_UPDATE_OPTION_NAME = 'jetpack_waf_needs_update'; |
| @@ -35,10 +35,11 @@ | ||
| 35 | 35 | |
| 36 | 36 | // Ensure backwards compatibility |
| 37 | 37 | Waf_Compatibility::add_compatibility_hooks(); |
| 38 | 38 | |
| 39 | - // Register REST routes | |
| 40 | - add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) ); | |
| 39 | + // Register REST routes. Use a static callable so the controller class is not | |
| 40 | + // loaded into memory/opcache on requests that never reach `rest_api_init`. | |
| 41 | + add_action( 'rest_api_init', array( REST_Controller::class, 'register_rest_routes' ) ); | |
| 41 | 42 | |
| 42 | 43 | // Update the WAF after installing or upgrading a relevant Jetpack plugin |
| 43 | 44 | add_action( 'upgrader_process_complete', __CLASS__ . '::update_waf_after_plugin_upgrade', 10, 2 ); |
| 44 | 45 | |
| @@ -131,8 +132,12 @@ | ||
| 131 | 132 | public static function update_waf_after_plugin_upgrade( $upgrader, $hook_extra ) { |
| 132 | 133 | $jetpack_text_domains_with_waf = array( 'jetpack', 'jetpack-protect' ); |
| 133 | 134 | $jetpack_plugins_with_waf = array( 'jetpack/jetpack.php', 'jetpack-protect/jetpack-protect.php' ); |
| 134 | 135 | |
| 136 | + $hook_extra['type'] ??= null; | |
| 137 | + $hook_extra['action'] ??= null; | |
| 138 | + $hook_extra['plugins'] ??= array(); | |
| 139 | + | |
| 135 | 140 | // Only run on upgrades affecting plugins |
| 136 | 141 | if ( 'plugin' !== $hook_extra['type'] ) { |
| 137 | 142 | return; |
| 138 | 143 | } |
| @@ -150,9 +155,9 @@ | ||
| 150 | 155 | return; |
| 151 | 156 | } |
| 152 | 157 | if ( 'install' === $hook_extra['action'] && |
| 153 | 158 | ! empty( $upgrader->new_plugin_data['TextDomain'] ) && |
| 154 | - empty( in_array( $upgrader->new_plugin_data['TextDomain'], $jetpack_text_domains_with_waf, true ) ) | |
| 159 | + empty( in_array( $upgrader->new_plugin_data['TextDomain'] ?? null, $jetpack_text_domains_with_waf, true ) ) | |
| 155 | 160 | ) { |
| 156 | 161 | return; |
| 157 | 162 | } |
| 158 | 163 | |
| @@ -179,13 +184,8 @@ | ||
| 179 | 184 | } |
| 180 | 185 | } |
| 181 | 186 | |
| 182 | 187 | Waf_Compatibility::run_compatibility_migrations(); |
| 183 | - | |
| 184 | - Waf_Constants::define_mode(); | |
| 185 | - if ( ! Waf_Runner::is_allowed_mode( JETPACK_WAF_MODE ) ) { | |
| 186 | - return new WP_Error( 'waf_mode_invalid', 'Invalid firewall mode.' ); | |
| 187 | - } | |
| 188 | 188 | |
| 189 | 189 | try { |
| 190 | 190 | Waf_Rules_Manager::generate_ip_rules(); |
| 191 | 191 | Waf_Rules_Manager::generate_rules(); |