0
0

Notice: Undefined index and has_cap issues

2011/05/11 · 评论 

Very often when you maintain your wordpress blog, you get a lot of unexpected warning messages when debug is turned on. These warning messages do not cause serious problems when it is inactive, but you are a perfectionist and just want to get rid of them. wait, perfectionist is good, I am too. Here, there are two common warning messages you may encounter when you are running wordpress 3.*.

The first warning message is “Notice: has_cap was called with an argument that is deprecated since version 2.0! …” .
As the warning suggests, this messages is issued when your site is calling some API which are deprecated. But, wordpress core source will not possibly do this, the source is from plugins and themes that are externals to core source. This is a very common problem, because there are thousands of plugins and themes, some of which are not kept updating in align with the newest wordpress version. So what is the causes? well,the cause is the difference assigning capabilities for plugins and themes to your site users between version wp 2.* and wp 3.*. To fix this, you need to find out which plugin or theme causes the issue. and further find out where the hook is(read more about what hook is here). for example:

 add_dashboard_page( "test", "test", 3, "test", "test"); 

Above, the number 3 is the capability that this plugin assigns to your site user. The use of this number is deprecated since version 3.0. instead, you can easily change it to:

 add_dashboard_page( "test", "test", 'level_3', "test", "test"); 

or

add_dashboard_page( "test", "test", 'edit_posts', "test", "test"); 

you can read more about roles and capabilities here.

The second warning message is: “Notice: Undefined index: cache_time in /customers/….”
This issue is caused by calling undefined variables in php. Typically, developers want to get value from get and post parameters, but without checking if there is actual value passed in. To fix this, find out all the locations where issues generate. change something like this:

$q=$_GET['param'];

to

if(isset($_GET['param']))$q=$_GET['param'];

After done these, you will probably get a clean wordpress blog. Hope this help you.

您可能也喜欢

与大家分享点什么吧: