| @@ -29,9 +29,8 @@ | ||
| 29 | 29 | /** |
| 30 | 30 | * Initializes the model and service, registers routes, and sets up scheduled events if the model is active. |
| 31 | 31 | */ |
| 32 | 32 | public function __construct() { |
| 33 | - add_filter( 'wp_defender_advanced_tools_data', array( $this, 'script_data' ) ); | |
| 34 | 33 | $this->model = wd_di()->get( \WP_Defender\Model\Setting\Security_Headers::class ); |
| 35 | 34 | $this->init_headers(); |
| 36 | 35 | $this->register_routes(); |
| 37 | 36 | } |
| @@ -49,21 +48,8 @@ | ||
| 49 | 48 | return new \WP_Defender\Model\Setting\Security_Headers(); |
| 50 | 49 | } |
| 51 | 50 | |
| 52 | 51 | /** |
| 53 | - * Provide data to the frontend via localized script. | |
| 54 | - * | |
| 55 | - * @param array $data Data collection is ready to passed. | |
| 56 | - * | |
| 57 | - * @return array Modified data array with added this controller data. | |
| 58 | - */ | |
| 59 | - public function script_data( array $data ): array { | |
| 60 | - $data['security_headers'] = $this->data_frontend(); | |
| 61 | - | |
| 62 | - return $data; | |
| 63 | - } | |
| 64 | - | |
| 65 | - /** | |
| 66 | 52 | * Save settings. |
| 67 | 53 | * |
| 68 | 54 | * @param Request $request The request object containing new settings data. |
| 69 | 55 | * |
| @@ -84,9 +70,9 @@ | ||
| 84 | 70 | $prev_data = $this->get_model()->get_old_settings(); |
| 85 | 71 | |
| 86 | 72 | $is_active_prev_data = false; |
| 87 | 73 | |
| 88 | - if ( ! empty( $prev_data ) ) { | |
| 74 | + if ( array() !== $prev_data ) { | |
| 89 | 75 | $is_active_prev_data = true === $prev_data['sh_xframe'] || true === $prev_data['sh_xss_protection'] |
| 90 | 76 | || true === $prev_data['sh_content_type_options'] || true === $prev_data['sh_feature_policy'] |
| 91 | 77 | || true === $prev_data['sh_strict_transport'] || true === $prev_data['sh_referrer_policy']; |
| 92 | 78 | } |
| @@ -233,11 +219,33 @@ | ||
| 233 | 219 | * @return array An array of strings. |
| 234 | 220 | */ |
| 235 | 221 | public function export_strings(): array { |
| 236 | 222 | return array( |
| 237 | - $this->get_model()->is_any_activated() ? esc_html__( 'Active', 'defender-security' ) : esc_html__( | |
| 238 | - 'Inactive', | |
| 223 | + \WP_Defender\Model\Setting\Security_Headers::get_module_name() . ' ' | |
| 224 | + . ( $this->get_model()->is_any_activated() ? esc_html__( 'active', 'defender-security' ) : esc_html__( | |
| 225 | + 'inactive', | |
| 239 | 226 | 'defender-security' |
| 240 | - ), | |
| 227 | + ) ), | |
| 228 | + ); | |
| 229 | + } | |
| 230 | + | |
| 231 | + /** | |
| 232 | + * Generates configuration strings based on the provided configuration. | |
| 233 | + * | |
| 234 | + * @param array $config Configuration data. | |
| 235 | + * | |
| 236 | + * @return array Returns an array of configuration strings. | |
| 237 | + */ | |
| 238 | + public function config_strings( array $config ): array { | |
| 239 | + $active = ( isset( $config['sh_xframe'] ) && $config['sh_xframe'] ) | |
| 240 | + || ( isset( $config['sh_xss_protection'] ) && $config['sh_xss_protection'] ) | |
| 241 | + || ( isset( $config['sh_content_type_options'] ) && $config['sh_content_type_options'] ) | |
| 242 | + || ( isset( $config['sh_feature_policy'] ) && $config['sh_feature_policy'] ) | |
| 243 | + || ( isset( $config['sh_strict_transport'] ) && $config['sh_strict_transport'] ) | |
| 244 | + || ( isset( $config['sh_referrer_policy'] ) && $config['sh_referrer_policy'] ); | |
| 245 | + | |
| 246 | + return array( | |
| 247 | + \WP_Defender\Model\Setting\Security_Headers::get_module_name() . ' ' | |
| 248 | + . ( $active ? esc_html__( 'active', 'defender-security' ) : esc_html__( 'inactive', 'defender-security' ) ), | |
| 241 | 249 | ); |
| 242 | 250 | } |
| 243 | 251 | } |