Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/06/2021 08:40:08 AM (4 years ago)
Author:
imath
Message:

Use WordPress "site-health" style tabs for BP Admin tabs

The BuddyPress settings and tools screens admin tabs are now using the "site-health" style. As aside from the "site-health" screens, the Privacy screens are also using this tabs' style, we think using this style will improve the way BuddyPress Admin screens integrate inside the WordPress Administration.

We've put a back compatibility process for plugins extending the BuddyPress settings or/and tools screens adding their custom tabs, so that they are automatically converted into these new tabs. Plugin developers are encouraged to progressively update the way they are adding these tabs.

  • bp_core_admin_tabbed_screen_header() has been introduced to generate the BuddyPress Admin screens headers using tabs.
  • bp_core_get_admin_settings_tabs() has been introduced to return the settings tabs, using the 'bp_core_get_admin_settings_tabs' filter, plugin developers can add their custom tab to the BuddyPress settings screens.
  • bp_core_get_admin_settings_tabs() has been introduced to return the settings tabs. Using the 'bp_core_get_admin_settings_tabs' filter, plugin developers can add their custom tabs to the BuddyPress settings screens.
  • bp_core_get_admin_tools_tabs() has been introduced to return the tools tabs. Using the 'bp_core_get_admin_tools_tabs' filter, plugin developers can add their custom tabs to the BuddyPress tools screens.
  • To make sure BuddyPress generate the inline style to custom tabs, plugin developers need to hook the 'bp_admin_submenu_pages' action which passes by reference an associative array keyed according to the screens to style (settings or tools) and containing the plugin page hookname of their custom screens.

Props oztaser

Fixes #8588

File:
1 edited

