Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glaubersilva/24e4ddc0a8408e08c15b110e4bc4c282 to your computer and use it in GitHub Desktop.
Save glaubersilva/24e4ddc0a8408e08c15b110e4bc4c282 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: [Defender] Remove Old Ignored Security Tweaks
* Plugin URI: https://premium.wpmudev.org/
* Description: If the user ignored a security tweak in the past that is no more available in the Defender options, the ignored tweaks counter need to be adjusted by this plugin.
* Author: Glauber Silva @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* Task: 0/11289012348292/1171986183162816
* License: GPLv2 or later
*
* @package Defender_Remove_Old_Ignored_Security_Tweaks
*/
defined( 'ABSPATH' ) || exit;
use WP_Defender\Module\Hardener\Model\Settings;
/**
* Catches the instance of Defender Settings and remove old ignored security tweaks that no more are used by the plugin.
*/
function wpmudev_remove_old_ignored_security_tweaks() {
if ( class_exists( 'WP_Defender\Module\Hardener\Model\Settings' ) ) {
$settings = Settings::instance();
$old_ignored_tweaks = array(
'wp-rest-api',
'sh-content-security',
);
foreach ($settings->ignore as $key => $value) {
if ( in_array( $value, $old_ignored_tweaks, true ) ) {
unset( $settings->ignore[ $key ] );
}
}
}
}
add_action( 'init', 'wpmudev_remove_old_ignored_security_tweaks' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment