WordPress.org

Make WordPress Core

Changes between Initial Version and Version 2 of Ticket #23861


Ignore:
Timestamp:
03/25/13 14:29:40 (2 years ago)
Author:
johnbillion
Comment:

The current_user_can() function, along with all the others in pluggable.php, are pluggable (hence the file name). This means they are explicitly defined after plugins are loaded so that plugins may override them (for example to implement a different authentication mechanism).

This means you cannot use any of the functions in pluggable.php directly in a plugin file (which you shouldn't do anyway). You must use them inside functions which are called on hooks.

For example:

function my_special_function() {
  if ( current_user_can( 'do_whatever' ) )
  // do your thing
}
add_action( 'plugins_loaded', 'my_special_function' );

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #23861

    • Property Status changed from new to closed
    • Property Resolution changed from to invalid
    • Property Milestone changed from Awaiting Review to
  • Ticket #23861 – Description

    initial v2  
    88or 
    99- add following line at the end of wp-content/plugins/hello.php: 
    10 -- echo current_user_can("switch_themes"); // any capability causes the error 
     10{{{ 
     11echo current_user_can("switch_themes"); 
     12// any capability causes the error 
     13}}} 
    1114 
    1215My environment: