Make WordPress Core

Opened 11 years ago

Closed 8 years ago

#34183 closed defect (bug) (fixed)

Add context to `doing_it_wrong_trigger_error` filter

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

Description

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 11 years ago.
Added the three function arguments to the filter to allow catching specific warnings
34183.2.diff (1.1 KB ) - added by flixos90 10 years ago.

Download all attachments as: .zip

Change History (11)

#1 @obenland
11 years ago

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

@flixos90
11 years ago

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

#2 @flixos90
11 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
10 years ago

  • Keywords 2nd-opinion removed
  • Milestone Awaiting ReviewFuture Release

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

#4 @flixos90
10 years ago

  • Owner set to flixos90
  • Status newassigned

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

@flixos90
10 years ago

#5 @flixos90
10 years ago

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

#6 @flixos90
8 years ago

  • Milestone Future Release5.0

#7 @flixos90
8 years ago

  • Resolutionfixed
  • Status assignedclosed

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
8 years ago

  • Milestone 5.05.1
  • Resolution fixed
  • Status closedreopened

Version numbers need to be changed to 5.1.0.

#9 @pento
8 years ago

  • Resolutionfixed
  • Status reopenedclosed

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.