Skip to:
Content

BuddyPress.org

Changeset 9205


Ignore:
Timestamp:
11/29/2014 07:57:25 PM (10 years ago)
Author:
djpaul
Message:

Admin: refactor bp_core_admin_tabs and create a get function.

This is a development aid for contributors experimenting with modifying different parts of BuddyPress screens in side wp-admin.
The nav tabs were defined and templated in the same function, making it hard to modify the output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/admin/bp-core-functions.php

    r9172 r9205  
    372372 *
    373373 * @since BuddyPress (1.5)
    374  * @param string $active_tab Name of the tab that is active
     374 * @param string $active_tab Name of the tab that is active. Optional.
    375375 */
    376376function bp_core_admin_tabs( $active_tab = '' ) {
    377 
    378     // Declare local variables
    379377    $tabs_html    = '';
    380378    $idle_class   = 'nav-tab';
    381379    $active_class = 'nav-tab nav-tab-active';
    382 
    383     // Setup core admin tabs
     380    $tabs         = apply_filters( 'bp_core_admin_tabs', bp_core_get_admin_tabs( $active_tab ) );
     381
     382    // Loop through tabs and build navigation
     383    foreach ( array_values( $tabs ) as $tab_data ) {
     384        $is_current = (bool) ( $tab_data['name'] == $active_tab );
     385        $tab_class  = $is_current ? $active_class : $idle_class;
     386        $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>';
     387    }
     388
     389    echo $tabs_html;
     390    do_action( 'bp_admin_tabs' );
     391}
     392
     393/**
     394 * Get the data for the tabs in the admin area.
     395 *
     396 * @since BuddyPress (2.2.0)
     397 * @param string $active_tab Name of the tab that is active. Optional.
     398 */
     399function bp_core_get_admin_tabs( $active_tab = '' ) {
    384400    $tabs = array(
    385401        '0' => array(
     
    410426    }
    411427
    412     // Allow the tabs to be filtered
    413     $tabs = apply_filters( 'bp_core_admin_tabs', $tabs );
    414 
    415     // Loop through tabs and build navigation
    416     foreach ( array_values( $tabs ) as $tab_data ) {
    417         $is_current = (bool) ( $tab_data['name'] == $active_tab );
    418         $tab_class  = $is_current ? $active_class : $idle_class;
    419         $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>';
    420     }
    421 
    422     // Output the tabs
    423     echo $tabs_html;
    424 
    425     // Do other fun things
    426     do_action( 'bp_admin_tabs' );
     428    /**
     429     * Filters the tab data used in our wp-admin screens.
     430     *
     431     * @param array $tabs Tab data.
     432     * @since BuddyPress (2.2.0)
     433     */
     434    return apply_filters( 'bp_core_get_admin_tabs', $tabs );
    427435}
    428436
Note: See TracChangeset for help on using the changeset viewer.