-
-
Save KingPin/49e9db66bcacfdbc7333 to your computer and use it in GitHub Desktop.
Remove Yoast SEO nag after update
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 | |
class ahRemoveYoastNag_Remove_Yoast_SEO_Nag { | |
private $yoastPluginFile; | |
public function __construct() { | |
$this->yoastPluginFile = "wordpress-seo/wp-seo.php"; | |
register_activation_hook( $this->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( $this->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