Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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');
share|improve this answer
    
Thank you! That worked perfectly :) –  fxfuture Oct 1 '10 at 8:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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