Skip to content

Instantly share code, notes, and snippets.

@afragen
Last active March 18, 2025 20:20
Show Gist options
  • Save afragen/986ba6046ebea963074283a77cae07fc to your computer and use it in GitHub Desktop.
Save afragen/986ba6046ebea963074283a77cae07fc to your computer and use it in GitHub Desktop.
Place in mu-plugins folder
<?php
/**
* Quiet specific trigger warnings.
*
* @package Quiet_Trigger_Errors
*
* Plugin Name: Quiet Trigger Errors
* Plugin URI: https://gist.github.com/afragen/986ba6046ebea963074283a77cae07fc
* Description: Quiet the trigger warnings to the error log.
* Version: 0.4.2
* Author: Andy Fragen
* License: MIT
* Requires at least: 6.7
* Requires PHP: 8.0
* Gist Plugin URI: https://gist.github.com/afragen/986ba6046ebea963074283a77cae07fc
*/
add_filter(
'doing_it_wrong_trigger_error',
function ($trigger, $function_name) {
$func_arr = ['_load_textdomain_just_in_time'];
if (in_array($function_name, $func_arr, true)) {
$trigger = false;
}
return $trigger;
},
10,
2
);
@ju1ius
Copy link

ju1ius commented Jan 30, 2025

Your remove_action call does nothing since QueryMonitor is not loaded at that point. Also, the action callback should be an instance method, not a class method.

Here's what worked for me:

add_action('plugin_loaded', function(string $plugin) {
    if (!str_ends_with($plugin, '/query-monitor/query-monitor.php')) {
        return;
    }
    $collector = QM_Collectors::get('doing_it_wrong');
    remove_action('doing_it_wrong', [$collector, 'action_doing_it_wrong_run']);
    remove_filter('doing_it_wrong_trigger_error', [$collector, 'maybe_prevent_error'], 999);
}, 10, 1);

@afragen
Copy link
Author

afragen commented Feb 4, 2025

QM recently updated to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment