Skip to content

Instantly share code, notes, and snippets.

@peterwilsoncc
Forked from maddisondesigns/functions.php
Last active January 21, 2018 15:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterwilsoncc/ffc23acd711af056219f to your computer and use it in GitHub Desktop.
Save peterwilsoncc/ffc23acd711af056219f to your computer and use it in GitHub Desktop.
Remove Yoast SEO nag after update
<?php
class ahRemoveYoastNag_Remove_Yoast_SEO_Nag {
private $yoastPluginFile;
public function __construct() {
$this->yoastPluginFile = "wordpress-seo/wp-seo.php";
register_activation_hook( $yoastPluginFile, array( $this, 'ryn_remove_yoast_nag_on_activation' ) );
add_action( 'upgrader_process_complete', array( $this, 'ryn_remove_yoast_nag_after_update' ), 10, 2 );
}
/*
* Check if Yoast has been activated and remove nag
*/
function ryn_remove_yoast_nag_on_activation() {
// If this constant is defined we know Yoast SEO is activated
if ( defined( 'WPSEO_FILE' ) ) {
ahRemoveYoastNag_Remove_Yoast_SEO_Nag::ryn_remove_yoast_nag();
}
}
/*
* Remove Yoast nag after plugin has been updated
*/
function ryn_remove_yoast_nag_after_update( $upgrader_object, $options ) {
// Only remove the nag if Yoast SEO has been updated
if ( array_search( $yoastPluginFile, $options['plugins'] ) !== NULL ) {
if ( current_user_can( 'manage_options' ) ) {
ahRemoveYoastNag_Remove_Yoast_SEO_Nag::ryn_remove_yoast_nag();
}
}
}
/*
* Remove nag for all Admin users
*/
private function ryn_remove_yoast_nag() {
$pluginData = get_plugin_data( WPSEO_FILE, false );
$pluginVersion = $pluginData['Version'];
$adminUsers = get_users( array( 'role' => 'administrator' ) );
// Since the nag displays for all admin users, let's clear it for all admin users
foreach ( $adminUsers as $user ) {
if ( get_user_meta( $user->ID, 'wpseo_seen_about_version', true ) !== $pluginVersion ) {
update_user_meta( $user->ID, 'wpseo_seen_about_version', $pluginVersion );
}
}
}
}
new ahRemoveYoastNag_Remove_Yoast_SEO_Nag();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment