Changeset 10003
- Timestamp:
- 07/10/2015 02:54:03 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-buddybar.php
r10001 r10003 33 33 */ 34 34 function bp_core_new_nav_item( $args = '' ) { 35 $bp = buddypress();36 35 37 36 $defaults = array( … … 48 47 $r = wp_parse_args( $args, $defaults ); 49 48 50 // If we don't have the required info we need, don't create this subnav item 49 // First, add the nav item link to the bp_nav array. 50 $created = bp_core_create_nav_link( $r ); 51 52 // To mimic the existing behavior, if bp_core_create_nav_link() 53 // returns false, we make an early exit and don't attempt to register 54 // the screen function. 55 if ( false === $created ) { 56 return false; 57 } 58 59 // Then, hook the screen function for the added nav item. 60 bp_core_register_nav_screen_function( $r ); 61 62 /** 63 * Fires after adding an item to the main BuddyPress navigation array. 64 * Note that, when possible, the more specific action hooks 65 * `bp_core_create_nav_link` or `bp_core_register_nav_screen_function` 66 * should be used. 67 * 68 * @since BuddyPress (1.5.0) 69 * 70 * @param array $r Parsed arguments for the nav item. 71 * @param array $args Originally passed in arguments for the nav item. 72 * @param array $defaults Default arguments for a nav item. 73 */ 74 do_action( 'bp_core_new_nav_item', $r, $args, $defaults ); 75 } 76 77 /** 78 * Add a link to the main BuddyPress navigation array. 79 * 80 * @since BuddyPress (2.4.0) 81 * 82 * @param array $args { 83 * Array describing the new nav item. 84 * @type string $name Display name for the nav item. 85 * @type string $slug Unique URL slug for the nav item. 86 * @type bool|string $item_css_id Optional. 'id' attribute for the nav item. Default: the value of `$slug`. 87 * @type bool $show_for_displayed_user Optional. Whether the nav item should be visible when viewing a 88 * member profile other than your own. Default: true. 89 * @type bool $site_admin_only Optional. Whether the nav item should be visible only to site admins 90 * (those with the 'bp_moderate' cap). Default: false. 91 * @type int $position Optional. Numerical index specifying where the item should appear in 92 * the nav array. Default: 99. 93 * @type callable $screen_function The callback function that will run when the nav item is clicked. 94 * @type bool|string $default_subnav_slug Optional. The slug of the default subnav item to select when the nav 95 * item is clicked. 96 * } 97 * @return bool|null Returns false on failure. 98 */ 99 function bp_core_create_nav_link( $args = '' ) { 100 $bp = buddypress(); 101 102 $defaults = array( 103 'name' => false, // Display name for the nav item 104 'slug' => false, // URL slug for the nav item 105 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 106 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 107 'site_admin_only' => false, // Can only site admins see this nav item? 108 'position' => 99, // Index of where this nav item should be positioned 109 'screen_function' => false, // The name of the function to run when clicked 110 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 111 ); 112 113 $r = wp_parse_args( $args, $defaults ); 114 115 // If we don't have the required info we need, don't create this nav item. 51 116 if ( empty( $r['name'] ) || empty( $r['slug'] ) ) { 52 117 return false; 53 118 } 54 119 55 // If this is for site admins only and the user is not one, don't create the subnav item120 // If this is for site admins only and the user is not one, don't create the nav item. 56 121 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 122 return false; 123 } 124 125 /** 126 * If this nav item is hidden for the displayed user, and 127 * the logged in user is not the displayed user 128 * looking at their own profile, don't create the nav item. 129 */ 130 if ( empty( $r['show_for_displayed_user'] ) && ! bp_user_has_access() ) { 57 131 return false; 58 132 } … … 73 147 ); 74 148 149 /** 150 * Fires after a link is added to the main BuddyPress navigation array. 151 * 152 * @since BuddyPress (2.4.0) 153 * 154 * @param array $r Parsed arguments for the nav item. 155 * @param array $args Originally passed in arguments for the nav item. 156 * @param array $defaults Default arguments for a nav item. 157 */ 158 do_action( 'bp_core_create_nav_link', $r, $args, $defaults ); 159 } 160 161 /** 162 * Register a screen function for an item in the main nav array. 163 * 164 * @since BuddyPress (2.4.0) 165 * 166 * @param array $args { 167 * Array describing the new nav item. 168 * @type string $name Display name for the nav item. 169 * @type string $slug Unique URL slug for the nav item. 170 * @type bool|string $item_css_id Optional. 'id' attribute for the nav item. Default: the value of `$slug`. 171 * @type bool $show_for_displayed_user Optional. Whether the nav item should be visible when viewing a 172 * member profile other than your own. Default: true. 173 * @type bool $site_admin_only Optional. Whether the nav item should be visible only to site admins 174 * (those with the 'bp_moderate' cap). Default: false. 175 * @type int $position Optional. Numerical index specifying where the item should appear in 176 * the nav array. Default: 99. 177 * @type callable $screen_function The callback function that will run when the nav item is clicked. 178 * @type bool|string $default_subnav_slug Optional. The slug of the default subnav item to select when the nav 179 * item is clicked. 180 * } 181 * @return bool|null Returns false on failure. 182 */ 183 function bp_core_register_nav_screen_function( $args = '' ) { 184 $bp = buddypress(); 185 186 $defaults = array( 187 'name' => false, // Display name for the nav item 188 'slug' => false, // URL slug for the nav item 189 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 190 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 191 'site_admin_only' => false, // Can only site admins see this nav item? 192 'position' => 99, // Index of where this nav item should be positioned 193 'screen_function' => false, // The name of the function to run when clicked 194 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 195 ); 196 197 $r = wp_parse_args( $args, $defaults ); 198 199 // If we don't have the required info we need, don't register this screen function. 200 if ( empty( $r['slug'] ) ) { 201 return false; 202 } 203 204 /** 205 * If this is for site admins only and the user is not one, 206 * don't register this screen function. 207 */ 208 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 209 return false; 210 } 211 75 212 /** 76 213 * If this nav item is hidden for the displayed user, and 77 214 * the logged in user is not the displayed user 78 * looking at their own profile, don't create the nav item.215 * looking at their own profile, don't don't register this screen function. 79 216 */ 80 217 if ( empty( $r['show_for_displayed_user'] ) && ! bp_user_has_access() ) { … … 97 234 // (eg: http://example.com/members/membername/activity/just-me/) 98 235 // The canonical version will not contain this subnav slug. 99 if ( ! empty( $r['default_subnav_slug'] ) && bp_is_current_action( $r['default_subnav_slug'] ) && ! bp_action_variable( 0 ) ) {236 if ( ! empty( $r['default_subnav_slug'] ) && bp_is_current_action( $r['default_subnav_slug'] ) && ! bp_action_variable( 0 ) ) { 100 237 unset( $bp->canonical_stack['action'] ); 101 238 } elseif ( ! bp_current_action() ) { … … 123 260 124 261 /** 125 * Fires after adding an item to the main BuddyPress navigation array. 262 * Fires after the screen function for an item in the BuddyPress main 263 * navigation is registered. 126 264 * 127 * @since BuddyPress ( 1.5.0)265 * @since BuddyPress (2.4.0) 128 266 * 129 267 * @param array $r Parsed arguments for the nav item. … … 131 269 * @param array $defaults Default arguments for a nav item. 132 270 */ 133 do_action( 'bp_core_ new_nav_item', $r, $args, $defaults );271 do_action( 'bp_core_register_nav_screen_function', $r, $args, $defaults ); 134 272 } 135 273
Note: See TracChangeset
for help on using the changeset viewer.