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/admin.php

    r6250 r6274  
    202202        $hooks = array();
    203203
    204         // These are later removed in admin_head
    205         if ( current_user_can( 'bbp_tools_page' ) ) {
    206             if ( current_user_can( 'bbp_tools_repair_page' ) ) {
    207                 $hooks[] = add_management_page(
    208                     __( 'Repair Forums', 'bbpress' ),
    209                     __( 'Forum Repair',  'bbpress' ),
    210                     $this->minimum_capability,
    211                     'bbp-repair',
    212                     'bbp_admin_repair'
    213                 );
     204        // Get the tools pages
     205        $tools = bbp_get_tools_admin_pages();
     206
     207        // Loop through tools and check
     208        foreach ( $tools as $tool ) {
     209
     210            // Try to add the admin page
     211            $page = add_management_page(
     212                $tool['name'],
     213                $tool['name'],
     214                $tool['cap'],
     215                $tool['page'],
     216                $tool['func']
     217            );
     218
     219            // Add page to hook if user can view it
     220            if ( false !== $page ) {
     221                $hooks[] = $page;
    214222            }
    215 
    216             if ( current_user_can( 'bbp_tools_import_page' ) ) {
    217                 $hooks[] = add_management_page(
    218                     __( 'Import Forums', 'bbpress' ),
    219                     __( 'Forum Import',  'bbpress' ),
    220                     $this->minimum_capability,
    221                     'bbp-converter',
    222                     'bbp_converter_settings'
    223                 );
    224             }
    225 
    226             if ( current_user_can( 'bbp_tools_reset_page' ) ) {
    227                 $hooks[] = add_management_page(
    228                     __( 'Reset Forums', 'bbpress' ),
    229                     __( 'Forum Reset',  'bbpress' ),
    230                     $this->minimum_capability,
    231                     'bbp-reset',
    232                     'bbp_admin_reset'
    233                 );
    234             }
    235 
    236             // Fudge the highlighted subnav item when on a bbPress admin page
    237             foreach ( $hooks as $hook ) {
    238                 add_action( "admin_head-$hook", 'bbp_tools_modify_menu_highlight' );
    239             }
    240 
    241             // Forums Tools Root
    242             add_management_page(
    243                 __( 'Forums', 'bbpress' ),
    244                 __( 'Forums', 'bbpress' ),
    245                 $this->minimum_capability,
    246                 'bbp-repair',
    247                 'bbp_admin_repair'
    248             );
    249         }
     223        }
     224
     225        // Fudge the highlighted subnav item when on a bbPress admin page
     226        foreach ( $hooks as $hook ) {
     227            add_action( "admin_head-{$hook}", 'bbp_tools_modify_menu_highlight' );
     228        }
     229
     230        // Forums Tools Root
     231        add_management_page(
     232            __( 'Forums', 'bbpress' ),
     233            __( 'Forums', 'bbpress' ),
     234            'bbp_tools_page',
     235            'bbp-repair',
     236            'bbp_admin_repair'
     237        );
    250238
    251239        // Are settings enabled?
    252         if ( ! bbp_settings_integration() && current_user_can( 'bbp_settings_page' ) ) {
     240        if ( ! bbp_settings_integration() ) {
    253241            add_options_page(
    254242                __( 'Forums',  'bbpress' ),
    255243                __( 'Forums',  'bbpress' ),
    256                 $this->minimum_capability,
     244                'bbp_settings_page',
    257245                'bbpress',
    258246                'bbp_admin_settings'
     
    267255                __( 'Welcome to bbPress',  'bbpress' ),
    268256                __( 'Welcome to bbPress',  'bbpress' ),
    269                 $this->minimum_capability,
     257                'bbp_about_page',
    270258                'bbp-about',
    271259                array( $this, 'about_screen' )
     
    276264                __( 'Welcome to bbPress',  'bbpress' ),
    277265                __( 'Welcome to bbPress',  'bbpress' ),
    278                 $this->minimum_capability,
     266                'bbp_about_page',
    279267                'bbp-credits',
    280268                array( $this, 'credits_screen' )
Note: See TracChangeset for help on using the changeset viewer.