Skip to content

Instantly share code, notes, and snippets.

@nilovelez
Created January 15, 2026 19:45
Show Gist options
  • Select an option

  • Save nilovelez/b626521279e3ad26c46d12bbb9397f7b to your computer and use it in GitHub Desktop.

Select an option

Save nilovelez/b626521279e3ad26c46d12bbb9397f7b to your computer and use it in GitHub Desktop.
Code to test if a textdomain function is called before the init hook
add_action('init', function(){
define('MACHETE_DEBUG_INIT_PASSED', true);
}, 1);
add_filter( 'gettext_' . 'machete', 'machete_gettext_debug', 10, 2 );
function machete_gettext_debug( $text, $untranslated ) {
if ( defined( 'MACHETE_DEBUG_INIT_PASSED' ) ) {
return $text;
}
error_log( "Textdomain 'machete' was loaded. Stack trace:" );
$debug_backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 10 );
foreach ( $debug_backtrace as $trace ) {
// if file starts with "D:\repos\" or "C:\Users\"
if ( strpos( $trace['file'], 'D:\repos' ) === 0 ) {
error_log( "Trace: " . print_r( $trace, true ) );
break;
}
}
return $text;
}
@nilovelez
Copy link
Author

if ( ! defined( 'WP_DEBUG' ) ) {
define( 'WP_DEBUG', true );
}
define( 'WP_DEBUG_LOG', true );
error_reporting(E_ALL);

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