diff --git a/src/bp-core/bp-core-buddybar.php b/src/bp-core/bp-core-buddybar.php
index ca87d9a..ebcd9e7 100644
|
a
|
b
|
function bp_core_new_nav_item( $args = '' ) { |
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | $r = wp_parse_args( $args, $defaults ); |
| 53 | | extract( $r, EXTR_SKIP ); |
| 54 | 53 | |
| 55 | 54 | // If we don't have the required info we need, don't create this subnav item |
| 56 | | if ( empty( $name ) || empty( $slug ) ) |
| | 55 | if ( empty( $r['name'] ) || empty( $r['slug'] ) ) { |
| 57 | 56 | return false; |
| | 57 | } |
| 58 | 58 | |
| 59 | 59 | // If this is for site admins only and the user is not one, don't create the subnav item |
| 60 | | if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) ) |
| | 60 | if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { |
| 61 | 61 | return false; |
| | 62 | } |
| | 63 | |
| | 64 | if ( empty( $r['item_css_id'] ) ) { |
| | 65 | $r['item_css_id'] = $r['slug']; |
| | 66 | } |
| 62 | 67 | |
| 63 | | if ( empty( $item_css_id ) ) |
| 64 | | $item_css_id = $slug; |
| 65 | | |
| 66 | | $bp->bp_nav[$slug] = array( |
| 67 | | 'name' => $name, |
| 68 | | 'slug' => $slug, |
| 69 | | 'link' => trailingslashit( bp_loggedin_user_domain() . $slug ), |
| 70 | | 'css_id' => $item_css_id, |
| 71 | | 'show_for_displayed_user' => $show_for_displayed_user, |
| 72 | | 'position' => $position, |
| 73 | | 'screen_function' => &$screen_function, |
| 74 | | 'default_subnav_slug' => $default_subnav_slug |
| | 68 | $bp->bp_nav[$r['slug']] = array( |
| | 69 | 'name' => $r['name'], |
| | 70 | 'slug' => $r['slug'], |
| | 71 | 'link' => trailingslashit( bp_loggedin_user_domain() . $r['slug'] ), |
| | 72 | 'css_id' => $r['item_css_id'], |
| | 73 | 'show_for_displayed_user' => $r['show_for_displayed_user'], |
| | 74 | 'position' => $r['position'], |
| | 75 | 'screen_function' => &$r['screen_function'], |
| | 76 | 'default_subnav_slug' => $r['default_subnav_slug'] |
| 75 | 77 | ); |
| 76 | 78 | |
| 77 | 79 | /** |
| … |
… |
function bp_core_new_nav_item( $args = '' ) { |
| 79 | 81 | * the logged in user is not the displayed user |
| 80 | 82 | * looking at their own profile, don't create the nav item. |
| 81 | 83 | */ |
| 82 | | if ( empty( $show_for_displayed_user ) && !bp_user_has_access() ) |
| | 84 | if ( empty( $r['show_for_displayed_user'] ) && ! bp_user_has_access() ) { |
| 83 | 85 | return false; |
| | 86 | } |
| 84 | 87 | |
| 85 | 88 | /** |
| 86 | 89 | * If the nav item is visible, we are not viewing a user, and this is a root |
| 87 | 90 | * component, don't attach the default subnav function so we can display a |
| 88 | 91 | * directory or something else. |
| 89 | 92 | */ |
| 90 | | if ( ( -1 != $position ) && bp_is_root_component( $slug ) && !bp_displayed_user_id() ) |
| | 93 | if ( ( -1 != $r['position'] ) && bp_is_root_component( $r['slug'] ) && ! bp_displayed_user_id() ) { |
| 91 | 94 | return; |
| | 95 | } |
| 92 | 96 | |
| 93 | 97 | // Look for current component |
| 94 | | if ( bp_is_current_component( $slug ) || bp_is_current_item( $slug ) ) { |
| | 98 | if ( bp_is_current_component( $r['slug'] ) || bp_is_current_item( $r['slug'] ) ) { |
| 95 | 99 | |
| 96 | 100 | // The requested URL has explicitly included the default subnav |
| 97 | 101 | // (eg: http://example.com/members/membername/activity/just-me/) |
| 98 | 102 | // The canonical version will not contain this subnav slug. |
| 99 | | if ( !empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) && !bp_action_variable( 0 ) ) { |
| | 103 | if ( ! empty( $r['default_subnav_slug'] ) && bp_is_current_action( $r['default_subnav_slug'] ) && !bp_action_variable( 0 ) ) { |
| 100 | 104 | unset( $bp->canonical_stack['action'] ); |
| 101 | 105 | } elseif ( ! bp_current_action() ) { |
| 102 | 106 | |
| 103 | 107 | // Add our screen hook if screen function is callable |
| 104 | | if ( is_callable( $screen_function ) ) { |
| 105 | | add_action( 'bp_screens', $screen_function, 3 ); |
| | 108 | if ( is_callable( $r['screen_function'] ) ) { |
| | 109 | add_action( 'bp_screens', $r['screen_function'], 3 ); |
| 106 | 110 | } |
| 107 | 111 | |
| 108 | | if ( !empty( $default_subnav_slug ) ) { |
| | 112 | if ( ! empty( $r['default_subnav_slug'] ) ) { |
| 109 | 113 | |
| 110 | 114 | /** |
| 111 | 115 | * Filters the default component subnav item. |
| … |
… |
function bp_core_new_nav_item( $args = '' ) { |
| 116 | 120 | * to select when clicked. |
| 117 | 121 | * @param array $r Parsed arguments for the nav item. |
| 118 | 122 | */ |
| 119 | | $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r ); |
| | 123 | $bp->current_action = apply_filters( 'bp_default_component_subnav', $r['default_subnav_slug'], $r ); |
| 120 | 124 | } |
| 121 | 125 | } |
| 122 | 126 | } |
| … |
… |
function bp_core_new_nav_default( $args = '' ) { |
| 154 | 158 | ); |
| 155 | 159 | |
| 156 | 160 | $r = wp_parse_args( $args, $defaults ); |
| 157 | | extract( $r, EXTR_SKIP ); |
| 158 | 161 | |
| 159 | | if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) { |
| | 162 | if ( $function = $bp->bp_nav[$r['parent_slug']]['screen_function'] ) { |
| 160 | 163 | // Remove our screen hook if screen function is callable |
| 161 | 164 | if ( is_callable( $function ) ) { |
| 162 | 165 | remove_action( 'bp_screens', $function, 3 ); |
| 163 | 166 | } |
| 164 | 167 | } |
| 165 | 168 | |
| 166 | | $bp->bp_nav[$parent_slug]['screen_function'] = &$screen_function; |
| | 169 | $bp->bp_nav[$r['parent_slug']]['screen_function'] = &$r['screen_function']; |
| 167 | 170 | |
| 168 | | if ( bp_is_current_component( $parent_slug ) ) { |
| | 171 | if ( bp_is_current_component( $r['parent_slug'] ) ) { |
| 169 | 172 | |
| 170 | 173 | // The only way to tell whether to set the subnav is to peek at the unfiltered_uri |
| 171 | 174 | // Find the component |
| 172 | | $component_uri_key = array_search( $parent_slug, $bp->unfiltered_uri ); |
| | 175 | $component_uri_key = array_search( $r['parent_slug'], $bp->unfiltered_uri ); |
| 173 | 176 | |
| 174 | 177 | if ( false !== $component_uri_key ) { |
| 175 | | if ( !empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) { |
| | 178 | if ( ! empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) { |
| 176 | 179 | $unfiltered_action = $bp->unfiltered_uri[$component_uri_key + 1]; |
| 177 | 180 | } |
| 178 | 181 | } |
| 179 | 182 | |
| 180 | 183 | // No subnav item has been requested in the URL, so set a new nav default |
| 181 | 184 | if ( empty( $unfiltered_action ) ) { |
| 182 | | if ( !bp_is_current_action( $subnav_slug ) ) { |
| 183 | | if ( is_callable( $screen_function ) ) { |
| 184 | | add_action( 'bp_screens', $screen_function, 3 ); |
| | 185 | if ( ! bp_is_current_action( $r['subnav_slug'] ) ) { |
| | 186 | if ( is_callable( $r['screen_function'] ) ) { |
| | 187 | add_action( 'bp_screens', $r['screen_function'], 3 ); |
| 185 | 188 | } |
| 186 | 189 | |
| 187 | | $bp->current_action = $subnav_slug; |
| | 190 | $bp->current_action = $r['subnav_slug']; |
| 188 | 191 | unset( $bp->canonical_stack['action'] ); |
| 189 | 192 | } |
| 190 | 193 | |
| 191 | 194 | // The URL is explicitly requesting the new subnav item, but should be |
| 192 | 195 | // directed to the canonical URL |
| 193 | | } elseif ( $unfiltered_action == $subnav_slug ) { |
| | 196 | } elseif ( $unfiltered_action == $r['subnav_slug'] ) { |
| 194 | 197 | unset( $bp->canonical_stack['action'] ); |
| 195 | 198 | |
| 196 | 199 | // In all other cases (including the case where the original subnav item |
| … |
… |
function bp_core_new_nav_default( $args = '' ) { |
| 215 | 218 | function bp_core_sort_nav_items() { |
| 216 | 219 | $bp = buddypress(); |
| 217 | 220 | |
| 218 | | if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) ) |
| | 221 | if ( empty( $bp->bp_nav ) || ! is_array( $bp->bp_nav ) ) { |
| 219 | 222 | return false; |
| | 223 | } |
| 220 | 224 | |
| 221 | 225 | $temp = array(); |
| 222 | 226 | |
| 223 | 227 | foreach ( (array) $bp->bp_nav as $slug => $nav_item ) { |
| 224 | | if ( empty( $temp[$nav_item['position']]) ) { |
| | 228 | if ( empty( $temp[$nav_item['position']] ) ) { |
| 225 | 229 | $temp[$nav_item['position']] = $nav_item; |
| 226 | 230 | } else { |
| 227 | 231 | // increase numbers here to fit new items in. |
| 228 | 232 | do { |
| 229 | 233 | $nav_item['position']++; |
| 230 | | } while ( !empty( $temp[$nav_item['position']] ) ); |
| | 234 | } while ( ! empty( $temp[$nav_item['position']] ) ); |
| 231 | 235 | |
| 232 | 236 | $temp[$nav_item['position']] = $nav_item; |
| 233 | 237 | } |
| … |
… |
function bp_core_new_subnav_item( $args = '' ) { |
| 288 | 292 | 'show_in_admin_bar' => false, // Show the Manage link in the current group's "Edit" Admin Bar menu |
| 289 | 293 | ) ); |
| 290 | 294 | |
| 291 | | extract( $r, EXTR_SKIP ); |
| 292 | | |
| 293 | 295 | // If we don't have the required info we need, don't create this subnav item |
| 294 | | if ( empty( $name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) ) |
| | 296 | if ( empty( $r['name'] ) || empty( $r['slug'] ) || empty( $r['parent_slug'] ) || empty( $r['parent_url'] ) || empty( $r['screen_function'] ) ) |
| 295 | 297 | return false; |
| 296 | 298 | |
| 297 | 299 | // Link was not forced, so create one |
| 298 | | if ( empty( $link ) ) { |
| 299 | | $link = trailingslashit( $parent_url . $slug ); |
| | 300 | if ( empty( $r['link'] ) ) { |
| | 301 | $r['link'] = trailingslashit( $r['parent_url'] . $r['slug'] ); |
| 300 | 302 | |
| 301 | 303 | // If this sub item is the default for its parent, skip the slug |
| 302 | | if ( ! empty( $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) && $slug == $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) { |
| 303 | | $link = trailingslashit( $parent_url ); |
| | 304 | if ( ! empty( $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) && $r['slug'] == $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) { |
| | 305 | $r['link'] = trailingslashit( $r['parent_url'] ); |
| 304 | 306 | } |
| 305 | 307 | } |
| 306 | 308 | |
| 307 | 309 | // If this is for site admins only and the user is not one, don't create the subnav item |
| 308 | | if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) ) |
| | 310 | if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { |
| 309 | 311 | return false; |
| | 312 | } |
| 310 | 313 | |
| 311 | | if ( empty( $item_css_id ) ) |
| 312 | | $item_css_id = $slug; |
| | 314 | if ( empty( $r['item_css_id'] ) ) { |
| | 315 | $r['item_css_id'] = $r['slug']; |
| | 316 | } |
| 313 | 317 | |
| 314 | 318 | $subnav_item = array( |
| 315 | | 'name' => $name, |
| 316 | | 'link' => $link, |
| 317 | | 'slug' => $slug, |
| 318 | | 'css_id' => $item_css_id, |
| 319 | | 'position' => $position, |
| 320 | | 'user_has_access' => $user_has_access, |
| 321 | | 'no_access_url' => $no_access_url, |
| 322 | | 'screen_function' => &$screen_function, |
| | 319 | 'name' => $r['name'], |
| | 320 | 'link' => $r['link'], |
| | 321 | 'slug' => $r['slug'], |
| | 322 | 'css_id' => $r['item_css_id'], |
| | 323 | 'position' => $r['position'], |
| | 324 | 'user_has_access' => $r['user_has_access'], |
| | 325 | 'no_access_url' => $r['no_access_url'], |
| | 326 | 'screen_function' => &$r['screen_function'], |
| 323 | 327 | 'show_in_admin_bar' => (bool) $r['show_in_admin_bar'], |
| 324 | 328 | ); |
| 325 | 329 | |
| 326 | | $bp->bp_options_nav[$parent_slug][$slug] = $subnav_item; |
| | 330 | $bp->bp_options_nav[$r['parent_slug']][$r['slug']] = $subnav_item; |
| 327 | 331 | |
| 328 | 332 | /** |
| 329 | 333 | * The last step is to hook the screen function for the added subnav item. But this only |
| … |
… |
function bp_core_new_subnav_item( $args = '' ) { |
| 343 | 347 | */ |
| 344 | 348 | |
| 345 | 349 | // If we *don't* meet condition (1), return |
| 346 | | if ( ! bp_is_current_component( $parent_slug ) && ! bp_is_current_item( $parent_slug ) ) |
| | 350 | if ( ! bp_is_current_component( $r['parent_slug'] ) && ! bp_is_current_item( $r['parent_slug'] ) ) { |
| 347 | 351 | return; |
| | 352 | } |
| 348 | 353 | |
| 349 | 354 | // If we *do* meet condition (2), then the added subnav item is currently being requested |
| 350 | | if ( ( bp_current_action() && bp_is_current_action( $slug ) ) || ( bp_is_user() && ! bp_current_action() && ( $screen_function == $bp->bp_nav[$parent_slug]['screen_function'] ) ) ) { |
| | 355 | 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'] ) ) ) { |
| 351 | 356 | |
| 352 | 357 | $hooked = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); |
| 353 | 358 | |
| … |
… |
function bp_core_new_subnav_item( $args = '' ) { |
| 356 | 361 | bp_core_no_access( $hooked['redirect_args'] ); |
| 357 | 362 | } |
| 358 | 363 | } |
| | 364 | |
| 359 | 365 | } |
| 360 | 366 | |
| 361 | 367 | /** |