Skip to:
Content

BuddyPress.org

Changeset 4840


Ignore:
Timestamp:
07/24/2011 10:22:55 PM (13 years ago)
Author:
boonebgorges
Message:

Introduces wrapper functions for retrieving and checking items in bp->action_variables. action_variables audit for xprofile component. See #3325

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-template.php

    r4839 r4840  
    471471}
    472472
     473/**
     474 * Return the value of $bp->action_variables
     475 *
     476 * @package BuddyPress
     477 *
     478 * @param mixed $action_variables The action variables array, or false if the array is empty
     479 */
    473480function bp_action_variables() {
    474481    global $bp;
    475482    $action_variables = !empty( $bp->action_variables ) ? $bp->action_variables : false;
    476483    return apply_filters( 'bp_action_variables', $action_variables );
     484}
     485
     486/**
     487 * Return the value of a given action variable
     488 *
     489 * @package BuddyPress
     490 * @since 1.3
     491 *
     492 * @param int $position The key of the action_variables array that you want
     493 * @return str $action_variable The value of that position in the array
     494 */
     495function bp_action_variable( $position = 0 ) {
     496    $action_variables = bp_action_variables();
     497   
     498    $action_variable = isset( $action_variables[$position] ) ? $action_variables[$position] : false;
     499   
     500    return apply_filters( 'bp_action_variable', $action_variable, $position );
    477501}
    478502
     
    677701}
    678702
     703/**
     704 * Check to see whether the current page matches a given action.
     705 *
     706 * Along with bp_is_current_component() and bp_is_action_variable(), this function is mostly used
     707 * to help determine when to use a given screen function.
     708 *
     709 * In BP parlance, the current_action is the URL chunk that comes directly after the
     710 * current item slug. E.g., in
     711 *   http://example.com/groups/my-group/members
     712 * the current_action is 'members'.
     713 *
     714 * @package BuddyPress
     715 * @since 1.3
     716 *
     717 * @param str $action The action being tested against
     718 * @return bool True if the current action matches $action
     719 */
    679720function bp_is_current_action( $action = '' ) {
    680721    global $bp;
     
    684725
    685726    return false;
     727}
     728
     729/**
     730 * Check to see whether the current page matches a given action_variable.
     731 *
     732 * Along with bp_is_current_component() and bp_is_current_action(), this function is mostly used
     733 * to help determine when to use a given screen function.
     734 *
     735 * In BP parlance, action_variables are an array made up of the URL chunks appearing after the
     736 * current_action in a URL. For example,
     737 *   http://example.com/groups/my-group/admin/group-settings
     738 * $action_variables[0] is 'group-settings'.
     739 *
     740 * @package BuddyPress
     741 * @since 1.3
     742 *
     743 * @param str $action_variable The action_variable being tested against
     744 * @param int $position The array key you're testing against. If you don't provide a $position,
     745 *   the function will return true if the $action_variable is found *anywhere* in the action
     746 *   variables array.
     747 * @return bool
     748 */
     749function bp_is_action_variable( $action_variable = '', $position = false ) {
     750    $is_action_variable = false;
     751   
     752    if ( false !== $position ) {
     753        // When a $position is specified, check that slot in the action_variables array     
     754        if ( $action_variable ) {
     755            $is_action_variable = $action_variable == bp_action_variable( $position );
     756        } else {
     757            // If no $action_variable is provided, we are essentially checking to see
     758            // whether the slot is empty
     759            $is_action_variable = !bp_action_variable( $position );
     760        }
     761    } else {
     762        // When no $position is specified, check the entire array
     763        $is_action_variable = in_array( $action_variable, bp_action_variables() );
     764    }
     765   
     766    return apply_filters( 'bp_is_action_variable', $is_action_variable, $action_variable, $position );
    686767}
    687768
  • trunk/bp-xprofile/bp-xprofile-actions.php

    r4827 r4840  
    2323function xprofile_action_delete_avatar() {
    2424    global $bp;
    25 
    26     if ( $bp->profile->id != $bp->current_component || 'change-avatar' != $bp->current_action || !isset( $bp->action_variables[0] ) || 'delete-avatar' != $bp->action_variables[0] )
     25   
     26    if ( !bp_is_current_component( 'profile' ) || !bp_is_current_action( 'change-avatar' ) || !bp_is_action_variable( 'delete-avatar', 0 ) )
    2727        return false;
    2828
  • trunk/bp-xprofile/bp-xprofile-screens.php

    r4827 r4840  
    3737
    3838    // Make sure a group is set.
    39     if ( empty( $bp->action_variables[1] ) )
    40         bp_core_redirect( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/1' );
     39    if ( !bp_action_variable( 1 ) )
     40        bp_core_redirect( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1' );
    4141
    4242    // Check the field group exists
    43     if ( ( !empty( $bp->action_variables[0] ) && 'group' != $bp->action_variables[0] ) || !xprofile_get_field_group( $bp->action_variables[1] ) ) {
     43    if ( !bp_is_action_variable( 'group' ) || !xprofile_get_field_group( bp_action_variable( 1 ) ) ) {
    4444        bp_do_404();
    4545        return;
     
    5454        // Check we have field ID's
    5555        if ( empty( $_POST['field_ids'] ) )
    56             bp_core_redirect( trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $bp->action_variables[1] ) );
     56            bp_core_redirect( trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . bp_action_variable( 1 ) ) );
    5757
    5858        // Explode the posted field IDs into an array so we know which
     
    6868                if ( !empty( $_POST['field_' . $field_id . '_day'] ) && is_numeric( $_POST['field_' . $field_id . '_day'] ) ) {
    6969                    // Concatenate the values
    70                     $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' .
    71                                     $_POST['field_' . $field_id . '_month'] . ' ' .
    72                                     $_POST['field_' . $field_id . '_year'];
     70                    $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
    7371
    7472                    // Turn the concatenated value into a timestamp
     
    116114
    117115            // Redirect back to the edit screen to display the updates and message
    118             bp_core_redirect( trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $bp->action_variables[1] ) );
     116            bp_core_redirect( trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable( 1 ) ) );
    119117        }
    120118    }
     
    137135        return false;
    138136
    139     if ( !empty( $bp->action_variables ) ) {
     137    if ( bp_action_variables() ) {
    140138        bp_do_404();
    141139        return;
  • trunk/bp-xprofile/bp-xprofile-template.php

    r4831 r4840  
    695695
    696696function bp_profile_group_name( $deprecated = true ) {
    697     global $bp;
    698 
    699     $group_id = !empty( $bp->action_variables[1] ) ? $bp->action_variables[1] : 1;
    700 
    701     if ( !is_numeric( $group_id ) )
    702         $group_id = 1;
    703 
    704     if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
    705         $group = new BP_XProfile_Group($group_id);
    706         wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
    707     }
    708 
    709697    if ( !$deprecated ) {
    710698        return bp_get_profile_group_name();
     
    714702}
    715703    function bp_get_profile_group_name() {
    716         global $bp;
    717 
    718         $group_id = !empty( $bp->action_variables[1] ) ? $bp->action_variables[1] : 1;
    719 
     704        if ( !$group_id = bp_action_variable( 1 ) )
     705            $group_id = 1;
     706           
    720707        if ( !is_numeric( $group_id ) )
    721708            $group_id = 1;
     
    764751}
    765752    function bp_get_current_profile_group_id() {
    766         global $bp;
    767 
    768         if ( empty( $bp->action_variables[1] ) || !$profile_group_id = $bp->action_variables[1] )
     753        if ( !$profile_group_id = bp_action_variable( 1 ) )
    769754            $profile_group_id = 1;
    770755
Note: See TracChangeset for help on using the changeset viewer.