Skip to:
Content

BuddyPress.org

Opened 8 years ago

Closed 8 years ago

#4533 closed defect (bug) (fixed)

Avoid "Notice: Undefined index" in bp_core_remove_nav_item

Reported by: wpdennis Owned by:
Milestone: 1.7 Priority: normal
Severity: trivial Version:
Component: Core Keywords: has-patch
Cc: jkudish

Description

I added an action to "bp_setup_nav" to remove nav items like:

bp_core_remove_nav_item('blogs');
bp_core_remove_nav_item('forums');

This can result in "Notice: Undefined index" in line 389
http://buddypress.trac.wordpress.org/browser/trunk/bp-core/bp-core-buddybar.php#L389.

Maybe we could avoid this in bp_core_remove_nav_item by adding:

if (!isset($bp->bp_nav[$parent_id]))
    return;

just before this if statement:

if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) {

Attachments (1)

4533.diff (970 bytes) - added by jkudish 8 years ago.
return false if the parent item doesn't exist in bp_core_remove_nav_item() and adjust phpdoc for the function

Download all attachments as: .zip

Change History (7)

#1 follow-up: @boonebgorges
8 years ago

  • Milestone changed from Awaiting Review to 1.7
  • Resolution set to fixed
  • Status changed from new to closed

Great suggestion. We should actually return false (or maybe an error) so that plugin authors can get an appropriate response.

#2 @boonebgorges
8 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#3 in reply to: ↑ 1 @wpdennis
8 years ago

Replying to boonebgorges:

Great suggestion. We should actually return false (or maybe an error) so that plugin authors can get an appropriate response.

Thanks for your feedback.

Returning false would be even better than returning void. I would prefer false over an error, because it seems to be more consistent to me (bp_core_new_nav_item, bp_core_sort_nav_items & Co).

#4 @DJPaul
8 years ago

  • Keywords needs-patch added; dev-feedback removed

@jkudish
8 years ago

return false if the parent item doesn't exist in bp_core_remove_nav_item() and adjust phpdoc for the function

#5 @jkudish
8 years ago

  • Cc jkudish added
  • Keywords has-patch added; needs-patch removed

#6 @boonebgorges
8 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [6412]) Fixes PHP warning when attempting to remove nav item that doesn't exist

Fixes #4533

Props wpdennis, jkudish

Note: See TracTickets for help on using tickets.