Skip to:
Content

BuddyPress.org

Opened 12 years ago

Closed 12 years ago

Last modified 9 years ago

#4794 closed defect (bug) (fixed)

Calling bp_core_new_nav_item() without screen_function parameter generates PHP warning

Reported by: doublesharp's profile doublesharp Owned by: boonebgorges's profile boonebgorges
Milestone: 1.8 Priority: normal
Severity: normal Version: 1.2
Component: Core Keywords: has-patch needs-testing
Cc:

Description

Adding a new navigation item via bp_core_new_nav_item() without passing screen_function as a parameter (if it uses a default subnav screen for example) will generate the following warning when do_action('bp_screens'); is called:

[29-Jan-2013 23:21:55 UTC] PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /Workspaces/PHP/wordpress/wp-includes/plugin.php on line 406

Changing the default value for this parameter in bp-core/bp-core-buddybar.php from false to '__return_false' uses a valid callback and does not generate the warning.

The same fix can be applied to bp_core_new_subnav_item(), bp_core_new_nav_item(), and bp_core_new_nav_default() asin the attached patch.

Attachments (2)

bp-core-buddybar.php.patch (1.6 KB) - added by doublesharp 12 years ago.
use 'return_false' instead of false for default screen actions
4794.02.patch (3.3 KB) - added by r-a-y 12 years ago.
Switch out is_object() for screen function checks and use is_callable()

Download all attachments as: .zip

Change History (12)

@doublesharp
12 years ago

use 'return_false' instead of false for default screen actions

#1 @r-a-y
12 years ago

  • Milestone changed from Awaiting Review to 1.7
  • Version changed from 1.6 to 1.2

Sounds valid. Moving to 1.7 milestone for testing.

#2 @DJPaul
12 years ago

  • Keywords needs-patch added; has-patch dev-feedback needs-testing removed

The patch works well for me and I'm tempted to commit it, but I think doing this properly would involve method_exists and function_exists checks before make the add_action calls.

@r-a-y
12 years ago

Switch out is_object() for screen function checks and use is_callable()

#3 @r-a-y
12 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

02.patch is another approach to this issue based on Paul's feedback.

I like this better as:

  • We don't have to explicitly set the default screen function to __return_false()
  • We can check the existence of the screen function with is_callable() for both methods and functions.

Tested lightly with default BP components and various plugins like BP Docs, BP Followers, bbPress, as well as with a new nav item with no screen function - no errors.

Feel free to commit doublesharp's patch and punt my one to 1.8 if not enough time to test.

Last edited 12 years ago by r-a-y (previous) (diff)

#4 @DJPaul
12 years ago

  • Keywords needs-patch added; has-patch needs-testing removed

Thanks for the patch r-a-y, but it's missing most of the is_object logic that's in the current version.

#5 @DJPaul
12 years ago

  • Milestone changed from 1.7 to Future Release

#6 @r-a-y
12 years ago

Thanks for the patch r-a-y, but it's missing most of the is_object logic that's in the current version.

Unless I'm mistaken, is_callable() already checks for objects or class methods.

See the example on the PHP doc page:
http://www.php.net/manual/en/function.is-callable.php

#7 @r-a-y
12 years ago

  • Milestone changed from Future Release to 1.8

#8 @boonebgorges
12 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

#9 @boonebgorges
12 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 7171:

Use is_callable() to validate screen_function callbacks before hooking in bp-core-buddybar.php

We were previously using is_object() and other custom verification techniques
to hook screen functions in bp_core_new_nav_item() and elsewhere. These
techniques are limited in that they allow certain sorts of uncallable strings
to pass through. We also should not be reinventing the wheel.

Fixes #4794

Props r-a-y

#10 @DJPaul
9 years ago

  • Component changed from Tools - Warnings/Notices to Core
Note: See TracTickets for help on using tickets.