BP_Core_Nav::delete_nav( string $slug = '', string $parent_slug = '' )
Unset an item or a subitem of the nav.
Description
Parameters
- $slug
-
(Optional) The slug of the main item.
Default value: ''
- $parent_slug
-
(Optional) The slug of the sub item.
Default value: ''
Return
(false|callable|array) False on failure, the screen function(s) on success.
Source
File: bp-core/classes/class-bp-core-nav.php
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | public function delete_nav( $slug = '' , $parent_slug = '' ) { // Bail if slug is empty if ( empty ( $slug ) ) { return false; } // We're deleting a child if ( ! empty ( $parent_slug ) ) { // Validate the subnav $sub_items = $this ->get_secondary( array ( 'parent_slug' => $parent_slug , 'slug' => $slug ), false ); if ( ! $sub_items ) { return false; } $sub_item = reset( $sub_items ); if ( empty ( $sub_item ->slug ) ) { return false; } // Delete the child unset( $this ->nav[ $this ->object_id ][ $parent_slug . '/' . $slug ] ); // Return the deleted item's screen function return array ( $sub_item ->screen_function ); // We're deleting a parent } else { // Validate the nav $nav_items = $this ->get_primary( array ( 'slug' => $slug ), false ); if ( ! $nav_items ) { return false; } $nav_item = reset( $nav_items ); if ( empty ( $nav_item ->slug ) ) { return false; } $screen_functions = array ( $nav_item ->screen_function ); // Life's unfair, children won't survive the parent :( $sub_items = $this ->get_secondary( array ( 'parent_slug' => $nav_item ->slug ), false ); if ( ! empty ( $sub_items ) ) { foreach ( $sub_items as $sub_item ) { $screen_functions [] = $sub_item ->screen_function; // Delete the child unset( $this ->nav[ $this ->object_id ][ $nav_item ->slug . '/' . $sub_item ->slug ] ); } } // Delete the parent. unset( $this ->nav[ $this ->object_id ][ $nav_item ->slug ] ); // Return the deleted item's screen functions. return $screen_functions ; } } |
Changelog
Version | Description |
---|---|
BuddyPress 2.6.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.