最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

child theme - Getting a list of the PHP files included to generate a page

programmeradmin2浏览0评论

Some commercial themes have become a real mess: the header may be created by the files in the theme folder or by child theme or maybe from a legacy folder which is located inside a legacy plugin.

In those case how can I find which is the real piece of code which is executed?

Some commercial themes have become a real mess: the header may be created by the files in the theme folder or by child theme or maybe from a legacy folder which is located inside a legacy plugin.

In those case how can I find which is the real piece of code which is executed?

Share Improve this question asked Mar 23, 2020 at 20:02 ReviousRevious 3233 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论