bp_is_action_variable

Check to see whether the current page matches a given action_variable.

Description

bp_is_action_variable( (string) $action_variable = '', (bool) $position = false ); 

Along with bp_is_current_component() and bp_is_current_action(), this function is mostly used to help determine when to use a given screen function.

In BP parlance, action_variables are an array made up of the URL chunks appearing after the current_action in a URL. For example, http://example.com/groups/my-group/admin/group-settings $action_variables[0] is group-settings..

Parameters (2)

0. $action_variable — Optional. (string) => ''
The action_variable being tested against.
1. $position — Optional. (bool) => false
The array key you're testing against. If you don't provide a $position, the function will return true if the $action_variable is found *anywhere* in the action variables array.

Usage

  1. if ( !function_exists( 'bp_is_action_variable' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template.php'; 
  3.  
  4. // The action_variable being tested against. 
  5. $action_variable = ''; 
  6. $position = false; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_is_action_variable($action_variable, $position); 
  10.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-template.php  
  1. function bp_is_action_variable( $action_variable = '', $position = false ) { 
  2. $is_action_variable = false; 
  3.  
  4. if ( false !== $position ) { 
  5. // When a $position is specified, check that slot in the action_variables array. 
  6. if ( $action_variable ) { 
  7. $is_action_variable = $action_variable == bp_action_variable( $position ); 
  8. } else { 
  9. // If no $action_variable is provided, we are essentially checking to see 
  10. // whether the slot is empty. 
  11. $is_action_variable = !bp_action_variable( $position ); 
  12. } else { 
  13. // When no $position is specified, check the entire array. 
  14. $is_action_variable = in_array( $action_variable, (array)bp_action_variables() ); 
  15.  
  16. /** 
  17. * Filters whether the current page matches a given action_variable. 
  18. * @since 1.5.0 
  19. * @param bool $is_action_variable Whether the current page matches a given action_variable. 
  20. * @param string $action_variable The action_variable being tested against. 
  21. * @param int $position The array key tested against. 
  22. */ 
  23. return apply_filters( 'bp_is_action_variable', $is_action_variable, $action_variable, $position );