Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove the annoying Wordfence Notifications on plugin updates and plugin activation
<?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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.