So I am trying to run a simple if statement inside the wp-functions.php file and am using current_user_can
. However I get PHP errors like: “Fatal error: Call to undefined function current_user_can() in…”
If anyone could take a look at my code, that would be much appreciated.
The code I am using is here:
global $current_user_can;
if ( current_user_can( 'manage_options' ) ) {
/* Admin User */
} else {
/* Member */
echo "<p>something</p>";
}
This usually happens because pluggable.php is not loaded by some reason. Try to add this before your function;
It just checks if pluggable is loaded, and if not, it includes it.
if you want to check directly the role of the member, you can use this code:
if you are creating a plugin, you must have to include like