<!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][5922] trunk: More redundant URL tweaks</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/5922">5922</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2012-03-16 00:30:11 +0000 (Fri, 16 Mar 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>More redundant URL tweaks

* Do not include sub_nav slug in $link if it's the default for its parent
* Add missing priorities to bp_screens actions to ensure adding/removing works correctly
* Avoid double-negative is_object() checks
* Add phpdoc header to bp-core-buddybar.php
* Various code clean-up
* Debug-notice dodging where missing
* See <a href="http://buddypress.trac.wordpress.org/ticket/1741">#1741</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcorebuddybarphp">trunk/bp-core/bp-core-buddybar.php</a></li>
<li><a href="#trunkbpmembersbpmemberstemplatephp">trunk/bp-members/bp-members-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcorebuddybarphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-buddybar.php (5921 => 5922)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-buddybar.php        2012-03-15 22:58:14 UTC (rev 5921)
+++ trunk/bp-core/bp-core-buddybar.php        2012-03-16 00:30:11 UTC (rev 5922)
</span><span class="lines">@@ -1,4 +1,13 @@
</span><span class="cx"> &lt;?php
</span><ins>+
+/**
+ * Core BuddyPress Navigational Functions
+ *
+ * @package BuddyPress
+ * @subpackage Core
+ * @todo Deprecate BuddyBar functions
+ */
+
</ins><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx"> 
</span><span class="lines">@@ -30,7 +39,7 @@
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         // If this is for site admins only and the user is not one, don't create the subnav item
</span><del>-        if ( $site_admin_only &amp;&amp; !bp_current_user_can( 'bp_moderate' ) )
</del><ins>+        if ( !empty( $site_admin_only ) &amp;&amp; !bp_current_user_can( 'bp_moderate' ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         if ( empty( $item_css_id ) )
</span><span class="lines">@@ -47,15 +56,15 @@
</span><span class="cx">                 'default_subnav_slug'          =&gt; $default_subnav_slug
</span><span class="cx">         );
</span><span class="cx"> 
</span><del>-         /***
</del><ins>+         /**
</ins><span class="cx">          * If this nav item is hidden for the displayed user, and
</span><span class="cx">          * the logged in user is not the displayed user
</span><span class="cx">          * looking at their own profile, don't create the nav item.
</span><span class="cx">          */
</span><del>-        if ( !$show_for_displayed_user &amp;&amp; !bp_user_has_access() )
</del><ins>+        if ( empty( $show_for_displayed_user ) &amp;&amp; !bp_user_has_access() )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        /***
</del><ins>+        /**
</ins><span class="cx">           * If the nav item is visible, we are not viewing a user, and this is a root
</span><span class="cx">          * component, don't attach the default subnav function so we can display a
</span><span class="cx">          * directory or something else.
</span><span class="lines">@@ -65,37 +74,41 @@
</span><span class="cx"> 
</span><span class="cx">         // Look for current component
</span><span class="cx">         if ( bp_is_current_component( $slug ) ) {
</span><ins>+
+                // The requested URL has explicitly included the default subnav (eg
+                // example.com/members/membername/activity/just-me/). The canonical
+                // version will not contain this subnav slug.
</ins><span class="cx">                 if ( !empty( $default_subnav_slug ) &amp;&amp; bp_is_current_action( $default_subnav_slug ) ) {
</span><del>-                        // The requested URL has explicitly included the default subnav (eg
-                        // example.com/members/membername/activity/just-me/). The canonical
-                        // version will not contain this subnav slug.
</del><span class="cx">                         unset( $bp-&gt;canonical_stack['action'] );
</span><span class="cx">                 } else if ( !bp_current_action() ) {
</span><del>-                        if ( !is_object( $screen_function[0] ) )
-                                add_action( 'bp_screens', $screen_function );
-                        else
</del><ins>+                        if ( is_object( $screen_function[0] ) ) {
</ins><span class="cx">                                 add_action( 'bp_screens', array( &amp;$screen_function[0], $screen_function[1] ), 3 );
</span><ins>+                        } else {
+                                add_action( 'bp_screens', $screen_function, 3 );
+                        }
</ins><span class="cx">         
</span><span class="cx">                         if ( !empty( $default_subnav_slug ) ) {
</span><del>-                                $bp-&gt;current_action                = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
</del><ins>+                                $bp-&gt;current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">         // Look for current item
</span><span class="cx">         } elseif ( bp_is_current_item( $slug ) ) {
</span><ins>+
+                // The requested URL has explicitly included the default subnav
+                // (eg: http://example.com/members/membername/activity/just-me/)
+                // The canonical version will not contain this subnav slug.
</ins><span class="cx">                 if ( !empty( $default_subnav_slug ) &amp;&amp; bp_is_current_action( $default_subnav_slug ) ) {
</span><del>-                        // The requested URL has explicitly included the default subnav (eg
-                        // example.com/members/membername/activity/just-me/). The canonical
-                        // version will not contain this subnav slug.
</del><span class="cx">                         unset( $bp-&gt;canonical_stack['action'] );
</span><span class="cx">                 } else if ( !bp_current_action() ) {
</span><del>-                        if ( !is_object( $screen_function[0] ) )
-                                add_action( 'bp_screens', $screen_function );
-                        else
</del><ins>+                        if ( is_object( $screen_function[0] ) ) {
</ins><span class="cx">                                 add_action( 'bp_screens', array( &amp;$screen_function[0], $screen_function[1] ), 3 );
</span><del>-        
</del><ins>+                        } else {
+                                add_action( 'bp_screens', $screen_function, 3 );
+                        }
+
</ins><span class="cx">                         if ( !empty( $default_subnav_slug ) ) {
</span><del>-                                $bp-&gt;current_action                = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
</del><ins>+                                $bp-&gt;current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -122,10 +135,11 @@
</span><span class="cx">         extract( $r, EXTR_SKIP );
</span><span class="cx">         
</span><span class="cx">         if ( $function = $bp-&gt;bp_nav[$parent_slug]['screen_function'] ) {
</span><del>-                if ( !is_object( $function[0] ) )
</del><ins>+                if ( is_object( $function[0] ) ) {
+                        remove_action( 'bp_screens', array( &amp;$function[0], $function[1] ), 3 );
+                } else {
</ins><span class="cx">                         remove_action( 'bp_screens', $function, 3 );
</span><del>-                else
-                        remove_action( 'bp_screens', array( &amp;$function[0], $function[1] ), 3 );
</del><ins>+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $bp-&gt;bp_nav[$parent_slug]['screen_function'] = &amp;$screen_function;
</span><span class="lines">@@ -141,31 +155,33 @@
</span><span class="cx">                                 $unfiltered_action = $bp-&gt;unfiltered_uri[$component_uri_key + 1];
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-                
</del><ins>+
+                // No subnav item has been requested in the URL, so set a new nav default
</ins><span class="cx">                 if ( empty( $unfiltered_action ) ) {
</span><del>-                        // No subnav item has been requested in the URL, so set a new nav default
</del><span class="cx">                         if ( !bp_is_current_action( $subnav_slug ) ) {
</span><del>-                                if ( !is_object( $screen_function[0] ) ) {
-                                        add_action( 'bp_screens', $screen_function );
</del><ins>+                                if ( is_object( $screen_function[0] ) ) {
+                                        add_action( 'bp_screens', array( &amp;$screen_function[0], $screen_function[1] ), 3 );
</ins><span class="cx">                                 } else {
</span><del>-                                        add_action( 'bp_screens', array( &amp;$screen_function[0], $screen_function[1] ) );
</del><ins>+                                        add_action( 'bp_screens', $screen_function, 3 );
</ins><span class="cx">                                 }
</span><span class="cx">                 
</span><span class="cx">                                 $bp-&gt;current_action = $subnav_slug;
</span><span class="cx">                                 unset( $bp-&gt;canonical_stack['action'] );
</span><span class="cx">                         }
</span><del>-                } else if ( $unfiltered_action == $subnav_slug ) {
-                        // The URL is explicitly requesting the new subnav item, but should be
-                        // directed to the canonical URL
</del><ins>+
+                // The URL is explicitly requesting the new subnav item, but should be
+                // directed to the canonical URL
+                } elseif ( $unfiltered_action == $subnav_slug ) {
</ins><span class="cx">                         unset( $bp-&gt;canonical_stack['action'] );
</span><ins>+
+                // In all other cases (including the case where the original subnav item
+                // is explicitly called in the URL), the canonical URL will contain the
+                // subnav slug
</ins><span class="cx">                 } else {
</span><del>-                        // In all other cases (including the case where the original subnav item
-                        // is explicitly called in the URL), the canonical URL will contain the
-                        // subnav slug
</del><span class="cx">                         $bp-&gt;canonical_stack['action'] = bp_current_action();
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-        
</del><ins>+
</ins><span class="cx">         return;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -183,9 +199,9 @@
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         foreach ( (array) $bp-&gt;bp_nav as $slug =&gt; $nav_item ) {
</span><del>-                if ( empty( $temp[$nav_item['position']]) )
</del><ins>+                if ( empty( $temp[$nav_item['position']]) ) {
</ins><span class="cx">                         $temp[$nav_item['position']] = $nav_item;
</span><del>-                else {
</del><ins>+                } else {
</ins><span class="cx">                         // increase numbers here to fit new items in.
</span><span class="cx">                         do {
</span><span class="cx">                                 $nav_item['position']++;
</span><span class="lines">@@ -230,11 +246,18 @@
</span><span class="cx">         if ( empty( $name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        if ( empty( $link ) )
</del><ins>+        // Link was not forced, so create one
+        if ( empty( $link ) ) {
</ins><span class="cx">                 $link = $parent_url . $slug;
</span><span class="cx"> 
</span><ins>+                // If this sub item is the default for its parent, skip the slug
+                if ( $slug == $bp-&gt;bp_nav[$parent_slug]['default_subnav_slug'] ) {
+                        $link = $parent_url;
+                }
+        }
+
</ins><span class="cx">         // If this is for site admins only and the user is not one, don't create the subnav item
</span><del>-        if ( $site_admin_only &amp;&amp; !bp_current_user_can( 'bp_moderate' ) )
</del><ins>+        if ( !empty( $site_admin_only ) &amp;&amp; !bp_current_user_can( 'bp_moderate' ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         if ( empty( $item_css_id ) )
</span><span class="lines">@@ -256,10 +279,10 @@
</span><span class="cx">          * subnav item. We figure out whether we're currently viewing this subnav by checking the
</span><span class="cx">          * following two conditions:
</span><span class="cx">          *   (1) Either:
</span><del>-         *         (a) the parent slug matches the current_component, or
-         *         (b) the parent slug matches the current_item
</del><ins>+         *             (a) the parent slug matches the current_component, or
+         *             (b) the parent slug matches the current_item
</ins><span class="cx">          *   (2) And either:
</span><del>-         *          (a) the current_action matches $slug, or
</del><ins>+         *             (a) the current_action matches $slug, or
</ins><span class="cx">          *       (b) there is no current_action (ie, this is the default subnav for the parent nav)
</span><span class="cx">          *             and this subnav item is the default for the parent item (which we check by
</span><span class="cx">          *             comparing this subnav item's screen function with the screen function of the
</span><span class="lines">@@ -276,16 +299,18 @@
</span><span class="cx"> 
</span><span class="cx">                 // Before hooking the screen function, check user access
</span><span class="cx">                 if ( !empty( $user_has_access ) ) {
</span><del>-                        if ( !is_object( $screen_function[0] ) ) {
-                                add_action( 'bp_screens', $screen_function );
</del><ins>+                        if ( is_object( $screen_function[0] ) ) {
+                                add_action( 'bp_screens', array( &amp;$screen_function[0], $screen_function[1] ), 3 );
</ins><span class="cx">                         } else {
</span><del>-                                add_action( 'bp_screens', array( &amp;$screen_function[0], $screen_function[1] ) );
</del><ins>+                                add_action( 'bp_screens', $screen_function, 3 );
</ins><span class="cx">                         }
</span><span class="cx">                 } else {
</span><del>-                        // When the content is off-limits, we handle the situation differently
-                        // depending on whether the current user is logged in
</del><ins>+
+                        // When the content is off-limits, we handle the situation
+                        // differently depending on whether the current user is logged in
</ins><span class="cx">                         if ( is_user_logged_in() ) {
</span><del>-                                if ( !bp_is_my_profile() &amp;&amp; !$bp-&gt;bp_nav[$bp-&gt;default_component]['show_for_displayed_user'] ) {
</del><ins>+                                if ( !bp_is_my_profile() &amp;&amp; empty( $bp-&gt;bp_nav[$bp-&gt;default_component]['show_for_displayed_user'] ) ) {
+
</ins><span class="cx">                                         // This covers the edge case where the default component is
</span><span class="cx">                                         // a non-public tab, like 'messages'
</span><span class="cx">                                         if ( bp_is_active( 'activity' ) &amp;&amp; isset( $bp-&gt;pages-&gt;activity ) ) {
</span><span class="lines">@@ -306,8 +331,9 @@
</span><span class="cx">                                         'root'     =&gt; $redirect_to,
</span><span class="cx">                                         'redirect' =&gt; false
</span><span class="cx">                                 ) );
</span><ins>+
+                        // Not logged in. Allow the user to log in, and attempt to redirect
</ins><span class="cx">                         } else {
</span><del>-                                // Not logged in. Allow the user to log in, and attempt to redirect
</del><span class="cx">                                 bp_core_no_access();
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="lines">@@ -382,10 +408,10 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( $function = $bp-&gt;bp_nav[$parent_id]['screen_function'] ) {
</span><del>-                if ( !is_object( $function[0] ) ) {
-                        remove_action( 'bp_screens', $function );
</del><ins>+                if ( is_object( $function[0] ) ) {
+                        remove_action( 'bp_screens', array( &amp;$function[0], $function[1] ), 3 );
</ins><span class="cx">                 } else {
</span><del>-                        remove_action( 'bp_screens', array( &amp;$function[0], $function[1] ) );
</del><ins>+                        remove_action( 'bp_screens', $function, 3 );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -402,13 +428,14 @@
</span><span class="cx"> function bp_core_remove_subnav_item( $parent_id, $slug ) {
</span><span class="cx">         global $bp;
</span><span class="cx"> 
</span><del>-        $screen_function = ( isset( $bp-&gt;bp_options_nav[$parent_id][$slug]['screen_function'] ) ) ? $bp-&gt;bp_options_nav[$parent_id][$slug]['screen_function'] : false;
</del><ins>+        $screen_function = isset( $bp-&gt;bp_options_nav[$parent_id][$slug]['screen_function'] ) ? $bp-&gt;bp_options_nav[$parent_id][$slug]['screen_function'] : false;
</ins><span class="cx"> 
</span><del>-        if ( $screen_function ) {
-                if ( !is_object( $screen_function[0] ) )
-                        remove_action( 'bp_screens', $screen_function );
-                else
-                        remove_action( 'bp_screens', array( &amp;$screen_function[0], $screen_function[1] ) );
</del><ins>+        if ( !empty( $screen_function ) ) {
+                if ( is_object( $screen_function[0] ) ) {
+                        remove_action( 'bp_screens', array( &amp;$screen_function[0], $screen_function[1] ), 3 );
+                } else {
+                        remove_action( 'bp_screens', $screen_function, 3 );
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         unset( $bp-&gt;bp_options_nav[$parent_id][$slug] );
</span><span class="lines">@@ -438,7 +465,7 @@
</span><span class="cx">         if ( defined( 'BP_DISABLE_ADMIN_BAR' ) &amp;&amp; BP_DISABLE_ADMIN_BAR )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        if ( (int)bp_get_option( 'hide-loggedout-adminbar' ) &amp;&amp; !is_user_logged_in() )
</del><ins>+        if ( (int) bp_get_option( 'hide-loggedout-adminbar' ) &amp;&amp; !is_user_logged_in() )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         $bp-&gt;doing_admin_bar = true;
</span></span></pre></div>
<a id="trunkbpmembersbpmemberstemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-members/bp-members-template.php (5921 => 5922)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-members/bp-members-template.php        2012-03-15 22:58:14 UTC (rev 5921)
+++ trunk/bp-members/bp-members-template.php        2012-03-16 00:30:11 UTC (rev 5922)
</span><span class="lines">@@ -744,7 +744,7 @@
</span><span class="cx">         global $bp;
</span><span class="cx"> 
</span><span class="cx">         foreach ( (array) $bp-&gt;bp_nav as $user_nav_item ) {
</span><del>-                if ( !$user_nav_item['show_for_displayed_user'] &amp;&amp; !bp_is_my_profile() )
</del><ins>+                if ( empty( $user_nav_item['show_for_displayed_user'] ) &amp;&amp; !bp_is_my_profile() )
</ins><span class="cx">                         continue;
</span><span class="cx"> 
</span><span class="cx">                 $selected = '';
</span></span></pre>
</div>
</div>

</body>
</html>