Skip to content

Instantly share code, notes, and snippets.

@zacscott
Last active January 17, 2023 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zacscott/88e6b26217c480d07838b994c6dd0ac8 to your computer and use it in GitHub Desktop.
Save zacscott/88e6b26217c480d07838b994c6dd0ac8 to your computer and use it in GitHub Desktop.
Hides all Yoast premium nags in the backend
<?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