Last active
March 25, 2019 21:48
-
-
Save maddisondesigns/9a037399344dbac2d1fe37e2265fec60 to your computer and use it in GitHub Desktop.
Remove the annoying Wordfence Notifications on plugin updates and plugin activation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Remove the annoying Wordfence Notifications. Tested with Wordfence v6.3.2 | |
*/ | |
class ahRWN_Remove_Wordfence_Notification { | |
private $wordfencePluginFile; | |
public function __construct() { | |
$this->wordfencePluginFile = "wordfence/wordfence.php"; | |
register_activation_hook( $this->wordfencePluginFile, array( $this, 'rwn_remove_wordfence_notifications_on_activation' ) ); | |
// Only disable notifications if Wordfence is active | |
if ( defined( 'WORDFENCE_VERSION' ) ) { | |
// Remove WF noifications after updating plugins | |
add_action( 'upgrader_process_complete', array( $this, 'rwn_remove_wordfence_notification' ), 100, 2 ); | |
// Remove WF Notifcations after it refreshes its notifications | |
add_action( 'wordfence_refreshUpdateNotification', array( $this, 'rwn_remove_wordfence_notification' ), 100, 2 ); | |
} | |
} | |
/* | |
* Check if Wordfence has been activated and remove notifications | |
*/ | |
function rwn_remove_wordfence_notifications_on_activation() { | |
// If this constant is defined we know Wordfence has been activated | |
if ( defined( 'WORDFENCE_VERSION' ) ) { | |
ahRWN_Remove_Wordfence_Notification::rwn_remove_wf_notifications(); | |
} | |
} | |
/* | |
* Remove Wordfence Notifications after plugin has been updated | |
*/ | |
function rwn_remove_wordfence_notification( $upgrader_object, $options ) { | |
// Wordfence will update its notifcations when plugins are updated so lets remove them at the same time | |
if ( current_user_can( 'manage_options' ) ) { | |
ahRWN_Remove_Wordfence_Notification::rwn_remove_wf_notifications(); | |
} | |
} | |
/* | |
* Turn off any active Wordfence Notifications | |
*/ | |
private function rwn_remove_wf_notifications() { | |
global $wpdb; | |
$tableprefix = $wpdb->base_prefix; | |
$wpdb->update( | |
$tableprefix.'wfNotifications', | |
array('new' => 0), | |
array( 'new' => 1 ) | |
); | |
} | |
} | |
new ahRWN_Remove_Wordfence_Notification(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment