Make WordPress Core

Opened 9 years ago

Closed 6 years ago

#34183 closed defect (bug) (fixed)

Add context to `doing_it_wrong_trigger_error` filter

Reported by: dd32's profile dd32 Owned by: flixos90's profile flixos90
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: Cc:


At present the doing_it_wrong_trigger_error filter is a boolean on-off switch for _doing_it_wrong()'s trigger_error() call.

The doing_it_wrong_run action is available to catch all of the _doing_it_wrong()s but there's no easy way to disable a single _doing_it_wrong notice.

The following code can be used to conditionally disable it:

add_action( 'doing_it_wrong_run', '_abc_maybe_cancel_notice', 10, 2 );
function _abc_maybe_cancel_notice( $function, $message ) {
	if ( WP_DEBUG && 'specific _doing_it_wrong message' == $message ) {
		add_filter( 'doing_it_wrong_trigger_error', '_abc_cancel_notice' );
function _abc_cancel_notice() {
	remove_filter( 'doing_it_wrong_trigger_error', '_abc_cancel_notice' );
	return false;

It would be far simpler if the same context were passed to both filters.
I'm on the fence here - Either you're interested in the notices, or you're not.. but at the same time, sometimes you're using a library (such as HyperDB) which triggers the notices and you just want silence again..

Any thoughts?

Attachments (2)

34183.diff (1.2 KB) - added by flixos90 9 years ago.
Added the three function arguments to the filter to allow catching specific warnings
34183.2.diff (1.1 KB) - added by flixos90 7 years ago.

Download all attachments as: .zip

Change History (11)

#1 @obenland
9 years ago

I agree, it would provide much more flexibility. Passing just the function name would be a huge improvement already.

9 years ago

Added the three function arguments to the filter to allow catching specific warnings

#2 @flixos90
9 years ago

  • Keywords 2nd-opinion has-patch added; needs-patch removed

In the above patch, I added all the three arguments to the function. It's probably most usable that way, at least we need $function and $message I think. We could remove $version if it is too specific, but I'd say it can be in there.

In addition to that, I'm proposing to do the same change for the deprecated_argument_trigger_error filter. Whenever we agree on which parameters exactly should be added to the filter (whether it's like in the patch above or not), we can simply apply the change to the other filter as well.

#3 @swissspidy
7 years ago

  • Keywords 2nd-opinion removed
  • Milestone changed from Awaiting Review to Future Release

Adding all parameters seems legit to me. @flixos90 Do you want to work on a refresh here?

#4 @flixos90
7 years ago

  • Owner set to flixos90
  • Status changed from new to assigned

@swissspidy Oh I forgot about this one. Sure, will do.

7 years ago

#5 @flixos90
7 years ago

34183.2.diff is the updated patch (docs adjustments only).

#6 @flixos90
6 years ago

  • Milestone changed from Future Release to 5.0

#7 @flixos90
6 years ago

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

In 43587:

General: Provide context parameters to doing_it_wrong_trigger_error filter.

$function, $message, and $version have historically been passed to the doing_it_wrong_run action. It makes sense to pass those to the filter as well, so that one can conditionally determine the filter value to return.

Fixes #34183.

#8 @flixos90
6 years ago

  • Milestone changed from 5.0 to 5.1
  • Resolution fixed deleted
  • Status changed from closed to reopened

Version numbers need to be changed to 5.1.0.

#9 @pento
6 years ago

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

In 44590:

Docs: Update the @since version for the doing_it_wrong_trigger_error filter.

Fixes #34183.

Note: See TracTickets for help on using tickets.