Skip to:
Content

bbPress.org


Ignore:
Timestamp:
02/02/2017 11:08:01 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Tools: Unify the tab/link experience:

  • Introduce function to get tools pages
  • Trust capability checks in core WordPress functions, and remove our own bespoke pre-checks
  • Add tool-box to wp-admin/tools.php linking to tools the user has access to

This change promotes exposure to bbPress's tools pages, and makes adding third-party tools pages easier.

See: #2959.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/functions.php

    r6115 r6274  
    278278
    279279        // Setup core admin tabs
    280         $tabs = apply_filters( 'bbp_tools_admin_tabs', array(
    281             '0' => array(
    282                 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-repair'    ), 'tools.php' ) ),
    283                 'name' => __( 'Repair Forums', 'bbpress' )
    284             ),
    285             '1' => array(
    286                 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-converter' ), 'tools.php' ) ),
    287                 'name' => __( 'Import Forums', 'bbpress' )
    288             ),
    289             '2' => array(
    290                 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-reset'     ), 'tools.php' ) ),
    291                 'name' => __( 'Reset Forums', 'bbpress' )
    292             )
    293         ) );
     280        $tabs = bbp_get_tools_admin_pages();
    294281
    295282        // Loop through tabs and build navigation
    296         foreach ( array_values( $tabs ) as $tab_data ) {
    297             $is_current = (bool) ( $tab_data['name'] == $active_tab );
     283        foreach ( $tabs as $tab ) {
     284
     285            // Skip if user cannot visit page
     286            if ( ! current_user_can( $tab['cap'] ) ) {
     287                continue;
     288            }
     289
     290            // Setup tab HTML
     291            $is_current = (bool) ( $tab['name'] == $active_tab );
    298292            $tab_class  = $is_current ? $active_class : $idle_class;
    299             $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>';
     293            $tab_url    = get_admin_url( '', add_query_arg( array( 'page' => $tab['page'] ), 'tools.php' ) );
     294            $tabs_html .= '<a href="' . esc_url( $tab_url ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab['name'] ) . '</a>';
    300295        }
    301296
     
    303298        return $tabs_html;
    304299    }
     300
     301/**
     302 * Return possible tools pages
     303 *
     304 * @since 2.6.0 (r6273)
     305 *
     306 * @return array
     307 */
     308function bbp_get_tools_admin_pages() {
     309    return apply_filters( 'bbp_tools_admin_tabs', array(
     310        array(
     311            'page' => 'bbp-repair',
     312            'func' => 'bbp_admin_repair',
     313            'cap'  => 'bbp_tools_repair_page',
     314            'name' => esc_html__( 'Repair Forums', 'bbpress' ),
     315
     316            // Deprecated 2.6.0
     317            'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-repair'    ), 'tools.php' ) )
     318        ),
     319        array(
     320            'page' => 'bbp-converter',
     321            'func' => 'bbp_converter_settings',
     322            'cap'  => 'bbp_tools_import_page',
     323            'name' => esc_html__( 'Import Forums', 'bbpress' ),
     324
     325            // Deprecated 2.6.0
     326            'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-converter' ), 'tools.php' ) )
     327        ),
     328        array(
     329            'page' => 'bbp-reset',
     330            'func' => 'bbp_admin_reset',
     331            'cap'  => 'bbp_tools_reset_page',
     332            'name' => esc_html__( 'Reset Forums', 'bbpress' ),
     333
     334            // Deprecated 2.6.0
     335            'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-reset'     ), 'tools.php' ) )
     336        )
     337    ) );
     338}
Note: See TracChangeset for help on using the changeset viewer.