0

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.

4

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-adl May 21 '14 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. – kaiser May 21 '14 at 16:49
2

I am not sure there is a generic answer to this question but my advice would be to:

  1. Enable debugging
  2. Learn to drive grep
  3. 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());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.