Last active
March 11, 2017 11:08
-
-
Save zacscott/0a5271ff9ab75035ddb3 to your computer and use it in GitHub Desktop.
Disable Nags - WordPress plugin
This file contains hidden or 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 | |
/** | |
* Plugin Name: Disable Nags | |
* Description: Disables the WP core update nags in the backend on production | |
* Version: 1.1 | |
* Author: Zachary Scott | |
*/ | |
namespace zacscott; | |
/** | |
* | |
* NOTE: | |
* Originally adapted from the following tutorial: | |
* http://www.wpoptimus.com/626/7-ways-disable-update-wordpress-notifications/ | |
* | |
* @author Zachary Scott <[email protected]> | |
*/ | |
class DisableNags { | |
public function __construct() { | |
if ( ! ( defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV ) && ! ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) { | |
// WP core notices | |
add_filter( 'pre_site_transient_update_core', array( $this, 'remove_core_updates' ) ); | |
add_filter( 'pre_site_transient_update_plugins', array( $this, 'remove_core_updates' ) ); | |
add_filter( 'pre_site_transient_update_themes', array( $this, 'remove_core_updates' ) ); | |
} | |
} | |
// Disables the WP core updates | |
public function remove_core_updates() { | |
global $wp_version; | |
return (object) array( | |
'last_checked' => time(), | |
'version_checked' => $wp_version, | |
); | |
} | |
// Filters the admin notices | |
public function filter_admin_notices() { | |
global $wp_filter; | |
$admin_notices = $wp_filter[ 'admin_notices' ]; | |
if ( is_array( $admin_notices ) ) { | |
foreach ( $admin_notices as $id => $hooks ) { | |
foreach ( $hooks as $hook ) { | |
if ( ! isset( $hook['function'] ) ) { | |
continue; | |
} | |
$function = $hook['function']; | |
$killit = $this->check_admin_notices( $function ); | |
if ( $killit ) { | |
remove_action( 'admin_notices', $function ); | |
} | |
} | |
} | |
} | |
} | |
} | |
// Boot | |
new DisableNags(); | |
/** | |
* Copyright (C) 2014 2015, Zachary Scott <[email protected]> | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
* SOFTWARE. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment