Skip to:
Content

BuddyPress.org

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#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

Change History (5)

#1 @DJPaul
6 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 2.6

What circumstances lead you to discover this?

This ticket was mentioned in Slack in #buddypress by djpaul. View the logs.


6 years ago

#3 @DJPaul
6 years ago

  • Milestone changed from 2.6 to Future Release

#4 @boonebgorges
6 years ago

  • Milestone Future Release deleted
  • Resolution set to invalid
  • Status changed from new to closed

This should no longer be an issue. After [10745], the nav functions work quite differently.

#5 @DJPaul
5 years ago

  • Component changed from General - Toolbar/BuddyBar to Toolbar & Notifications
Note: See TracTickets for help on using tickets.