settings = Plugin::get_settings( 'security' ); add_filter( 'adminease_settings_fields', [ $this, 'adminease_settings_fields' ] ); if( !empty( $this->settings['hide_wordpress_version'] ) ) { add_filter( 'the_generator', '__return_empty_string' ); add_filter( 'style_loader_src', [ $this, 'filter_asset_version' ], 9999 ); add_filter( 'script_loader_src', [ $this, 'filter_asset_version' ], 9999 ); } } /** * Modifies and returns the array of settings fields for the AdminEase plugin by adding a field to hide the WordPress version. * * @param array $fields The existing settings fields. * * @return array The modified settings fields, including the hide WordPress version field. */ public function adminease_settings_fields( array $fields ): array { $fields['security']['fields'][] = [ 'type' => 'switch', 'id' => 'hide-wordpress-version', 'name' => 'adminease[security][hide_wordpress_version]', 'value' => $this->settings['hide_wordpress_version'] ?? false, 'label_class' => 'pwp-switch', 'input_class' => 'pwp-field-input', 'label' => __( 'Hide WordPress version', 'adminease' ), 'description' => __( "By default, WordPress includes its version number in your site's source code, RSS feeds, and sometimes in script URLs. While this seems harmless, it can give attackers clues about potential vulnerabilities if you're running an outdated version. Hiding the WordPress version helps improve your site's security by making it less obvious which version you're using. This can be done with a simple code snippet added to your theme or a security plugin.", 'adminease' ), ]; return $fields; } /** * Filters the asset URL to remove the WordPress version query parameter. * This helps to hide the WordPress version from being exposed in asset URLs. * * @param string $src The source URL of the asset. * * @return string The filtered asset URL with the version parameter removed, if applicable. */ public function filter_asset_version( string $src ): string { $wp_version = get_bloginfo( 'version' ); if( false !== strpos( $src, 'ver=' . $wp_version ) ) { return remove_query_arg( 'ver', $src ); } return $src; } }