WordPress.org

Ready to get started?Download WordPress

Forums

Theme-Check
file_get_contents warning with .git directories (8 posts)

  1. David Hancock
    Member
    Posted 2 years ago #

    I get the following warning about a hundred times down the page every time I run a theme check:

    Warning: file_get_contents(D:\www\webroot\work\wordpress.dev/wp-content/themes/theme\.git): failed to open stream: Permission denied in D:\www\webroot\work\wordpress.dev\wp-content\plugins\theme-check\main.php on line 29

    I understand this to be file permissions that Windows has set on the .git directories. I was just wondering if you would add a simple fix to the main.php file?

    I propose the following change on line 29 of main.php:

    $other[$filename] = @file_get_contents( $filename );

    instead of:

    $other[$filename] = file_get_contents( $filename );

    to suppress the warnings. Of course that is a simple fix, feel free to do your own proper exception checking with a try/catch routine.

    Would make me super happy to not have to see these warnings again :)

    Thanks.

    http://wordpress.org/extend/plugins/theme-check/

  2. Simon Prosser
    Theme Review Admin
    Plugin Author

    Posted 2 years ago #

    Suppressing errors with @ goes against everything the plugin is designed to do ;)

  3. David Hancock
    Member
    Posted 2 years ago #

    Yeah I understand that, I felt dirty just typing it lol. It's just when you get a page like this.

    It starts getting a little annoying having to scroll a bajillion lines to get to the good stuff. I use git in my workflow it'd be nice if it didn't throw up all over the page when it comes across a directory it can't access.

    Thanks ;)

  4. Simon Prosser
    Theme Review Admin
    Plugin Author

    Posted 2 years ago #

    I dont know much about windows im afraid, what if you add the .git dir to the group apache is running on?

  5. David Hancock
    Member
    Posted 2 years ago #

    My bad, I've figured out that the problem is nothing to do with permissions.

    The problem is actually caused because on line 29 of main.php the script tries to access a directory (such as .git) using file_get_contents() and as it's not a file, a warning is thrown.

    I propose the following change:

    if ( is_dir($filename) ) {
    	$other[$filename] = NULL;
    } else {
    	$other[$filename] = file_get_contents( $filename );
    }

    instead of:

    $other[$filename] = file_get_contents( $filename );

    That way the warnings will no longer occur but directories like .git will still be caught by the following checks such as WARNING: .git .gitignore .ds_store Hidden Files or Folders found..

  6. Simon Prosser
    Theme Review Admin
    Plugin Author

    Posted 2 years ago #

    $other[$filename] = ( ! is_dir($filename) ) ? file_get_contents( $filename ) : NULL;

    Try that...

  7. David Hancock
    Member
    Posted 2 years ago #

    Yeah either ternary operator or basic if condition will do, could you add it to the plugin in the next update please? :)

  8. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 2 years ago #

    Fixed in trunk.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic