bp_is_action_variable( string $action_variable = '', int|bool $position = false )
Check to see whether the current page matches a given action_variable.
Description
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
- $action_variable
-
(Optional) The action_variable being tested against.
Default value: ''
- $position
-
(Optional) 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.
Default value: false
Return
(bool) True if $action_variable matches at the $position provided.
Source
File: bp-core/bp-core-template.php
function bp_is_action_variable( $action_variable = '', $position = false ) { $is_action_variable = false; if ( false !== $position ) { // When a $position is specified, check that slot in the action_variables array. if ( $action_variable ) { $is_action_variable = $action_variable == bp_action_variable( $position ); } else { // If no $action_variable is provided, we are essentially checking to see // whether the slot is empty. $is_action_variable = !bp_action_variable( $position ); } } else { // When no $position is specified, check the entire array. $is_action_variable = in_array( $action_variable, (array)bp_action_variables() ); } /** * Filters whether the current page matches a given action_variable. * * @since BuddyPress 1.5.0 * * @param bool $is_action_variable Whether the current page matches a given action_variable. * @param string $action_variable The action_variable being tested against. * @param int $position The array key tested against. */ return apply_filters( 'bp_is_action_variable', $is_action_variable, $action_variable, $position ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.5.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.