[theme-reviewers] fopen, fgets and freads errors

Darren Slatten darrenslatten at gmail.com
Sat Jul 16 21:23:08 UTC 2011


I'm guessing 3.1.x, since wp-includes/functions.php has an fopen() on line
4284 (whereas WP 3.2 has only a line break).

The WP function calling fopen() is get_file_data(). Does your theme call
this function directly?

Here's the code:

/**
 * Retrieve metadata from a file.
 *
 * Searches for metadata in the first 8kiB of a file, such as a plugin or
theme.
 * Each piece of metadata must be on its own line. Fields can not span
multple
 * lines, the value will get cut at the end of the first line.
 *
 * If the file data is not within that first 8kiB, then the author should
correct
 * their plugin file and move the data headers to the top.
 *
 * @see http://codex.wordpress.org/File_Header
 *
 * @since 2.9.0
 * @param string $file Path to the file
 * @param array $default_headers List of headers, in the format
array('HeaderKey' => 'Header Name')
 * @param string $context If specified adds filter hook
"extra_{$context}_headers"
 */
function get_file_data( $file, $default_headers, $context = '' ) {
    // We don't need to write to the file, so just open for reading.
    $fp = fopen( $file, 'r' );

    // Pull only the first 8kiB of the file in.
    $file_data = fread( $fp, 8192 );

    // PHP will close file handle, but we are good citizens.
    fclose( $fp );

    if ( $context != '' ) {
        $extra_headers = apply_filters( "extra_{$context}_headers", array()
);

        $extra_headers = array_flip( $extra_headers );
        foreach( $extra_headers as $key=>$value ) {
            $extra_headers[$key] = $key;
        }
        $all_headers = array_merge( $extra_headers, (array) $default_headers
);
    } else {
        $all_headers = $default_headers;
    }

    foreach ( $all_headers as $field => $regex ) {
        preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) .
':(.*)$/mi', $file_data, ${$field});
        if ( !empty( ${$field} ) )
            ${$field} = _cleanup_header_comment( ${$field}[1] );
        else
            ${$field} = '';
    }

    $file_data = compact( array_keys( $all_headers ) );

    return $file_data;
}


On Sat, Jul 16, 2011 at 4:14 PM, Darren Slatten <darrenslatten at gmail.com>wrote:

> What version of WP are they using?
>
>
>
>
> On Sat, Jul 16, 2011 at 3:49 PM, Tom Matteson <perspectivevision at gmail.com
> > wrote:
>
>> Darren ... the first one switched to using a different theme because they
>> could not resolve this. However, his WordPress installation was in a
>> subdirectory (see the errors below **with the user's domain and subdirectory
>> edited**) I do know the first user's site was hosted by surpasshosting dot
>> com and per their security settings they would not enable allow_url_fopen
>> ... other than that I am unaware of their php.ini settings
>>
>>
>> Warning:
>> fopen(
>> http://primarydomain.com/sub-directory/wp-content/themes/wordsmith-anvil/style.css
>> )
>> [function.fopen]: failed to open stream: no suitable wrapper could be
>> found in
>> /home/primaryd/public_html/sub-directory/wp-includes/functions.php on line
>> 4284
>>
>> Warning: fread(): supplied argument is not a valid stream resource in
>> /home/primaryd/public_html/sub-directory/wp-includes/functions.php on line
>> 4287
>>
>> Warning: fclose(): supplied argument is not a valid stream resource in
>> /home/primaryd/public_html/sub-directory/wp-includes/functions.php on line
>> 4290"
>>
>> One thing I had read somewhere is that using absolute paths (direct links)
>> as opposed to relative paths could cause these errors to appear. In the
>> Wordsmith Anvil theme the only direct links are:
>>
>>
>>    - Developer and WordPress.org credit links (common with most all
>>    themes)
>>    - Link to FAQ and Theme Home page in Admin Theme Options Page (fairly
>>    common)
>>    - Various license links (common with all themes)
>>    - Direct links assigned to Social Media variables for Twitter, FB,
>>    Flickr, YouTube ...[eg $flickrurl = 'http://www.flickr.com/photos/';]
>>    (common to themes with these options)
>>
>>
>> The second user's site is hosted with secureserver.net (there apparently
>> have been some errors with that host server and WordPress in the past see:
>> http://wordpress.org/support/topic/defaultsecureservernet)
>>
>> The errors on the second user's site were the same. The user has currently
>> deactivated the theme and has an under construction page displayed. I have
>> emailed her to ask that she re-activate to get addtional feedback. I imagine
>> it will be re-activated at some point today. For reference, the url to that
>> site is: http://homesweethomerescue.org/
>>
>> As I discover additional details I will provide them.
>>
>> *Best Regards
>> Tom Matteson*
>>
>> ---------------------------------------------------------------------------------------
>>
>>
>>
>> On Sat, Jul 16, 2011 at 12:37 PM, Darren Slatten <darrenslatten at gmail.com
>> > wrote:
>>
>>> This would be a lot easier to diagnose if you could provide information
>>> like:
>>>
>>>    - hosting environment
>>>    - php.ini settings
>>>    - full text of error messages
>>>    - what types of pages/requests generate the errors
>>>
>>> If the errors are only showing in 2:10,000 installations, then there's a
>>> good chance that those 2 users have an unusual server configuration or
>>> file/URL structure. Could be caused by something like trying to open/include
>>> a file or image that isn't in the typical location, relative to your theme.
>>>
>>>
>>> On Sat, Jul 16, 2011 at 3:47 AM, Tom Matteson <
>>> perspectivevision at gmail.com> wrote:
>>>
>>>> Greetings All Concerned ...
>>>>
>>>> I have a theme on the Repository--Wordsmith Anvil--which does not use
>>>> fopen, fgets or freads functions. It has been downloaded close to 10,000
>>>> times and I have just received a comment from the second user who is
>>>> receiving errors referencing "failed to open stream: no suitable wrapper
>>>> could be found in ...", or "supplied argument is not a valid stream resource
>>>> in ..." with this theme. The errors all point to various lines of
>>>> wp-includes/functions.php, except one file reference to the theme default
>>>> css file, style.css. The first user told me they disabled all plugins. Also,
>>>> they performed a fresh WordPress install and did not see the errors using
>>>> TwentyTen and a number of other themes. The second user who contacted me
>>>> yesterday told me they do not have any plugins installed and when they
>>>> activated the Wordsmith Anvil theme, these errors display at the top of the
>>>> page.
>>>>
>>>> Knowing that these functions are not used in this theme; yet the errors
>>>> seem to be theme specific, and each user experiencing these errors have
>>>> WordPress installations hosted on entirely different servers I am more
>>>> uncertain as to why these errors are being displayed. I was hoping someone
>>>> on this list may have experienced this with another theme and could shed
>>>> some light on why these errors would occur when the theme does not use those
>>>> functions. In fact, if these functions had been used in my theme, I am
>>>> fairly certain it would not have been approved anyway.
>>>>
>>>> Otto, Nathan, Chip, Justin, Emil, Cais, etc ... any thoughts or feedback
>>>> on this. I would like to address this so that users in the future do not see
>>>> these errors.
>>>>
>>>> *Best Regards
>>>> Tom Matteson*
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> theme-reviewers mailing list
>>>> theme-reviewers at lists.wordpress.org
>>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>>
>>>>
>>>
>>>
>>> --
>>> Darren Slatten
>>>
>>>
>>> _______________________________________________
>>> theme-reviewers mailing list
>>> theme-reviewers at lists.wordpress.org
>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>
>>>
>>
>> _______________________________________________
>> theme-reviewers mailing list
>> theme-reviewers at lists.wordpress.org
>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>
>>
>
>
> --
> Darren Slatten
>
>


-- 
Darren Slatten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110716/417671a5/attachment.htm>


More information about the theme-reviewers mailing list