0

I'm trying to edit a plugin so that it only shows it's submenu if the user is an administrator but I don't know how to define the value of the variable before the function:

function load_view( $name, $params = array(), $print_submenu_navigation = false ) {

My code so far is:

if (current_user_can('administrator')) {
 $print_submenu_navigation = true;  
}
else {
 $print_submenu_navigation = false;
}

If I put this before the function I get a php error telling me it's expecting a function.

1 Answer 1

1

Wrong approach. $print_submenu_navigation will be filled in local scope when function is called with arguments, it's not a matter of global variables.

You want something like this when function is called (not defined):

load_view( 'name', array(), current_user_can('administrator') ) {

Alternatively you can add your snippet inside the function, then input value for $print_submenu_navigation will overwritten with result of your check.

And it's shorter to write it like this, function returns boolean:

$print_submenu_navigation = current_user_can('administrator');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.