Custom PHP code as a Panels selection rule Panels allows selection rules to be created with custom PHP code (disclaimer: I know this approach is insecure and should be avoided).

When adding PHP code as a selection rule, the helpful description states:


  Access will be granted if the following PHP code returns TRUE. Do not
  include . Note that executing incorrect PHP-code can break
  your Drupal site. All contexts will be available in the $contexts
  variable.


I made a function in a custom module to use for the selection rule:

function mymodule_selection_rule_is_location_set() {
  global $user;
  $user_fields = user_load($user-&gt;uid);
  if (isset($user_fields-&gt;field_acc_location['und']['0']['lat'])) {
    $location = $user_fields-&gt;field_acc_location['und']['0']['lat'];
  }
  if (empty($location)) {
    return FALSE;
  }
  else {
    return TRUE;
  }
}


However, when I set the selection rule as shown below, the selection rule is not triggered even when there is a value for $location and the function returns TRUE (confirmed with devel module).

Evaluates false as a selection rule even when the function returns TRUE

mymodule_selection_rule_is_location_set()


To get it to work, I had to write the selection rule like this:

Evaluates correctly

if (mymodule_selection_rule_is_location_set()) {
  return TRUE;
}


My question is why do I have to write it like the latter rather than the former?
I think the calling function which executes your PHP code would expect the RETURN true/false statement. Thus, you would need return to the calling function as returned by the called function.

return mymodule_selection_rule_is_location_set();


If you don't have return, the calling function would expect NULL and it would execute as FALSE always regardless of what is returned by the called function.