| | 278 | |
| | 279 | // First, add the subnav item link to the bp_options_nav array. |
| | 280 | $created = bp_core_create_subnav_link( $args ); |
| | 281 | |
| | 282 | // To mimic the existing behavior, if bp_core_create_subnav_link() |
| | 283 | // returns false, we make an early exit and don't attempt to register |
| | 284 | // the screen function. |
| | 285 | if ( false === $created ) { |
| | 286 | return false; |
| | 287 | } |
| | 288 | |
| | 289 | // Then, hook the screen function for the added subnav item. |
| | 290 | bp_core_register_subnav_screen_function( $args ); |
| | 291 | |
| | 292 | } |
| | 293 | |
| | 294 | /** |
| | 295 | * Add a subnav link to the BuddyPress navigation. |
| | 296 | * |
| | 297 | * @param array $args { |
| | 298 | * Array describing the new subnav item. |
| | 299 | * @type string $name Display name for the subnav item. |
| | 300 | * @type string $slug Unique URL slug for the subnav item. |
| | 301 | * @type string $parent_slug Slug of the top-level nav item under which the |
| | 302 | * new subnav item should be added. |
| | 303 | * @type string $parent_url URL of the parent nav item. |
| | 304 | * @type bool|string $item_css_id Optional. 'id' attribute for the nav |
| | 305 | * item. Default: the value of $slug. |
| | 306 | * @type bool $user_has_access Optional. True if the logged-in user has |
| | 307 | * access to the subnav item, otherwise false. Can be set dynamically |
| | 308 | * when registering the subnav; eg, use bp_is_my_profile() to restrict |
| | 309 | * access to profile owners only. Default: true. |
| | 310 | * @type bool $site_admin_only Optional. Whether the nav item should be |
| | 311 | * visible only to site admins (those with the 'bp_moderate' cap). |
| | 312 | * Default: false. |
| | 313 | * @type int $position Optional. Numerical index specifying where the item |
| | 314 | * should appear in the subnav array. Default: 90. |
| | 315 | * @type callable $screen_function The callback function that will run |
| | 316 | * when the nav item is clicked. |
| | 317 | * @type string $link Optional. The URL that the subnav item should point |
| | 318 | * to. Defaults to a value generated from the $parent_url + $slug. |
| | 319 | * @type bool $show_in_admin_bar Optional. Whether the nav item should be |
| | 320 | * added into the group's "Edit" Admin Bar menu for group admins. |
| | 321 | * Default: false. |
| | 322 | * } |
| | 323 | * @return bool|null Returns false on failure. |
| | 324 | */ |
| | 325 | function bp_core_create_subnav_link( $args = '' ) { |
| | 379 | } |
| | 380 | |
| | 381 | /** |
| | 382 | * Register a screen function, whether or not a related subnav link exists. |
| | 383 | * |
| | 384 | * @param array $args { |
| | 385 | * Array describing the new subnav item. |
| | 386 | * @type string $slug Unique URL slug for the subnav item. |
| | 387 | * @type string $parent_slug Slug of the top-level nav item under which the |
| | 388 | * new subnav item should be added. |
| | 389 | * @type string $parent_url URL of the parent nav item. |
| | 390 | * @type bool $user_has_access Optional. True if the logged-in user has |
| | 391 | * access to the subnav item, otherwise false. Can be set dynamically |
| | 392 | * when registering the subnav; eg, use bp_is_my_profile() to restrict |
| | 393 | * access to profile owners only. Default: true. |
| | 394 | * @type bool $site_admin_only Optional. Whether the nav item should be |
| | 395 | * visible only to site admins (those with the 'bp_moderate' cap). |
| | 396 | * Default: false. |
| | 397 | * @type int $position Optional. Numerical index specifying where the item |
| | 398 | * should appear in the subnav array. Default: 90. |
| | 399 | * @type callable $screen_function The callback function that will run |
| | 400 | * when the nav item is clicked. |
| | 401 | * @type string $link Optional. The URL that the subnav item should point |
| | 402 | * to. Defaults to a value generated from the $parent_url + $slug. |
| | 403 | * @type bool $show_in_admin_bar Optional. Whether the nav item should be |
| | 404 | * added into the group's "Edit" Admin Bar menu for group admins. |
| | 405 | * Default: false. |
| | 406 | * } |
| | 407 | * @return bool|null Returns false on failure. |
| | 408 | */ |
| | 409 | function bp_core_register_subnav_screen_function( $args = '' ) { |
| | 410 | $r = wp_parse_args( $args, array( |
| | 411 | 'slug' => false, // URL slug for the screen |
| | 412 | 'parent_slug' => false, // URL slug of the parent screen |
| | 413 | 'user_has_access' => true, // Can the user visit this screen? |
| | 414 | 'no_access_url' => '', |
| | 415 | 'site_admin_only' => false, // Can only site admins visit this screen? |
| | 416 | 'screen_function' => false, // The name of the function to run when clicked |
| | 417 | ) ); |
| 333 | | * The last step is to hook the screen function for the added subnav item. But this only |
| 334 | | * needs to be done if this subnav item is the current view, and the user has access to the |
| 335 | | * subnav item. We figure out whether we're currently viewing this subnav by checking the |
| 336 | | * following two conditions: |
| | 420 | * Hook the screen function for the added subnav item. But this only needs to |
| | 421 | * be done if this subnav item is the current view, and the user has access to the |
| | 422 | * subnav item. We figure out whether we're currently viewing this subnav by |
| | 423 | * checking the following two conditions: |