I’d like to debug some WordPress functionality, but to do so I need to know where to find the php file that is executing on a given page. How can I set up something that will tell me what php files (or functions, objects) are being called to generate a given page? I’m using a ridiculous amount of plugins, and I have a complicated theme structure, so it’s not really practical to insert debug messages into every single php file I have, like the answer to this question suggests.
2 Answers
There’s a native PHP function get_included_files()
for that.
Simply attach it to an action on the hook from where you want to know it. The first one is muplugins_loaded
and the last accessible on is shutdown
.
add_action( 'muplugins_loaded', function()
{
$files = get_included_files();
foreach ( $files as $f )
echo $f.'<br>';
// or...
var_dump( $files );
}