Show list of loaded php files from plugins

So currently I have the following code and it shows me a list of all the php files loaded from the theme. So how can I edit this to show either all php files or just the plugin ones?


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>';

Then in the footer.php

<pre><?php print_r($GLOBALS['grabber']->grab()); ?></pre>

Solutions Collecting From Web of "Show list of loaded php files from plugins"

In setup, set the plugin folder root:

$this->plugin_root = wp_normalize_path( WP_PLUGIN_DIR );

Then modify filter to check if file is in theme root or plugin root:

return $this->switch && ( strpos($norm, $this->root) === 0 || strpos($norm, $this->plugin_root) === 0 );

or to show all included files, don’t filter any of the results in grab:

return get_included_files();