Skip to:
Content

BuddyPress.org

Changeset 9684


Ignore:
Timestamp:
04/03/2015 01:40:17 PM (10 years ago)
Author:
johnjamesjacoby
Message:

XProfile: Clean up bp_profile_group_tabs():

  • Introduce bp_get_profile_group_tabs() for consistency
  • Have bp_profile_group_tabs() echo bp_get_profile_group_tabs()
  • Remove unused $group_name global
  • continue if field-group has no fields to avoid extra code intendation
  • Run output of field-group name through bp_get_the_profile_group_name filter for consistency
  • Also remove some trailing whitespace from bp-xprofile-template.php
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r9676 r9684  
    2020     */
    2121    public $current_group = -1;
    22    
     22
    2323    /**
    2424     * The number of groups returned by the paged query.
     
    2929     */
    3030    public $group_count;
    31    
     31
    3232    /**
    3333     * Array of groups located by the query.
     
    3838     */
    3939    public $groups;
    40    
     40
    4141    /**
    4242     * The group object currently being iterated on.
     
    5656     */
    5757    public $current_field = -1;
    58    
     58
    5959    /**
    6060     * The field count.
     
    6565     */
    6666    public $field_count;
    67    
     67
    6868    /**
    6969     * Field has data.
     
    7474     */
    7575    public $field_has_data;
    76    
     76
    7777    /**
    7878     * The field.
     
    9292     */
    9393    public $in_the_loop;
    94    
     94
    9595    /**
    9696     * The user ID.
     
    921921 * Output the tabs to switch between profile field groups.
    922922 *
     923 * @since BuddyPress (1.0.0)
     924 *
    923925 * @return string Field group tabs markup.
    924926 */
    925927function bp_profile_group_tabs() {
    926     global $group_name;
    927 
    928     $bp     = buddypress();
    929     $groups = bp_profile_get_field_groups();
    930 
    931     if ( empty( $group_name ) )
    932         $group_name = bp_profile_group_name(false);
    933 
    934     $tabs = array();
     928    echo bp_get_profile_group_tabs();
     929
     930    /**
     931     * Fires at the end of the tab output for switching between profile field
     932     * groups. This action is in a strange place for legacy reasons.
     933     *
     934     * @since BuddyPress (1.0.0)
     935     */
     936    do_action( 'xprofile_profile_group_tabs' );
     937}
     938
     939/**
     940 * Return the XProfile group tabs
     941 *
     942 * @since BuddyPress (2.3.0)
     943 *
     944 * @return string
     945 */
     946function bp_get_profile_group_tabs() {
     947
     948    // Get field group data
     949    $groups     = bp_profile_get_field_groups();
     950    $group_name = bp_get_profile_group_name();
     951    $tabs       = array();
     952
     953    // Loop through field groups and put a tab-lst together
    935954    for ( $i = 0, $count = count( $groups ); $i < $count; ++$i ) {
    936         if ( $group_name == $groups[$i]->name )
     955
     956        // Setup the selected class
     957        $selected = '';
     958        if ( $group_name === $groups[ $i ]->name ) {
    937959            $selected = ' class="current"';
    938         else
    939             $selected = '';
    940 
    941         if ( !empty( $groups[$i]->fields ) ) {
    942             $link = trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . $groups[$i]->id );
    943             $tabs[] = sprintf( '<li %1$s><a href="%2$s">%3$s</a></li>', $selected, $link, esc_html( $groups[$i]->name ) );
    944         }
     960        }
     961
     962        // Skip if group has no fields
     963        if ( empty( $groups[ $i ]->fields ) ) {
     964            continue;
     965        }
     966
     967        // Build the profile field group link
     968        $link   = trailingslashit( bp_displayed_user_domain() . buddypress()->profile->slug . '/edit/group/' . $groups[ $i ]->id );
     969
     970        // Add tab to end of tabs array
     971        $tabs[] = sprintf(
     972            '<li %1$s><a href="%2$s">%3$s</a></li>',
     973            $selected,
     974            esc_url( $link ),
     975            esc_html( apply_filters( 'bp_get_the_profile_group_name', $groups[ $i ]->name ) )
     976        );
    945977    }
    946978
     
    955987     */
    956988    $tabs = apply_filters( 'xprofile_filter_profile_group_tabs', $tabs, $groups, $group_name );
    957     foreach ( (array) $tabs as $tab )
    958         echo $tab;
    959 
    960     /**
    961      * Fires at the end of the tab output for switching between profile field groups.
    962      *
    963      * @since BuddyPress (1.0.0)
    964      */
    965     do_action( 'xprofile_profile_group_tabs' );
     989
     990    return join( '', $tabs );
    966991}
    967992
Note: See TracChangeset for help on using the changeset viewer.