Exclude node_modules and vendor from theme check plugin

While I created countless themes, I’m currently creating my first theme for the WordPress.org theme repo. To ensure a smooth reviewing process, I’m using the plugin Theme Check as mentioned in the theme review handbook.

After adding both composer and npm to my theme, I ended up with an Fatal error: Allowed memory size of 536870912 bytes exhausted error. Investigating this issue brought me to:

I found the solution to my specific issue in:

Thus, I went ahead, opened the main.php in the root folder of the plugin and replaced

foreach( $files as $key => $filename ) {
  if ( ( basename( $filename ) == '..' )
    || ( basename( $filename ) == '.' )
  ){
    continue;
  }

  if ( substr( $filename, -4 ) == '.php' && ! is_dir( $filename ) ) {
    $php[$filename] = file_get_contents( $filename );
    $php[$filename] = tc_strip_comments( $php[$filename] );
  }
  else if ( substr( $filename, -4 ) == '.css' && ! is_dir( $filename ) ) {
    $css[$filename] = file_get_contents( $filename );
  }
  else {
    $other[$filename] = ( ! is_dir($filename) ) ? file_get_contents( $filename ) : '';
  }
}

with

foreach( $files as $key => $filename ) {
  if ( ( basename( $filename ) == '..' )
    || ( basename( $filename ) == '.' )
    || preg_match( '/node_modules\/.+/i', $filename )
    || preg_match( '/vendor\/.+/i', $filename )
  ){
    continue;
  }

  if ( substr( $filename, -4 ) == '.php' && ! is_dir( $filename ) ) {
    $php[$filename] = file_get_contents( $filename );
    $php[$filename] = tc_strip_comments( $php[$filename] );
  }
  else if ( substr( $filename, -4 ) == '.css' && ! is_dir( $filename ) ) {
    $css[$filename] = file_get_contents( $filename );
  }
  else {
    $other[$filename] = ( ! is_dir($filename) ) ? file_get_contents( $filename ) : '';
  }
}

While this might not be the best solution to solve this issue, it allows me to analyse my theme.

Leave a Reply

Your email address will not be published. Required fields are marked *