How to Fix the common has_cap error notices in your WordPress site
A common error that is popping up a lot with later versions of wordpress looks something like this:
Notice: has_cap was called with an argument that is deprecated since version 2.0! Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead. in /home/xxxx/public_html/wp-includes/functions.php on line xxxx
this can usually be traced back to a plugin and the error may only show when debug mode is turned on in your wp-config.php file
Often the recommended fix is to simply get rid of these errors by turning off debug mode but that does not fix anything, it just stops the error from being displayed on the site.
I prefer to leave debug mode on and actually correct any errors.
These kinds of errors seem to result as an incompatibility problem with some functions like "get_options" that are no longer working correctly with wordpress 3.0. and above.
Perhaps the functions work ok but the parameters are no longer correct.
To find the solution we need to disable plugins one by one, until you find the one that is causing the warning. Then, find a call like "add_submenu_page" or "
add_options_page" or similar, that is using a numeric user level instead of a capability name. Substitute the numeric user level with a compatible capability or user role and the warning should vanish.
Here is an example using WP v.3.2.1 and Audio-Player v.18.104.22.168 plugin which was giving this error:
go to line 176 of audio-player.php (/wp-content/plugins/audio-player/audio-player.php)
of course other plugins will require some searching to find the correct line but you will be looking for a similar line which starts with
"add_options_page" or add_submenu_page" The line will look something like this:
$pageName = add_options_page
Moving on with the example...
Once you have the file open in your chosen editing method:
$pageName = add_options_page("Audio player options", "Audio Player", 8, $this->optionsPageName, array(&$this, "outputOptionsSubpanel"));
Change the 8 (a numeric user level) to 'activate_plugins' (single quotes included), so that the line looks like this:
$pageName = add_options_page("Audio player options", "Audio Player", 'activate_plugins', $this->optionsPageName, array(&$this, "outputOptionsSubpanel"));
so for a different plugin simply do a search for "
add_options_page" and loog for a number value being used (8 in the above example) .. save and hopefully your error has gone.
change 8 to "activate_plugins"
This is only one particular fix for the above specific plugin which was using the number "8" instead of "activate_plugins" in relation to add_options_page
Troubleshooting Other Plugins
The main issue seems to be a problem with defining roles and capabilities within WordPress.
When we register a new user we can define their roles (Admin, Super Admin, Editor, Contributor, Subscriber).
Each of these roles has different skills (reading a page / post, edit a page / post, add a page / post, etc)
To learn more about the roles and capabilities provided useful wordpress codex: http://codex.wordpress.org/Function_Reference/add_menu_page
If we have a plugin or template that generates a new menu in our back end functions such as safely used add_theme_page, add_menu_page, add_submenu_page, add_options_page etc
Consider the statement of one of these functions
<? Php add_menu_page ($ page_title, $ menu_title, $ capability, $ menu_slug, $ function, $ icon_url, $ position);?>
The third parameter, $capability, accepts as a value that defines the different capabilities of WordPress. This menu gives access to only users (roles) that have that capability.
The error in question is generated because we do not pass a value of type capacity, we offer a value of type User Level, the old system to limit user roles.
IMPORTANT: The user levels ceased to be used in WordPress 2.0 and in WordPress 3.0 they were completely eliminated.
If a plugin developer has not updated their plugin then you will get these errors.
Read more here: http://codex.wordpress.org/User_Levels
In case you do not understand much I'm posting a link which helped me to understand that this was the problem: fix-notice-has_cap-was-called-with-an-argument-that-is- deprecated-since-version-2-0-in-wordpress /
So for example, using 10 versus 'manage_options' will cause this same kind of error notice.
when troubleshooting your plugins use the table at the bottom of http://codex.wordpress.org/Roles_and_Capabilities#User_Level_to_Role_Conversion to figure out the right string value.
If you have shell access you can also run this command on your plugins directory to find all of the plugins suffering from the same condition:
(change number values as required eg you may need to enter number 10 instead of 0-9 )
grep -HnR "add_[a-zA-Z].*_page.*, [0-9]*," ./
I ran that command over my plugins directory and found 14 plugins using the old numeric role identifier :-/ .
I have come across this error in many plugins. Often reporting the error to the plugin developer will help them become aware of the issue and it is relatively easy for them to address it and bring their plugin up-to-date. otherwise you can fix it within your plugins yourself however do be aware that if the plugin later gets updated by the developer within the wordpress repository without the correct fix for this issue being applied and you then run the automatic plugin update then your fix will get overwritten and the error will return so it is always best to notify the plugin developer and get them to fix their plugin at the source. You can always fix it yourself and then provide the developer with the information about how you corrected the problem manually on your own site and most developers will more than likely be grateful for you taking the time to notify them and make their job easier by even giving them a fix. To do this you can visit the plugins page in the wordpress repository and visit the developers support forum or send them an email.