Last active
January 17, 2023 09:51
-
-
Save zacscott/88e6b26217c480d07838b994c6dd0ac8 to your computer and use it in GitHub Desktop.
Hides all Yoast premium nags in the backend
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 | |
/** | |
* Plugin Name: Disable Yoast Nags | |
* Description: Hides all Yoast premium nags in the backend. | |
* Version: 1.0 | |
* Author: Zachary Scott | |
*/ | |
namespace zacscott; | |
/** | |
* Disables Yoast premium nags in the WP backend. | |
* | |
* @author Zachary Scott <zscott.dev@thecode.co> | |
*/ | |
class DisableYoastNags { | |
function __construct() { | |
add_action( 'admin_init', array( $this, 'filter_admin_notices' ) ); | |
} | |
function filter_admin_notices() { | |
global $wp_filter; | |
foreach ( $wp_filter[ 'admin_notices' ] as $id => $hooks ) { | |
foreach ( $hooks as $hook ) { | |
if ( !isset( $hook[ 'function' ] ) ) continue; | |
$callback = $hook[ 'function' ]; | |
// Yoast free license nag | |
if ( is_array( $callback ) && ( $callback[0] instanceof \Yoast_Plugin_License_Manager ) ) { | |
remove_action( 'admin_notices', $callback ); | |
} | |
} | |
} | |
} | |
} | |
// Boot | |
new DisableYoastNags(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment