Skip to:
Content

bbPress.org

Changeset 4046


Ignore:
Timestamp:
07/02/2012 07:06:30 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Admin Menus:

  • Fix issue where bbPress top-level admin-menu positions could conflict with other plugins.
  • Set menu_position on post-types to 555555.
  • Refactor bbp_admin_menu_order() to reposition all available custom menus above the second separator.
  • Fixes #1876.
Location:
branches/plugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-functions.php

    r3966 r4046  
    2121
    2222    // Prevent duplicate separators when no new menu items exist
    23     if ( !current_user_can( 'edit_replies' ) )
     23    if ( !current_user_can( 'edit_forums' ) && !current_user_can( 'edit_topics' ) && !current_user_can( 'edit_replies' ) )
    2424        return;
    2525
     
    4141 * @return bool Always true
    4242 */
    43 function bbp_admin_custom_menu_order( $menu_order ) {
    44     if ( !current_user_can( 'edit_replies' ) )
     43function bbp_admin_custom_menu_order( $menu_order = false ) {
     44    if ( !current_user_can( 'edit_forums' ) && !current_user_can( 'edit_topics' ) && !current_user_can( 'edit_replies' ) )
    4545        return $menu_order;
    4646
     
    5959function bbp_admin_menu_order( $menu_order ) {
    6060
     61    // Bail if user cannot see any top level bbPress menus
     62    if ( empty( $menu_order ) || ( !current_user_can( 'edit_forums' ) && !current_user_can( 'edit_topics' ) && !current_user_can( 'edit_replies' ) ) )
     63        return $menu_order;
     64
    6165    // Initialize our custom order array
    6266    $bbp_menu_order = array();
    6367
    64     // Get the index of our custom separator
    65     $bbp_separator = array_search( 'separator-bbpress', $menu_order );
    66 
    67     // Forums
    68     if ( current_user_can( 'edit_forums' ) ) {
    69         $top_menu_type = bbp_get_forum_post_type();
    70 
    71     // Topics
    72     } elseif ( current_user_can( 'edit_topics' ) ) {
    73         $top_menu_type = bbp_get_topic_post_type();
    74 
    75     // Replies
    76     } elseif ( current_user_can( 'edit_replies' ) ) {
    77         $top_menu_type = bbp_get_reply_post_type();
    78 
    79     // Bail if there are no bbPress menus present
    80     } else {
    81         return;
    82     }
     68    // Menu values
     69    $second_sep   = 'separator2';
     70    $custom_menus = array(
     71        'separator-bbpress',                               // Separator
     72        'edit.php?post_type=' . bbp_get_forum_post_type(), // Forums
     73        'edit.php?post_type=' . bbp_get_topic_post_type(), // Topics
     74        'edit.php?post_type=' . bbp_get_reply_post_type()  // Replies
     75    );
    8376
    8477    // Loop through menu order and do some rearranging
    85     foreach ( $menu_order as $index => $item ) {
    86 
    87         // Current item is ours, so set our separator here
    88         if ( ( ( 'edit.php?post_type=' . $top_menu_type ) == $item ) ) {
    89             $bbp_menu_order[] = 'separator-bbpress';
    90             unset( $menu_order[$bbp_separator] );
    91         }
    92 
    93         // Skip our separator
    94         if ( !in_array( $item, array( 'separator-bbpress' ) ) ) {
     78    foreach ( $menu_order as $item ) {
     79
     80        // Position bbPress menus above appearance
     81        if ( $second_sep == $item ) {
     82
     83            // Add our custom menus
     84            foreach( $custom_menus as $custom_menu ) {
     85                if ( array_search( $custom_menu, $menu_order ) ) {
     86                    $bbp_menu_order[] = $custom_menu;
     87                }
     88            }
     89
     90            // Add the appearance separator
     91            $bbp_menu_order[] = $second_sep;
     92
     93        // Skip our menu items
     94        } elseif ( ! in_array( $item, $custom_menus ) ) {
    9595            $bbp_menu_order[] = $item;
    9696        }
  • branches/plugin/bbpress.php

    r4043 r4046  
    513513                'capabilities'        => bbp_get_forum_caps(),
    514514                'capability_type'     => array( 'forum', 'forums' ),
    515                 'menu_position'       => 56,
     515                'menu_position'       => 555555,
    516516                'has_archive'         => bbp_get_root_slug(),
    517517                'exclude_from_search' => true,
     
    570570                'capabilities'        => bbp_get_topic_caps(),
    571571                'capability_type'     => array( 'topic', 'topics' ),
    572                 'menu_position'       => 57,
     572                'menu_position'       => 555555,
    573573                'has_archive'         => bbp_get_topic_archive_slug(),
    574574                'exclude_from_search' => true,
     
    627627                'capabilities'        => bbp_get_reply_caps(),
    628628                'capability_type'     => array( 'reply', 'replies' ),
    629                 'menu_position'       => 58,
     629                'menu_position'       => 555555,
    630630                'exclude_from_search' => true,
    631631                'has_archive'         => false,
Note: See TracChangeset for help on using the changeset viewer.