Skip to content

Commit

Permalink
Use is_writable() to avoid the silenced PHP warnings from `@fopen()…
Browse files Browse the repository at this point in the history
…`. (#17671)
  • Loading branch information
dd32 authored Nov 14, 2020
1 parent f3af80f commit 415fc43
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,25 @@ function gutenberg_register_vendor_script( $scripts, $handle, $src, $deps = arra
// Determine whether we can write to this file. If not, don't waste
// time doing a network request.
// @codingStandardsIgnoreStart
$f = @fopen( $full_path, 'a' );

$is_writable = is_writable( $full_path );
if ( $is_writable ) {
$f = @fopen( $full_path, 'a' );
if ( ! $f ) {
$is_writable = false;
} else {
fclose( $f );
}
}

// @codingStandardsIgnoreEnd
if ( ! $f ) {
if ( ! $is_writable ) {
// Failed to open the file for writing, probably due to server
// permissions. Enqueue the script directly from the URL instead.
gutenberg_override_script( $scripts, $handle, $src, $deps, $ver, $in_footer );
return;
}
fclose( $f );

$response = wp_remote_get( $src );
if ( wp_remote_retrieve_response_code( $response ) === 200 ) {
$f = fopen( $full_path, 'w' );
Expand Down

0 comments on commit 415fc43

Please sign in to comment.