Skip to:
Content

BuddyPress.org

Changeset 6676


Ignore:
Timestamp:
12/26/2012 03:47:11 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Admin Menus:

  • Add missing separator if network activated.
  • Experiment with moving top level menus out of limbo and into the "content" section of the $menus global.
  • Add functions to activity and groups components to hook them into the relocated menu items array.
  • Introduce functions to reorder top level component menu items accordingly (props bbPress.)
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-admin.php

    r6609 r6676  
    4545}
    4646add_action( bp_core_admin_hook(), 'bp_activity_add_admin_menu' );
     47
     48/**
     49 * Add activity component to custom menus array
     50 *
     51 * @since BuddyPress (1.7)
     52 *
     53 * @param array $custom_menus
     54 * @return array
     55 */
     56function bp_activity_admin_menu_order( $custom_menus = array() ) {
     57    array_push( $custom_menus, 'bp-activity' );
     58    return $custom_menus;
     59}
     60add_filter( 'bp_admin_menu_order', 'bp_activity_admin_menu_order' );
    4761
    4862/**
  • trunk/bp-core/admin/bp-core-actions.php

    r6558 r6676  
    4444add_action( 'admin_notices',           'bp_admin_notices'                 );
    4545add_action( 'admin_enqueue_scripts',   'bp_admin_enqueue_scripts'         );
     46add_action( 'network_admin_menu',      'bp_admin_menu'                    );
     47add_action( 'custom_menu_order',       'bp_admin_custom_menu_order'       );
     48add_action( 'menu_order',              'bp_admin_menu_order'              );
    4649add_action( 'wpmu_new_blog',           'bp_new_site',               10, 6 );
    4750
     
    5356add_action( 'bp_admin_init', 'bp_do_activation_redirect', 1   );
    5457
    55 // Reset the menu order
    56 //add_action( 'bp_admin_menu', 'bp_admin_separator' );
     58// Add a new separator
     59add_action( 'bp_admin_menu', 'bp_admin_separator' );
    5760
    5861/**
  • trunk/bp-core/admin/bp-core-functions.php

    r6632 r6676  
    361361    }
    362362}
     363
     364/** Separator *****************************************************************/
     365
     366/**
     367 * Add a separator to the WordPress admin menus
     368 *
     369 * @since BuddyPress (1.7)
     370 *
     371 * @uses bp_current_user_can() To check users capability on root blog
     372 */
     373function bp_admin_separator() {
     374
     375    // Prevent duplicate separators when no core menu items exist
     376    if ( ! bp_current_user_can( 'bp_moderate' ) )
     377        return;
     378
     379    global $menu;
     380
     381    $menu[] = array( '', 'read', 'separator-buddypress', '', 'wp-menu-separator buddypress' );
     382}
     383
     384/**
     385 * Tell WordPress we have a custom menu order
     386 *
     387 * @since BuddyPress (1.7)
     388 *
     389 * @param bool $menu_order Menu order
     390 * @uses bp_current_user_can() To check users capability on root blog
     391 * @return bool Always true
     392 */
     393function bp_admin_custom_menu_order( $menu_order = false ) {
     394
     395    // Bail if user cannot see admin pages
     396    if ( ! bp_current_user_can( 'bp_moderate' ) )
     397        return $menu_order;
     398
     399    return $menu_order;
     400}
     401
     402/**
     403 * Move our custom separator above our custom post types
     404 *
     405 * @since BuddyPress (1.7)
     406 *
     407 * @param array $menu_order Menu Order
     408 * @uses bp_current_user_can() To check users capability on root blog
     409 * @return array Modified menu order
     410 */
     411function bp_admin_menu_order( $menu_order = array() ) {
     412
     413    // Bail if user cannot see admin pages
     414    if ( empty( $menu_order ) || ! bp_current_user_can( 'bp_moderate' ) )
     415        return $menu_order;
     416
     417    // Initialize our custom order array
     418    $bp_menu_order = array();
     419
     420    // Menu values
     421    $last_sep     = is_network_admin() ? 'separator1' : 'separator2';
     422
     423    // Filter the custom admin menus
     424    $custom_menus = (array) apply_filters( 'bp_admin_menu_order', array() );
     425
     426    // Add our separator to beginning of array
     427    array_unshift( $custom_menus, 'separator-buddypress' );
     428
     429    // Loop through menu order and do some rearranging
     430    foreach ( (array) $menu_order as $item ) {
     431
     432        // Position BuddyPress menus above appearance
     433        if ( $last_sep == $item ) {
     434
     435            // Add our custom menus
     436            foreach( (array) $custom_menus as $custom_menu ) {
     437                if ( array_search( $custom_menu, $menu_order ) ) {
     438                    $bp_menu_order[] = $custom_menu;
     439                }
     440            }
     441
     442            // Add the appearance separator
     443            $bp_menu_order[] = $last_sep;
     444
     445        // Skip our menu items
     446        } elseif ( ! in_array( $item, $custom_menus ) ) {
     447            $bp_menu_order[] = $item;
     448        }
     449    }
     450
     451    // Return our custom order
     452    return $bp_menu_order;
     453}
  • trunk/bp-groups/bp-groups-admin.php

    r6674 r6676  
    4545}
    4646add_action( bp_core_admin_hook(), 'bp_groups_add_admin_menu' );
     47
     48/**
     49 * Add groups component to custom menus array
     50 *
     51 * @since BuddyPress (1.7)
     52 *
     53 * @param array $custom_menus
     54 * @return array
     55 */
     56function bp_groups_admin_menu_order( $custom_menus = array() ) {
     57    array_push( $custom_menus, 'bp-groups' );
     58    return $custom_menus;
     59}
     60add_filter( 'bp_admin_menu_order', 'bp_groups_admin_menu_order' );
    4761
    4862/**
Note: See TracChangeset for help on using the changeset viewer.