Fix “Notice: has_cap was called with an argument that is deprecated since version 2.0!” in WordPress

Recently I turned WP_DEBUG on:


//wp-config.php

define('WP_DEBUG', true);

and noticed that my plugins were throwing notices that read:

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. 

After fixing my own, it appeared that most other plugins active were throwing the same notices, so I thought I’d post the fix here.

In my case the issue stemmed from how I’d declared the menu pages. I was using numerical role identifiers (deprecated) and string role identifiers. Neither are correct because the menu and submenu functions take capabilities not roles.


//Wrong, using '8' as a role identifier

add_menu_page( 'UtMan', 'UtMan', 8, 'utman', array(&$this, 'mainAdmin'), null, 6);

//Changed to a capability, correct

add_menu_page( 'UtMan', 'UtMan', 'edit_pages', 'utman', array(&$this, 'mainAdmin'), null, 6);

//Wrong, using 'administrator' as a role identifier

add_submenu_page('utman', 'UtMan Requests', 'Requests', 'administrator', 'utman-requests', array(&$this, 'requestPage'));

//Changed to a capability, correct

add_submenu_page('utman', 'UtMan Requests', 'Requests', 'edit_pages', 'utman-requests', array(&$this, 'requestPage'));

More here:

http://codex.wordpress.org/Adding_Administration_Menus

http://codex.wordpress.org/Roles_and_Capabilities

  • Leave a Comment

  • http://twitter.com/volomike Mike McKee

    Thanks for this! I was wondering what the heck was going on and there wasn’t a lot of documentation on this. I’m a WordPress Plugin coder too, and have been getting used to the changes with WP3.

  • http://blog.tumbledesign.com/ Nicky Hajal

    Hey Mike,

    So glad this helped! Feel free to share any links to your plugins in the comments, would love to check them out.

    -Nicky

  • http://inklight.lol-hosting.tk/blog/ Salem

    thanks for advice…
    i notice too many errors with must of Plugins .. and i totally forget that I turning debug mode on .. it’s weird that much of plugins that have errors like this ..

  • Dudesl

    Hey! tanks for this. I posted in the WordPress.org forum your solution. Here the link: http://wordpress.org/support/topic/has_cap-was-called-with-an-argument-that-is-deprecated?replies=8#post-1775460

  • Anca

    Thanks for the solution! I found your site through @dudesl, who posted to the wordpress.org site.

  • http://thomas-genin.com Thomas

    Thanks men, it helps a lot !

  • http://www.budo.sanok.pl Langus

    Where can I find comparison of numerical and string identifiers of functions? For example, which string identifier has function with ’10′ numerical identifier?

  • Rob Daniels

    Thanks!

  • markp_2000

    Thanks – I made the changes but it is still throwing the errors. I use

    grep -r "add_page_menu" .

    to find other files I need to correct.

  • markp_2000

    Thanks – I made the changes but it is still throwing the errors. I use

    grep -r "add_page_menu" .

    to find other files I need to correct.

  • http://blog.tumbledesign.com/ Nicky Hajal

    Are you sure that all the errors are coming from your plugin? They may be coming from others.

  • markp_2000

    I still had issues after I updated the suggested items. I ran a grep command to locate the remain issues.

    I used this command and five other plugins had the same issue as well.

    [blockquote]grep -r “add_[a-zA-Z].*_page.*, [0-9],” . [/blockquote]

    I used 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.

  • http://www.facebook.com/people/Jørn-Støylen/551440905 Jørn Støylen

    Thanks! I just fixed some warnings from a plugin with your help – and have notified its author!

  • yijie li

    I also find out the a slightly different fix for this, ckeck it here http://yjlblog.com/notice-undefined-index-and-has_cap-issues/

  • http://keriat.ru Beresnev Sergey

    Thz for information

  • http://twentyfiveautumn.com Ray

    thanks for this info! it really helped

  • Anonymous

    Thank’s for sharing this Nicky. I’ve found that it happens with plugins that use the add_options_page() function as well.

  • Anonymous

    THANK YOU!

  • brijesh dekivadiya

    Hey Friends,
    You can also solve this bug like thatyou just need to set 
    deprecated_argument_trigger_error  as false in function.php file

    example:
    function _deprecated_argument( $function, $version, $message = null ) { do_action( ‘deprecated_argument_run’, $function, $message, $version ); // Allow plugin to filter the output error trigger if ( WP_DEBUG && apply_filters( ‘deprecated_argument_trigger_error’, false ) ) { if ( ! is_null( $message ) ) trigger_error( sprintf( __(‘%1$s was called with an argument that is deprecated since version %2$s! %3$s’), $function, $version, $message ) ); else trigger_error( sprintf( __(‘%1$s was called with an argument that is deprecated since version %2$s with no alternative available.’), $function, $version ) ); }}
    —MR.10

  • lucight

    Nice thanks, still helping out.

  • Chris

    Awesome! thanks. I’m not much of a programmer, but you helped me fix two different plugins causing this problem

  • zul

    THANKS A LOT!

  • http://www.miscy.net/ Max Pen

    How do I fix this for Custom-More-Link-Complete plugin?