| | 35 | |
| | 36 | // First, add the nav item link to the bp_nav array. |
| | 37 | $created = bp_core_create_nav_link( $args ); |
| | 38 | |
| | 39 | // To mimic the existing behavior, if bp_core_create_nav_link() |
| | 40 | // returns false, we make an early exit and don't attempt to register |
| | 41 | // the screen function. |
| | 42 | if ( false === $created ) { |
| | 43 | return false; |
| | 44 | } |
| | 45 | |
| | 46 | // Then, hook the screen function for the added nav item. |
| | 47 | bp_core_register_nav_screen_function( $args ); |
| | 48 | |
| | 49 | } |
| | 50 | |
| | 51 | /** |
| | 52 | * Add a link to the main BuddyPress navigation array. |
| | 53 | * |
| | 54 | * @param array $args { |
| | 55 | * Array describing the new nav item. |
| | 56 | * @type string $name Display name for the nav item. |
| | 57 | * @type string $slug Unique URL slug for the nav item. |
| | 58 | * @type bool|string $item_css_id Optional. 'id' attribute for the nav item. Default: the value of `$slug`. |
| | 59 | * @type bool $show_for_displayed_user Optional. Whether the nav item should be visible when viewing a |
| | 60 | * member profile other than your own. Default: true. |
| | 61 | * @type bool $site_admin_only Optional. Whether the nav item should be visible only to site admins |
| | 62 | * (those with the 'bp_moderate' cap). Default: false. |
| | 63 | * @type int $position Optional. Numerical index specifying where the item should appear in |
| | 64 | * the nav array. Default: 99. |
| | 65 | * @type callable $screen_function The callback function that will run when the nav item is clicked. |
| | 66 | * @type bool|string $default_subnav_slug Optional. The slug of the default subnav item to select when the nav |
| | 67 | * item is clicked. |
| | 68 | * } |
| | 69 | * @return bool|null Returns false on failure. |
| | 70 | */ |
| | 71 | function bp_core_create_nav_link( $args = '' ) { |
| | 119 | } |
| | 120 | |
| | 121 | /** |
| | 122 | * Register a screen function, whether or not a related nav link exists. |
| | 123 | * |
| | 124 | * @param array $args { |
| | 125 | * Array describing the new nav item. |
| | 126 | * @type string $name Display name for the nav item. |
| | 127 | * @type string $slug Unique URL slug for the nav item. |
| | 128 | * @type bool|string $item_css_id Optional. 'id' attribute for the nav item. Default: the value of `$slug`. |
| | 129 | * @type bool $show_for_displayed_user Optional. Whether the nav item should be visible when viewing a |
| | 130 | * member profile other than your own. Default: true. |
| | 131 | * @type bool $site_admin_only Optional. Whether the nav item should be visible only to site admins |
| | 132 | * (those with the 'bp_moderate' cap). Default: false. |
| | 133 | * @type int $position Optional. Numerical index specifying where the item should appear in |
| | 134 | * the nav array. Default: 99. |
| | 135 | * @type callable $screen_function The callback function that will run when the nav item is clicked. |
| | 136 | * @type bool|string $default_subnav_slug Optional. The slug of the default subnav item to select when the nav |
| | 137 | * item is clicked. |
| | 138 | * } |
| | 139 | * @return bool|null Returns false on failure. |
| | 140 | */ |
| | 141 | function bp_core_register_nav_screen_function( $args = '' ) { |
| | 142 | $bp = buddypress(); |
| | 143 | |
| | 144 | $defaults = array( |
| | 145 | 'name' => false, // Display name for the nav item |
| | 146 | 'slug' => false, // URL slug for the nav item |
| | 147 | 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item |
| | 148 | 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? |
| | 149 | 'site_admin_only' => false, // Can only site admins see this nav item? |
| | 150 | 'position' => 99, // Index of where this nav item should be positioned |
| | 151 | 'screen_function' => false, // The name of the function to run when clicked |
| | 152 | 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked |
| | 153 | ); |
| | 154 | |
| | 155 | $r = wp_parse_args( $args, $defaults ); |
| | 156 | |
| | 157 | // If we don't have the required info we need, don't create this subnav item |
| | 158 | if ( empty( $r['slug'] ) ) { |
| | 159 | return false; |
| | 160 | } |
| | 161 | |
| | 162 | // If this is for site admins only and the user is not one, don't create the subnav item |
| | 163 | if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { |
| | 164 | return false; |
| | 165 | } |
| | 166 | |