Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed coding standards for PR 680 #977

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions Cache_File_Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ function set( $key, $var, $expire = 0, $group = '' ) {
@fputs( $fp, $var['content'] );
@fclose( $fp );

if ( $this->_locking )
$chmod = 0644;
if ( defined( 'FS_CHMOD_FILE' ) ) {
$chmod = FS_CHMOD_FILE;
}

@chmod( $tmppath, $chmod );

if ( $this->_locking ) {
@flock( $fp, LOCK_UN );
}

// some hostings create files with restrictive permissions
// not allowing apache to read it later
Expand Down Expand Up @@ -134,9 +142,17 @@ function set( $key, $var, $expire = 0, $group = '' ) {
}
}

if ( !empty($rules) ) {
@file_put_contents( dirname( $path ) .
DIRECTORY_SEPARATOR . '.htaccess', $rules );
if ( ! empty( $rules ) ) {
$htaccess_path = dirname( $path ) . DIRECTORY_SEPARATOR . '.htaccess';

@file_put_contents( $htaccess_path, $rules );

$chmod = 0644;
if ( defined( 'FS_CHMOD_FILE' ) ) {
$chmod = FS_CHMOD_FILE;
}

@chmod( $htaccess_path, $chmod );
}
}

Expand Down
6 changes: 6 additions & 0 deletions Util_Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ static public function add_rules( $exs, $path, $rules, $start, $end, $order,
return;
}
}

$chmod = 0644;
if ( defined( 'FS_CHMOD_FILE' ) ) {
$chmod = FS_CHMOD_FILE;
}
@chmod( $path, $chmod );
}

Util_Rule::after_rules_modified();
Expand Down
12 changes: 10 additions & 2 deletions Util_WpFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ public static function ajax_check_credentials( $extra = null ) {
* @return void
*/
static public function write_to_file( $filename, $content ) {
if ( @file_put_contents( $filename, $content ) )
$chmod = 0644;

if ( defined( 'FS_CHMOD_FILE' ) ) {
$chmod = FS_CHMOD_FILE;
}

if ( @file_put_contents( $filename, $content ) ) {
@chmod( $filename, $chmod );
return;
}

try {
self::request_filesystem_credentials();
Expand All @@ -73,7 +81,7 @@ static public function write_to_file( $filename, $content ) {
}

global $wp_filesystem;
if ( !$wp_filesystem->put_contents( $filename, $content ) ) {
if ( ! $wp_filesystem->put_contents( $filename, $content, $chmod ) ) {
throw new Util_WpFile_FilesystemWriteException(
'FTP credentials don\'t allow to write to file <strong>' .
$filename . '</strong>', self::get_filesystem_credentials_form(),
Expand Down