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 );
}
-
Wasn't my question but thanks, completely forgot about this function.– aj-adlMay 21, 2014 at 14:48
-
Well, it was "to find the php file that is executing on a given page" and that is what the answer provides. I'm not completely sure how to answer your question in any other way.– kaiserMay 21, 2014 at 16:49
I am not sure there is a generic answer to this question but my advice would be to:
- Enable debugging
- Learn to drive grep
- Run
debug_backtrace()
for a more detailed history of what has occurred up to some point in a page load or function call--var_dump(debug_backtrace());