因此,目前我有以下代码,它显示了从主题加载的所有php文件的列表。那么,我如何编辑它以显示所有php文件或仅显示插件文件呢?
功能。php
class IncludedPartGrabber
{
private $main;
private $root;
private $switch = false;
public function setup($template)
{
$this->root = wp_normalize_path(get_theme_root()); // theme folder
$this->main = wp_normalize_path($template); // main template
return $template;
}
public function grab()
{
return array_filter(get_included_files(), array($this, \'filter\') );
}
private function filter($file)
{
$norm = wp_normalize_path($file);
if ($norm === $this->main)
$this->switch = TRUE; // after main template all files are good to be included
return $this->switch && strpos($norm, $this->root) === 0; // true if file is in theme dir
}
}
$grabber = new IncludedPartGrabber;
add_action(\'template_include\', array($grabber, \'setup\'));
add_action(\'wp_footer\', function() use($grabber) {
echo \'<pre>\';
print_r($grabber->grab()); // see your footer :)
echo \'</pre>\';
});
然后在页脚中。php<pre><?php print_r($GLOBALS[\'grabber\']->grab()); ?></pre>