#8005 closed defect (bug) (fixed)
PHP warning when getting BuddyPress page title part
Reported by: | Venutius | Owned by: | espellcaste |
---|---|---|---|
Milestone: | 5.0.0 | Priority: | normal |
Severity: | normal | Version: | 3.0.0 |
Component: | Navigation | Keywords: | good-first-bug has-patch |
Cc: |
Description
I've been getting the following error in my logs:
reset() expects parameter 1 to be array, boolean given
Type: PHP Warning
Line: 3038
File: /wp-content/plugins/buddypress/bp-core/bp-core-template.php
Line 3038 has:
if ( ! empty( $bp->members->nav ) ) { $primary_nav_item = $bp->members->nav->get_primary( array( 'slug' => $component_id ), false ); $primary_nav_item = reset( $primary_nav_item ); }
I had a play and one way of dealing with the issue could be:
if ( ! empty( $bp->members->nav ) ) { $primary_nav_item = $bp->members->nav->get_primary( array( 'slug' => $component_id ), false ); $primary_nav_item = reset( $arr = array($primary_nav_item) ); }
Attachments (1)
Change History (13)
#2
@
6 years ago
My latest fix is to wrap a check to see if the variable is an array:
if ( ! empty( $bp->members->nav ) ) { $primary_nav_item = $bp->members->nav->get_primary( array( 'slug' => $component_id ), false ); if ( is_array( $primary_nav_item ) ) { $primary_nav_item = reset( $primary_nav_item ); } }
#3
@
6 years ago
- Component changed from Core to Navigation
- Keywords good-first-bug added
- Milestone changed from Awaiting Review to Awaiting Contributions
get_primary
looks like it can return boolean false. We just need to handle that case in the code you mentioned. Good find!
#4
@
6 years ago
Hello, I've been getting the same error with my project so I added a check to make sure $primary_nav_item is not false which seems to be working for me. I replaced
$primary_nav_item = $bp->members->nav->get_primary( array( 'slug' => $component_id ), false ); $primary_nav_item = reset( $primary_nav_item );
with
$primary_nav_item = $bp->members->nav->get_primary( array( 'slug' => $component_id ), false ); $primary_nav_item = $primary_nav_item ? reset( $primary_nav_item ) : $primary_nav_item;
My first time contributing here so if there is a better place to put fixes i'll be happy to repost there.
#5
@
6 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Contributions to 5.0.0
- Owner set to espellcaste
- Status changed from new to accepted
This is something we can do at the next milestone.
#6
@
6 years ago
- Keywords has-patch added; needs-patch removed
Suggested patch added! The approach seems ok to me.
This ticket was mentioned in Slack in #buddypress by espellcaste. View the logs.
6 years ago
#8
@
6 years ago
Hi @espellcaste
I think I’d do something like this :
$primary_nav_item = (array) $bp->members->nav->get_primary( array( 'slug' => $component_id ), false ); $primary_nav_item = reset( $primary_nav_item );
#9
@
6 years ago
- Summary changed from Reset() expects parameter 1 to be and array, boolean given - buddypress/bp-core/bp-core-template.php 3038 to PHP warning when getting BuddyPress page title part
#11
@
5 years ago
This debug warning has recently started clogging up some log files on BuddyPress.org.
I'm going to merge this change to plugins.svn.wordpress.org/buddypress/trunk to silence them.
That fix was not good, now getting the following error:
[21-Nov-2018 21:00:40 UTC] PHP Notice: Only variables should be passed by reference in /wp-content/plugins/buddypress/bp-core/bp-core-template.php on line 3039.
I'm not able to replicate this as yet, It's a live site and this error just seems to come in randomly. The last time I got it, I had installed a new plugin BWS Error Log, disabled another WP Error Log and saved the new settings of the BWS plugin, it went to view the error log and the error appeared so I'm not sure it's me that's triggering it.