If you design WordPress themes, you’ve no doubt had this happen: You get a call in the middle of the night from a frantic customer. They were in the backend of their site and they saw a number 1 with a circle next to update. So they clicked on it and saw that a plugin needed to be updated. Seeing that it could be done automatically, they clicked to have it happen. Now their site doesn’t work!
The automatic updates are a great thing, but sometimes you – as a designer – have to go in and make changes to plugin files. For example, I routinely get asked to update the Ninja Affiliate Links plugin so that the links appear in alphabetical order on the edit post screen instead of by their id number. So I have to go in and change the plugin itself. At this point, the plugin cannot be updated without losing the code modification I made.
If only there was a way to hide these update notification icons….WAIT! There is!
In my years of working with WordPress, I’ve created (and found via the web) a set of functions that will hide the menu items and notifications that I don’t want my clients to see. If this is something you’d like to do, keep reading!
First the two functions:
function custom_admin_css() { global $current_user; get_currentuserinfo(); if ($current_user->ID != 1) { echo '<style type="text/css">.plugin-count, .update-count {display: none!important; }</style>'; } } add_action('admin_head','custom_admin_css'); add_action('admin_init', 'cnk_lock_panels'); function cnk_lock_panels() { global $submenu, $userdata; get_currentuserinfo(); if ($userdata->ID != 1) { unset($submenu['index.php'][10]); } }
OK, so what we have here is two different functions. The functions assume that you, the administrator/designer of the site, is the first user created for the site (hence you have the ID of 1).
Function custom_admin_css()
- First, we set the global variable $current_user.
- Next we use the WordPress function get_currentuserinfo();. This takes the users information and stores it into the $current_user variable.
- We use that variable to test who the user is. If it’s NOT the first user, then we add a line of code. This line of code is a style that hides the update number buttons
Now we need to hide the actual Update Submenu item that’s under the Dashboard. That’s where our second function comes in to play:
Function cnk_lock_panels()
- This time, we set two global variables.
- If the user isn’t the first person, then we unset the following piece (the Updates submenu)
Simple, yet effective!
EDIT: After some research, I’ve found that instead of using the user ID, you can use your username for better control, since you aren’t always going to be the ID 1. So instead of using $current_user->ID and $userdata->ID, you can use $current_user->user_login and $userdata->user_login and use your own login name.