[buddypress-trac] [BuddyPress Trac] #6861: Buddybar bp_core_remove_nav_item issue with Undefined index for screen_function

buddypress-trac noreply at wordpress.org
Mon Feb 1 21:51:20 UTC 2016


#6861: Buddybar bp_core_remove_nav_item issue with Undefined index for
screen_function
----------------------------------------+-----------------------------
 Reporter:  garrett-eclipse             |      Owner:
     Type:  defect (bug)                |     Status:  new
 Priority:  normal                      |  Milestone:  Awaiting Review
Component:  General - Toolbar/BuddyBar  |    Version:  2.4.0
 Severity:  normal                      |   Keywords:
----------------------------------------+-----------------------------
 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
 <?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
 <?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

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6861>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list