WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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.