Changeset 9996 for trunk/src/bp-core/bp-core-buddybar.php
- Timestamp:
- 07/05/2015 04:57:22 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-buddybar.php
r9987 r9996 47 47 48 48 $r = wp_parse_args( $args, $defaults ); 49 extract( $r, EXTR_SKIP );50 49 51 50 // If we don't have the required info we need, don't create this subnav item 52 if ( empty( $name ) || empty( $slug ) ) 53 return false; 51 if ( empty( $r['name'] ) || empty( $r['slug'] ) ) { 52 return false; 53 } 54 54 55 55 // If this is for site admins only and the user is not one, don't create the subnav item 56 if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) ) 57 return false; 58 59 if ( empty( $item_css_id ) ) 60 $item_css_id = $slug; 61 62 $bp->bp_nav[$slug] = array( 63 'name' => $name, 64 'slug' => $slug, 65 'link' => trailingslashit( bp_loggedin_user_domain() . $slug ), 66 'css_id' => $item_css_id, 67 'show_for_displayed_user' => $show_for_displayed_user, 68 'position' => $position, 69 'screen_function' => &$screen_function, 70 'default_subnav_slug' => $default_subnav_slug 56 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 57 return false; 58 } 59 60 if ( empty( $r['item_css_id'] ) ) { 61 $r['item_css_id'] = $r['slug']; 62 } 63 64 $bp->bp_nav[$r['slug']] = array( 65 'name' => $r['name'], 66 'slug' => $r['slug'], 67 'link' => trailingslashit( bp_loggedin_user_domain() . $r['slug'] ), 68 'css_id' => $r['item_css_id'], 69 'show_for_displayed_user' => $r['show_for_displayed_user'], 70 'position' => $r['position'], 71 'screen_function' => &$r['screen_function'], 72 'default_subnav_slug' => $r['default_subnav_slug'] 71 73 ); 72 74 … … 76 78 * looking at their own profile, don't create the nav item. 77 79 */ 78 if ( empty( $show_for_displayed_user ) && !bp_user_has_access() ) 79 return false; 80 if ( empty( $r['show_for_displayed_user'] ) && ! bp_user_has_access() ) { 81 return false; 82 } 80 83 81 84 /** … … 84 87 * directory or something else. 85 88 */ 86 if ( ( -1 != $ position ) && bp_is_root_component( $slug ) && !bp_displayed_user_id() )89 if ( ( -1 != $r['position'] ) && bp_is_root_component( $r['slug'] ) && ! bp_displayed_user_id() ) { 87 90 return; 91 } 88 92 89 93 // Look for current component 90 if ( bp_is_current_component( $ slug ) || bp_is_current_item( $slug) ) {94 if ( bp_is_current_component( $r['slug'] ) || bp_is_current_item( $r['slug'] ) ) { 91 95 92 96 // The requested URL has explicitly included the default subnav 93 97 // (eg: http://example.com/members/membername/activity/just-me/) 94 98 // The canonical version will not contain this subnav slug. 95 if ( ! empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug) && !bp_action_variable( 0 ) ) {99 if ( ! empty( $r['default_subnav_slug'] ) && bp_is_current_action( $r['default_subnav_slug'] ) && !bp_action_variable( 0 ) ) { 96 100 unset( $bp->canonical_stack['action'] ); 97 101 } elseif ( ! bp_current_action() ) { 98 102 99 103 // Add our screen hook if screen function is callable 100 if ( is_callable( $ screen_function) ) {101 add_action( 'bp_screens', $ screen_function, 3 );104 if ( is_callable( $r['screen_function'] ) ) { 105 add_action( 'bp_screens', $r['screen_function'], 3 ); 102 106 } 103 107 104 if ( ! empty( $default_subnav_slug) ) {108 if ( ! empty( $r['default_subnav_slug'] ) ) { 105 109 106 110 /** … … 113 117 * @param array $r Parsed arguments for the nav item. 114 118 */ 115 $bp->current_action = apply_filters( 'bp_default_component_subnav', $ default_subnav_slug, $r );119 $bp->current_action = apply_filters( 'bp_default_component_subnav', $r['default_subnav_slug'], $r ); 116 120 } 117 121 } … … 149 153 150 154 $r = wp_parse_args( $args, $defaults ); 151 extract( $r, EXTR_SKIP ); 152 153 if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) { 155 156 if ( $function = $bp->bp_nav[$r['parent_slug']]['screen_function'] ) { 154 157 // Remove our screen hook if screen function is callable 155 158 if ( is_callable( $function ) ) { … … 158 161 } 159 162 160 $bp->bp_nav[$ parent_slug]['screen_function'] = &$screen_function;161 162 if ( bp_is_current_component( $ parent_slug) ) {163 $bp->bp_nav[$r['parent_slug']]['screen_function'] = &$r['screen_function']; 164 165 if ( bp_is_current_component( $r['parent_slug'] ) ) { 163 166 164 167 // The only way to tell whether to set the subnav is to peek at the unfiltered_uri 165 168 // Find the component 166 $component_uri_key = array_search( $ parent_slug, $bp->unfiltered_uri );169 $component_uri_key = array_search( $r['parent_slug'], $bp->unfiltered_uri ); 167 170 168 171 if ( false !== $component_uri_key ) { 169 if ( ! empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) {172 if ( ! empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) { 170 173 $unfiltered_action = $bp->unfiltered_uri[$component_uri_key + 1]; 171 174 } … … 174 177 // No subnav item has been requested in the URL, so set a new nav default 175 178 if ( empty( $unfiltered_action ) ) { 176 if ( ! bp_is_current_action( $subnav_slug) ) {177 if ( is_callable( $ screen_function) ) {178 add_action( 'bp_screens', $ screen_function, 3 );179 if ( ! bp_is_current_action( $r['subnav_slug'] ) ) { 180 if ( is_callable( $r['screen_function'] ) ) { 181 add_action( 'bp_screens', $r['screen_function'], 3 ); 179 182 } 180 183 181 $bp->current_action = $ subnav_slug;184 $bp->current_action = $r['subnav_slug']; 182 185 unset( $bp->canonical_stack['action'] ); 183 186 } … … 185 188 // The URL is explicitly requesting the new subnav item, but should be 186 189 // directed to the canonical URL 187 } elseif ( $unfiltered_action == $ subnav_slug) {190 } elseif ( $unfiltered_action == $r['subnav_slug'] ) { 188 191 unset( $bp->canonical_stack['action'] ); 189 192 … … 210 213 $bp = buddypress(); 211 214 212 if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) ) 213 return false; 215 if ( empty( $bp->bp_nav ) || ! is_array( $bp->bp_nav ) ) { 216 return false; 217 } 214 218 215 219 $temp = array(); 216 220 217 221 foreach ( (array) $bp->bp_nav as $slug => $nav_item ) { 218 if ( empty( $temp[$nav_item['position']] ) ) {222 if ( empty( $temp[$nav_item['position']] ) ) { 219 223 $temp[$nav_item['position']] = $nav_item; 220 224 } else { … … 222 226 do { 223 227 $nav_item['position']++; 224 } while ( ! empty( $temp[$nav_item['position']] ) );228 } while ( ! empty( $temp[$nav_item['position']] ) ); 225 229 226 230 $temp[$nav_item['position']] = $nav_item; … … 279 283 ) ); 280 284 281 extract( $r, EXTR_SKIP );282 283 285 // If we don't have the required info we need, don't create this subnav item 284 if ( empty( $ name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function) )286 if ( empty( $r['name'] ) || empty( $r['slug'] ) || empty( $r['parent_slug'] ) || empty( $r['parent_url'] ) || empty( $r['screen_function'] ) ) 285 287 return false; 286 288 287 289 // Link was not forced, so create one 288 if ( empty( $ link) ) {289 $ link = trailingslashit( $parent_url . $slug);290 if ( empty( $r['link'] ) ) { 291 $r['link'] = trailingslashit( $r['parent_url'] . $r['slug'] ); 290 292 291 293 // If this sub item is the default for its parent, skip the slug 292 if ( ! empty( $bp->bp_nav[$ parent_slug]['default_subnav_slug'] ) && $slug == $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) {293 $ link = trailingslashit( $parent_url);294 if ( ! empty( $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) && $r['slug'] == $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) { 295 $r['link'] = trailingslashit( $r['parent_url'] ); 294 296 } 295 297 } 296 298 297 299 // If this is for site admins only and the user is not one, don't create the subnav item 298 if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) ) 299 return false; 300 301 if ( empty( $item_css_id ) ) 302 $item_css_id = $slug; 300 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 301 return false; 302 } 303 304 if ( empty( $r['item_css_id'] ) ) { 305 $r['item_css_id'] = $r['slug']; 306 } 303 307 304 308 $subnav_item = array( 305 'name' => $ name,306 'link' => $ link,307 'slug' => $ slug,308 'css_id' => $ item_css_id,309 'position' => $ position,310 'user_has_access' => $ user_has_access,311 'no_access_url' => $ no_access_url,312 'screen_function' => &$ screen_function,309 'name' => $r['name'], 310 'link' => $r['link'], 311 'slug' => $r['slug'], 312 'css_id' => $r['item_css_id'], 313 'position' => $r['position'], 314 'user_has_access' => $r['user_has_access'], 315 'no_access_url' => $r['no_access_url'], 316 'screen_function' => &$r['screen_function'], 313 317 'show_in_admin_bar' => (bool) $r['show_in_admin_bar'], 314 318 ); 315 319 316 $bp->bp_options_nav[$ parent_slug][$slug] = $subnav_item;320 $bp->bp_options_nav[$r['parent_slug']][$r['slug']] = $subnav_item; 317 321 318 322 /** … … 334 338 335 339 // If we *don't* meet condition (1), return 336 if ( ! bp_is_current_component( $ parent_slug ) && ! bp_is_current_item( $parent_slug ) )340 if ( ! bp_is_current_component( $r['parent_slug'] ) && ! bp_is_current_item( $r['parent_slug'] ) ) { 337 341 return; 342 } 338 343 339 344 // If we *do* meet condition (2), then the added subnav item is currently being requested 340 if ( ( bp_current_action() && bp_is_current_action( $ slug ) ) || ( bp_is_user() && ! bp_current_action() && ( $screen_function== $bp->bp_nav[$parent_slug]['screen_function'] ) ) ) {345 if ( ( bp_current_action() && bp_is_current_action( $r['slug'] ) ) || ( bp_is_user() && ! bp_current_action() && ( $r['screen_function'] == $bp->bp_nav[$parent_slug]['screen_function'] ) ) ) { 341 346 342 347 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
Note: See TracChangeset
for help on using the changeset viewer.