Legend:

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

    r13022 r13137  
    7575     */
    7676    public $notices = array();
     77
     78    /**
     79     * BuddyPress admin screens nav tabs.
     80     *
     81     * @since 10.0.0
     82     * @var array()
     83     */
     84    public $nav_tabs = array();
     85
     86    /**
     87     * BuddyPress admin active nav tab.
     88     *
     89     * @since 10.0.0
     90     * @var string()
     91     */
     92    public $active_nav_tab = '';
     93
     94    /**
     95     * BuddyPress admin screens submenu pages.
     96     *
     97     * @since 10.0.0
     98     * @var array()
     99     */
     100    public $submenu_pages = array();
    77101
    78102    /** Methods ***************************************************************/
     
    230254
    231255        // Add the option pages.
    232         $hooks[] = add_submenu_page(
     256        $bp_components_page = add_submenu_page(
    233257            $this->settings_page,
    234258            __( 'BuddyPress Components', 'buddypress' ),
     
    239263        );
    240264
    241         $hooks[] = add_submenu_page(
     265        $this->submenu_pages['settings']['bp-components'] = $bp_components_page;
     266        $hooks[]                                          = $bp_components_page;
     267
     268        $bp_page_settings_page = add_submenu_page(
    242269            $this->settings_page,
    243270            __( 'BuddyPress Pages', 'buddypress' ),
     
    248275        );
    249276
    250         $hooks[] = add_submenu_page(
     277        $this->submenu_pages['settings']['bp-page-settings'] = $bp_page_settings_page;
     278        $hooks[]                                             = $bp_page_settings_page;
     279
     280        $bp_settings_page = add_submenu_page(
    251281            $this->settings_page,
    252282            __( 'BuddyPress Options', 'buddypress' ),
     
    257287        );
    258288
     289        $this->submenu_pages['settings']['bp-settings'] = $bp_settings_page;
     290        $hooks[]                                        = $bp_settings_page;
     291
    259292        // Credits.
    260         $hooks[] = add_submenu_page(
     293        $bp_credits_page = add_submenu_page(
    261294            $this->settings_page,
    262295            __( 'BuddyPress Credits', 'buddypress' ),
     
    266299            array( $this, 'credits_screen' )
    267300        );
     301
     302        $this->submenu_pages['settings']['bp-credits'] = $bp_credits_page;
     303        $hooks[]                                       = $bp_credits_page;
    268304
    269305        // For consistency with non-Multisite, we add a Tools menu in
     
    294330        }
    295331
    296         $hooks[] = add_submenu_page(
     332        // Init the Tools submenu pages global.
     333        $this->submenu_pages['tools'] = array();
     334
     335        $bp_repair_tools = add_submenu_page(
    297336            $tools_parent,
    298337            __( 'BuddyPress Tools', 'buddypress' ),
     
    303342        );
    304343
    305         $hooks[] = add_submenu_page(
     344        $this->submenu_pages['tools']['bp-tools'] = $bp_repair_tools;
     345        $hooks[]                                  = $bp_repair_tools;
     346
     347        $bp_optouts_tools = add_submenu_page(
    306348            $tools_parent,
    307349            __( 'Manage Opt-outs', 'buddypress' ),
     
    311353            'bp_core_optouts_admin'
    312354        );
     355
     356        $this->submenu_pages['tools']['bp-optouts'] = $bp_optouts_tools;
     357        $hooks[]                                    = $bp_optouts_tools;
    313358
    314359        // For network-wide configs, add a link to (the root site's) Emails screen.
     
    333378        foreach( $hooks as $hook ) {
    334379            add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' );
     380        }
     381
     382        /**
     383         * Fires before adding inline styles for BP Admin tabs.
     384         *
     385         * @since 10.0.0
     386         *
     387         * @param array $submenu_pages The BP_Admin submenu pages passed by reference.
     388         */
     389        do_action_ref_array( 'bp_admin_submenu_pages', array( &$this->submenu_pages ) );
     390
     391        foreach( $this->submenu_pages as $subpage_hooks ) {
     392            foreach ( $subpage_hooks as $subpage_hook ) {
     393                add_action( "admin_print_styles-{$subpage_hook}", array( $this, 'add_inline_styles' ), 20 );
     394            }
    335395        }
    336396    }
     
    811871     */
    812872    public function credits_screen() {
     873        bp_core_admin_tabbed_screen_header( __( 'BuddyPress Settings', 'buddypress' ), __( 'Credits', 'buddypress' ) );
    813874    ?>
    814875
    815         <div class="wrap bp-about-wrap">
    816 
    817         <h1 class="wp-heading-inline"><?php esc_html_e( 'BuddyPress Settings', 'buddypress' ); ?></h1>
    818         <hr class="wp-header-end">
    819 
    820         <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( esc_html__( 'Credits', 'buddypress' ) ); ?></h2>
     876        <div class="buddypress-body bp-about-wrap">
    821877
    822878            <p class="about-description"><?php esc_html_e( 'Meet the contributors behind BuddyPress:', 'buddypress' ); ?></p>
     
    12251281        }
    12261282    }
     1283
     1284    /**
     1285     * Adds inline styles to adapt the number of grid columns according to the number of BP Admin tabs.
     1286     *
     1287     * @since 10.0.0
     1288     */
     1289    public function add_inline_styles() {
     1290        $screen                  = get_current_screen();
     1291        $current_settings_tab_id = array_search( $screen->id, $this->submenu_pages['settings'], true );
     1292        $current_tools_tab_id    = array_search( $screen->id, $this->submenu_pages['tools'], true );
     1293        $current_tab_id          = '';
     1294        $tabs                    = array();
     1295        $context                 = '';
     1296
     1297        if ( $current_settings_tab_id ) {
     1298            $current_tab_id = $current_settings_tab_id;
     1299            $tabs           = wp_list_pluck( bp_core_get_admin_settings_tabs(), 'name', 'id' );
     1300            $context        = 'settings';
     1301        } elseif ( $current_tools_tab_id ) {
     1302            $current_tab_id = $current_tools_tab_id;
     1303            $tabs           = wp_list_pluck( bp_core_get_admin_tools_tabs(), 'name', 'id' );
     1304            $context        = 'tools';
     1305        }
     1306
     1307        if ( $current_tab_id && isset( $tabs[ $current_tab_id ] ) ) {
     1308            $this->nav_tabs = bp_core_admin_tabs( $tabs[ $current_tab_id ], $context, false );
     1309            $grid_columns   = array_fill( 0, count( $this->nav_tabs ), '1fr');
     1310            $help_tab_css   = '';
     1311
     1312            if ( $screen->get_help_tabs() ) {
     1313                $help_tab_css  = '#screen-meta { margin-right: 0; } #screen-meta-links { position: absolute; right: 0; }';
     1314            }
     1315
     1316            wp_add_inline_style(
     1317                'bp-admin-common-css',
     1318                sprintf(
     1319                    '.buddypress-tabs-wrapper {
     1320                        -ms-grid-columns: %1$s;
     1321                        grid-template-columns: %1$s;
     1322                    }
     1323                    %2$s',
     1324                    implode( " ", $grid_columns ),
     1325                    $help_tab_css
     1326                )
     1327            );
     1328        }
     1329    }
    12271330}
    12281331endif; // End class_exists check.
Note: See TracChangeset for help on using the changeset viewer.