Using WordPress ‘doing_it_wrong_trigger_error’ PHP filter

The doing_it_wrong_trigger_error WordPress PHP filter allows you to control whether or not to trigger an error for _doing_it_wrong() calls.

Usage

add_filter( 'doing_it_wrong_trigger_error', 'your_custom_function', 10, 4 );

function your_custom_function( $trigger, $function_name, $message, $version ) {
    // Your custom code here

    return $trigger;
}

Parameters

  • $trigger (bool): Whether to trigger the error for _doing_it_wrong() calls. Default is true.
  • $function_name (string): The function that was called.
  • $message (string): A message explaining what has been done incorrectly.
  • $version (string): The version of WordPress where the message was added.

More information

See WordPress Developer Resources: doing_it_wrong_trigger_error

Examples

Disable error triggering for a specific function

Disable error triggering when calling a specific deprecated function:

add_filter( 'doing_it_wrong_trigger_error', 'disable_specific_error_trigger', 10, 4 );

function disable_specific_error_trigger( $trigger, $function_name, $message, $version ) {
    if ( 'deprecated_function' === $function_name ) {
        return false;
    }
    return $trigger;
}

Disable error triggering for a specific message

Disable error triggering when a specific error message is encountered:

add_filter( 'doing_it_wrong_trigger_error', 'disable_specific_message_error_trigger', 10, 4 );

function disable_specific_message_error_trigger( $trigger, $function_name, $message, $version ) {
    if ( 'This is a specific error message.' === $message ) {
        return false;
    }
    return $trigger;
}

Disable error triggering for a specific WordPress version

Disable error triggering for _doing_it_wrong() calls added in a specific WordPress version:

add_filter( 'doing_it_wrong_trigger_error', 'disable_specific_version_error_trigger', 10, 4 );

function disable_specific_version_error_trigger( $trigger, $function_name, $message, $version ) {
    if ( '5.6' === $version ) {
        return false;
    }
    return $trigger;
}

Enable error triggering only in development environment

Enable error triggering for _doing_it_wrong() calls only in a development environment:

add_filter( 'doing_it_wrong_trigger_error', 'enable_error_trigger_dev_environment', 10, 4 );

function enable_error_trigger_dev_environment( $trigger, $function_name, $message, $version ) {
    if ( defined( 'WP_ENV' ) && 'development' === WP_ENV ) {
        return true;
    }
    return false;
}

Log errors instead of triggering

Log errors for _doing_it_wrong() calls instead of triggering an error:

add_filter( 'doing_it_wrong_trigger_error', 'log_errors_instead_of_trigger', 10, 4 );

function log_errors_instead_of_trigger( $trigger, $function_name, $message, $version ) {
    error_log( "Doing it wrong: {$function_name} - {$message} (since WordPress {$version})" );
    return false;
}