Disable update notifications for non-admin

I successfully migrated my first site without a hitch! I would be grateful if someone could let me know the code to disable all update notifications for non-admin users. I currently have the following in my theme’s functions.php and would appreciate any edits to make it compatible with ClassicPress.

<?php if ( !current_user_can('administrator') ) { add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) ); } ?>
1 Like

If this code works in WordPress, then there are no modifications needed for ClassicPress.

1 Like

I thought there might be a change to wp_version_check so thanks for clarifying James. :+1:.

2 Likes

I would just note that create_function has been deprecated in PHP 7.2.

3 Likes

Thanks for the heads-up ithilien. I think the following should be ok instead.

// Disable ClassicPress update notifications for all except administrators
function remove_core_updates(){
global $wp_version;return(object) array(‘last_checked’=> time(),‘version_checked’=> $wp_version,);
}
if ( !current_user_can(‘administrator’) ) {
add_filter(‘pre_site_transient_update_core’,‘remove_core_updates’); //hide updates for ClassicPress itself
add_filter(‘pre_site_transient_update_plugins’,‘remove_core_updates’); //hide updates for all plugins
add_filter(‘pre_site_transient_update_themes’,‘remove_core_updates’); //hide updates for all themes
}

The following is a slightly modified version for anyone on WordPress who is sticking with the 4.9 branch for now but wants to get rid of the “update to 5.x” notice. It hides this notice for everyone but shows available plugin and theme updates for administrators.

// Disable WordPress update notifications 
function remove_core_updates(){
  global $wp_version;return(object) array('last_checked'=> time(),'version_checked'=> $wp_version,);
}
add_filter('pre_site_transient_update_core','remove_core_updates'); //hide WordPress updates for ALL users 
if ( !current_user_can('administrator') ) {
  add_filter('pre_site_transient_update_plugins','remove_core_updates'); //hide all plugin updates for non-admins
  add_filter('pre_site_transient_update_themes','remove_core_updates'); //hide all theme updates for non-admins
}

@Padraig in order to produce a more readable code block you can surround your code in three backquotes, like this:

```
code goes here
```
3 Likes

You learn something new every day. I never even new that key existed. Took me ages to find it on the keyboard under the tilda, another key I rarely use.

3 Likes

I didn’t realise that. Thanks for the tip @james +1:

1 Like

This code and similar solutions have a significant drawback: you will also not receive notifications for security releases on the WP 4.9.x branch!

Yes, it’s just a temporary measure for me. I’ve my sites on 4.9.9 at the moment and just want to get rid of the annoying 5.x nag screen before moving to ClassicPress when version 1 is released. I’m keeping an eye out for any WP security releases in the meantime.

I actually updated to WP 5.1 by accident when updating some plugins but thankfully I use UpDraftPlus so restoring a backup was really easy. From my tests, UpDraftPlus appears to be working great with ClassicPress as well.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.