#6861 closed defect (bug) (no action required)
Buddybar bp_core_remove_nav_item issue with Undefined index for screen_function
Reported by: | garrett-eclipse | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.4.0 |
Component: | Toolbar & Notifications | Keywords: | needs-patch |
Cc: |
Description
Hello,
I ran into a recurring warning with Buddypress' BuddyBar;
[01-Feb-2016 21:39:56 UTC] PHP Notice: Undefined index: screen_function in /home/ljlee/public_html/wp-content/plugins/buddypress/bp-core/bp-core-buddybar.php on line 536
Looking into it this isolated on this call within bp_core_remove_nav_item;
<?php if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) { // Remove our screen hook if screen function is callable if ( is_callable( $function ) ) { remove_action( 'bp_screens', $function, 3 ); } }
Currently there's no check to determine if the screen_function array key even exists before it's reference.
Looking at the docs (https://codex.buddypress.org/developer/function-examples/core/bp_core_new_nav_item/) the screen_function is optional when using bp_core_new_nav_item which is most likely why it doesn't exist in certain cases.
To leave it optional and avoid the warning would suggest modifying the reference to do an array_key_exists check as follows;
<?php if ( array_key_exists('screen_function', $bp->bp_nav[$parent_id]) && $function = $bp->bp_nav[$parent_id]['screen_function'] ) { // Remove our screen hook if screen function is callable if ( is_callable( $function ) ) { remove_action( 'bp_screens', $function, 3 ); } }
Appreciated,
Cheers
What circumstances lead you to discover this?