<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][6676] trunk: Admin Menus:</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/6676">6676</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2012-12-26 15:47:11 +0000 (Wed, 26 Dec 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Admin Menus:

* Add missing separator if network activated.
* Experiment with moving top level menus out of limbo and into the &quot;content&quot; 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.)</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivityadminphp">trunk/bp-activity/bp-activity-admin.php</a></li>
<li><a href="#trunkbpcoreadminbpcoreactionsphp">trunk/bp-core/admin/bp-core-actions.php</a></li>
<li><a href="#trunkbpcoreadminbpcorefunctionsphp">trunk/bp-core/admin/bp-core-functions.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsadminphp">trunk/bp-groups/bp-groups-admin.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivityadminphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-admin.php (6675 => 6676)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-admin.php        2012-12-26 09:36:31 UTC (rev 6675)
+++ trunk/bp-activity/bp-activity-admin.php        2012-12-26 15:47:11 UTC (rev 6676)
</span><span class="lines">@@ -46,6 +46,20 @@
</span><span class="cx"> add_action( bp_core_admin_hook(), 'bp_activity_add_admin_menu' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Add activity component to custom menus array
+ *
+ * @since BuddyPress (1.7)
+ *
+ * @param array $custom_menus
+ * @return array
+ */
+function bp_activity_admin_menu_order( $custom_menus = array() ) {
+        array_push( $custom_menus, 'bp-activity' );
+        return $custom_menus;
+}
+add_filter( 'bp_admin_menu_order', 'bp_activity_admin_menu_order' );
+
+/**
</ins><span class="cx">  * AJAX receiver for Activity replies via the admin screen. Adds a new activity
</span><span class="cx">  * comment, and returns HTML for a new table row.
</span><span class="cx">  *
</span></span></pre></div>
<a id="trunkbpcoreadminbpcoreactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/admin/bp-core-actions.php (6675 => 6676)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/admin/bp-core-actions.php        2012-12-26 09:36:31 UTC (rev 6675)
+++ trunk/bp-core/admin/bp-core-actions.php        2012-12-26 15:47:11 UTC (rev 6676)
</span><span class="lines">@@ -43,6 +43,9 @@
</span><span class="cx"> add_action( 'admin_head',              'bp_admin_head'                    );
</span><span class="cx"> add_action( 'admin_notices',           'bp_admin_notices'                 );
</span><span class="cx"> add_action( 'admin_enqueue_scripts',   'bp_admin_enqueue_scripts'         );
</span><ins>+add_action( 'network_admin_menu',      'bp_admin_menu'                    );
+add_action( 'custom_menu_order',       'bp_admin_custom_menu_order'       );
+add_action( 'menu_order',              'bp_admin_menu_order'              );
</ins><span class="cx"> add_action( 'wpmu_new_blog',           'bp_new_site',               10, 6 );
</span><span class="cx"> 
</span><span class="cx"> // Hook on to admin_init
</span><span class="lines">@@ -52,8 +55,8 @@
</span><span class="cx"> add_action( 'bp_admin_init', 'bp_register_admin_settings'     );
</span><span class="cx"> add_action( 'bp_admin_init', 'bp_do_activation_redirect', 1   );
</span><span class="cx"> 
</span><del>-// Reset the menu order
-//add_action( 'bp_admin_menu', 'bp_admin_separator' );
</del><ins>+// Add a new separator
+add_action( 'bp_admin_menu', 'bp_admin_separator' );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * When a new site is created in a multisite installation, run the activation
</span></span></pre></div>
<a id="trunkbpcoreadminbpcorefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/admin/bp-core-functions.php (6675 => 6676)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/admin/bp-core-functions.php        2012-12-26 09:36:31 UTC (rev 6675)
+++ trunk/bp-core/admin/bp-core-functions.php        2012-12-26 15:47:11 UTC (rev 6676)
</span><span class="lines">@@ -360,3 +360,94 @@
</span><span class="cx">                         break;
</span><span class="cx">         }
</span><span class="cx"> }
</span><ins>+
+/** Separator *****************************************************************/
+
+/**
+ * Add a separator to the WordPress admin menus
+ *
+ * @since BuddyPress (1.7)
+ *
+ * @uses bp_current_user_can() To check users capability on root blog
+ */
+function bp_admin_separator() {
+
+        // Prevent duplicate separators when no core menu items exist
+        if ( ! bp_current_user_can( 'bp_moderate' ) )
+                return;
+
+        global $menu;
+
+        $menu[] = array( '', 'read', 'separator-buddypress', '', 'wp-menu-separator buddypress' );
+}
+
+/**
+ * Tell WordPress we have a custom menu order
+ *
+ * @since BuddyPress (1.7)
+ *
+ * @param bool $menu_order Menu order
+ * @uses bp_current_user_can() To check users capability on root blog
+ * @return bool Always true
+ */
+function bp_admin_custom_menu_order( $menu_order = false ) {
+
+        // Bail if user cannot see admin pages
+        if ( ! bp_current_user_can( 'bp_moderate' ) )
+                return $menu_order;
+
+        return $menu_order;
+}
+
+/**
+ * Move our custom separator above our custom post types
+ *
+ * @since BuddyPress (1.7)
+ *
+ * @param array $menu_order Menu Order
+ * @uses bp_current_user_can() To check users capability on root blog
+ * @return array Modified menu order
+ */
+function bp_admin_menu_order( $menu_order = array() ) {
+
+        // Bail if user cannot see admin pages
+        if ( empty( $menu_order ) || ! bp_current_user_can( 'bp_moderate' ) )
+                return $menu_order;
+
+        // Initialize our custom order array
+        $bp_menu_order = array();
+
+        // Menu values
+        $last_sep     = is_network_admin() ? 'separator1' : 'separator2';
+
+        // Filter the custom admin menus
+        $custom_menus = (array) apply_filters( 'bp_admin_menu_order', array() );
+
+        // Add our separator to beginning of array
+        array_unshift( $custom_menus, 'separator-buddypress' );
+
+        // Loop through menu order and do some rearranging
+        foreach ( (array) $menu_order as $item ) {
+
+                // Position BuddyPress menus above appearance
+                if ( $last_sep == $item ) {
+
+                        // Add our custom menus
+                        foreach( (array) $custom_menus as $custom_menu ) {
+                                if ( array_search( $custom_menu, $menu_order ) ) {
+                                        $bp_menu_order[] = $custom_menu;
+                                }
+                        }
+
+                        // Add the appearance separator
+                        $bp_menu_order[] = $last_sep;
+
+                // Skip our menu items
+                } elseif ( ! in_array( $item, $custom_menus ) ) {
+                        $bp_menu_order[] = $item;
+                }
+        }
+
+        // Return our custom order
+        return $bp_menu_order;
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsadminphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-admin.php (6675 => 6676)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-admin.php        2012-12-26 09:36:31 UTC (rev 6675)
+++ trunk/bp-groups/bp-groups-admin.php        2012-12-26 15:47:11 UTC (rev 6676)
</span><span class="lines">@@ -46,6 +46,20 @@
</span><span class="cx"> add_action( bp_core_admin_hook(), 'bp_groups_add_admin_menu' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Add groups component to custom menus array
+ *
+ * @since BuddyPress (1.7)
+ *
+ * @param array $custom_menus
+ * @return array
+ */
+function bp_groups_admin_menu_order( $custom_menus = array() ) {
+        array_push( $custom_menus, 'bp-groups' );
+        return $custom_menus;
+}
+add_filter( 'bp_admin_menu_order', 'bp_groups_admin_menu_order' );
+
+/**
</ins><span class="cx">  * Set up the admin page before any output is sent. Register contextual help and screen options for this admin page.
</span><span class="cx">  *
</span><span class="cx">  * @global object $bp BuddyPress global settings
</span></span></pre>
</div>
</div>

</body>
</html>