Getting a list of the PHP files included to generate a page

Due to said complexity, it’s a pretty generic question without a specific answer. But here are some ideas based on what I do to grok through other people’s code.

Forward/Back-tracing

I do a lot of forward tracing and back tracing through code. If you have an IDE (or something like Notepad++), you can do a “search all” through the entire directory to find “clues” as to what you’re looking for.

For example, if you’re trying to find where something comes from, start by looking at specific output you can target in a search – some text or HTML that you can key off of. Once you find where it’s generated, you can back trace through the functions that are generated and look for various includes.

Breakpoints and debug code

Sometimes, if you’re really not sure, it may be necessary to create a breakpoint or some debugging output to see if you’re even in the right place, execution-wise.

If I’m not sure I’m even in the right place, I might drop in something like this:

echo 'You are here'; exit();

If it’s a production site, that may not be appropriate, but you can do related things like:

echo '<!-- you are here... -->';

That gives you an HTML comment in the generated output.

Or, use the log file:

error_log( 'this point was hit.' );

If you’re logging, make sure you have debugging and debug logging turned on in your wp-config.php file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );

PHP

PHP has a function get_included_files() that will display all included files. Depending on how things are constructed in your theme, this may or may not work, but it might help so I’m including it as a possible suggestion:

$included_files = get_included_files();

foreach ($included_files as $filename) {
    echo "$filename\n";
}

As I said in the beginning, this isn’t a specific “do this and it is guaranteed to solve your problem” kind of answer. Just some suggestions and ideas that may help you get to what you need. Hope it helps.