Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/28/2011 10:30:03 PM (13 years ago)
Author:
djpaul
Message:

Relocates the top-level BuddyPress admin menu to under the Settings and Users menus. Maintains compatibility with third-party plugins that add their admin menus under the old top-level BP menu. See #3708.

File:
1 edited

Legend:

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

    r5404 r5406  
    285285
    286286/**
    287  * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
    288  *
    289  * @package BuddyPress Core
    290  * @global object $bp Global BuddyPress settings object
    291  * @uses bp_current_user_can() returns true if the current user is a site admin, false if not
    292  * @uses add_submenu_page() WP function to add a submenu item
     287 * In BP 1.6, the top-level admin menu was removed. For backpat, this function
     288 * keeps the top-level menu if a plugin has registered a menu into the old
     289 * 'bp-general-settings' menu.
     290 *
     291 * The old "bp-general-settings" page was renamed "bp-general-config".
     292 *
     293 * @global array $_parent_pages
     294 * @global array $_registered_pages
     295 * @global array $submenu
     296 * @since 1.6
     297 */
     298function bp_core_admin_backpat_menu() {
     299    global $_parent_pages, $_registered_pages, $submenu;
     300
     301    if ( ! is_super_admin() )
     302        return;
     303
     304    // Don't do anything if a BP upgrade is in progress, or if the bp-wizard is in progress.
     305    if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE || empty( $submenu['bp-general-settings'] ) )
     306        return;
     307
     308    /**
     309     * By default, only the core "Help" submenu is added under the top-level BuddyPress menu.
     310     * This means that if no third-party plugins have registered their admin pages into the
     311     * 'bp-general-settings' menu, it will only contain one item. Kill it.
     312     */
     313    if ( 1 == count( $submenu['bp-general-settings'] ) ) {
     314        // This removes the top-level menu
     315        remove_submenu_page( 'bp-general-settings', 'bp-general-settings' );
     316        remove_menu_page( 'bp-general-settings' );
     317
     318        // These stop people accessing the URL directly
     319        unset( $_parent_pages['bp-general-settings'] );
     320        unset( $_registered_pages['toplevel_page_bp-general-settings'] );
     321    }
     322}
     323add_action( bp_core_admin_hook(), 'bp_core_admin_backpat_menu', 999 );
     324
     325/**
     326 * Registers BuddyPress' admin menus.
     327 *
     328 * @since 1.0
    293329 */
    294330function bp_core_add_admin_menu() {
    295     if ( !bp_current_user_can( 'bp_moderate' ) )
    296         return false;
    297 
    298     // Don't add this version of the admin menu if a BP upgrade is in progress
    299     // See bp_core_update_add_admin_menu()
     331    if ( ! bp_current_user_can( 'bp_moderate' ) )
     332        return;
     333
     334    /**
     335     * Don't add this version of the admin menu if a BP upgrade is in progress.
     336     * See bp_core_update_add_admin_menu().
     337     */
    300338    if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE )
    301         return false;
     339        return;
    302340
    303341    $hooks = array();
    304342
    305     // Add the administration tab under the "Site Admin" tab for site administrators
    306     $hooks[] = add_menu_page( __( 'BuddyPress', 'buddypress' ), __( 'BuddyPress', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_component_setup', '' );
    307     $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Components', 'buddypress' ), __( 'Components', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_component_setup'  );
    308     $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Pages',      'buddypress' ), __( 'Pages',      'buddypress' ), 'manage_options', 'bp-page-settings',    'bp_core_admin_page_setup'       );
    309     $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Settings',   'buddypress' ), __( 'Settings',   'buddypress' ), 'manage_options', 'bp-settings',         'bp_core_admin_settings'         );
    310 
    311     // Add a hook for css/js
    312     foreach( $hooks as $hook )
     343    // Changed in BP 1.6 . See bp_core_admin_backpat_menu()
     344    $hooks[] = add_menu_page( __( 'BuddyPress', 'buddypress' ), __( 'BuddyPress', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_backpat_menu', '' );
     345    $hooks[] = add_submenu_page( 'bp-general-settings', __( 'BuddyPress Help', 'buddypress' ), __( 'Help', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_backpat_page' );
     346
     347    // Add the option pages
     348    $hooks[] = add_options_page( __( 'BuddyPress Components', 'buddypress' ), __( 'BuddyPress', 'buddypress' ), 'manage_options', 'bp-general-config', 'bp_core_admin_component_setup' );
     349    $hooks[] = add_options_page( __( 'BuddyPress Pages', 'buddypress' ),      __( 'BuddyPress Pages', 'buddypress' ),      'manage_options', 'bp-page-settings',  'bp_core_admin_page_setup'      );
     350    $hooks[] = add_options_page( __( 'BuddyPress Settings', 'buddypress' ),   __( 'BuddyPress Settings', 'buddypress' ),   'manage_options', 'bp-settings',       'bp_core_admin_settings'        );
     351
     352    foreach( $hooks as $hook ) {
     353        // Add a hook for common BP admin CSS/JS scripts
    313354        add_action( "admin_print_styles-$hook", 'bp_core_add_admin_menu_styles' );
     355
     356        // Fudge the highlighted subnav item when on a BuddyPress admin page
     357        add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' );
     358    }
     359}
     360
     361/**
     362 * Tweak the Settings subnav menu to show only one BuddyPress menu item (Settings > BuddyPress).
     363 *
     364 * @since 1.6
     365 */
     366function bp_core_modify_admin_menu() {
     367    remove_submenu_page( 'options-general.php', 'bb-forums-setup' );
     368    remove_submenu_page( 'options-general.php', 'bp-page-settings' );
     369    remove_submenu_page( 'options-general.php', 'bp-settings' );
     370}
     371add_action( "admin_head", 'bp_core_modify_admin_menu', 999 );
     372
     373/**
     374 * This tells WP to highlight the Settings > BuddyPress menu item,
     375 * regardless of which actual BuddyPress admin screen we are on.
     376 *
     377 * The conditional prevents the behaviour when the user is viewing the
     378 * backpat "Help" page, the Activity page, or any third-party plugins.
     379 *
     380 * @global string $plugin_page
     381 * @global array $submenu
     382 * @since 1.6
     383 */
     384function bp_core_modify_admin_menu_highlight() {
     385    global $plugin_page, $submenu_file;
     386
     387    // This tweaks the Settings subnav menu to show only one BuddyPress menu item
     388    if ( ! in_array( $plugin_page, array( 'bp-activity', 'bp-general-settings', ) ) )
     389        $submenu_file = 'bp-general-config';
    314390}
    315391
Note: See TracChangeset for help on using the changeset viewer.