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

fix Fatal Errors: don't assume set_ini() exists #7352

Open
wants to merge 14 commits into
base: trunk
Choose a base branch
from
Open
8 changes: 6 additions & 2 deletions src/wp-admin/includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,9 @@
// Set correct file permissions.
$stat = stat( dirname( $new_file ) );
$perms = $stat['mode'] & 0000666;
chmod( $new_file, $perms );
if( function_exists('chmod') ) {

Check failure on line 1043 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Space after opening control structure is required

Check failure on line 1043 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

No space before opening parenthesis is prohibited

Check failure on line 1043 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 space after IF keyword; 0 found

Check failure on line 1043 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 1043 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 spaces before closing parenthesis; 0 found
chmod( $new_file, $perms );
}

// Compute the URL.
$url = $uploads['url'] . "/$filename";
Expand Down Expand Up @@ -2019,7 +2021,9 @@
if ( 'f' === $fileinfo['type'] ) {
if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) {
// If copy failed, chmod file to 0644 and try again.
$wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
if( function_exists('chmod') ) {

Check failure on line 2024 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Space after opening control structure is required

Check failure on line 2024 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

No space before opening parenthesis is prohibited

Check failure on line 2024 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 space after IF keyword; 0 found

Check failure on line 2024 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 2024 in src/wp-admin/includes/file.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 spaces before closing parenthesis; 0 found
$wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
}

if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) {
return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename );
Expand Down
4 changes: 3 additions & 1 deletion src/wp-admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
}

ini_set( 'display_errors', true ); // Ensure that fatal errors are displayed.
if ( function_exists( 'ini_set' ) ) {
ini_set( 'display_errors', true ); // Ensure that fatal errors are displayed.
}
// Go back to "sandbox" scope so we get the same errors as before.
plugin_sandbox_scrape( $plugin );
/** This action is documented in wp-admin/includes/plugin.php */
Expand Down
4 changes: 3 additions & 1 deletion src/wp-admin/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@
echo '<p>' . __( 'Plugin failed to reactivate due to a fatal error.' ) . '</p>';

error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
ini_set( 'display_errors', true ); // Ensure that fatal errors are displayed.
if ( function_exists( 'ini_set' ) ) {
ini_set( 'display_errors', true ); // Ensure that fatal errors are displayed.
}
wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
include WP_PLUGIN_DIR . '/' . $plugin;
}
Expand Down
8 changes: 6 additions & 2 deletions src/wp-includes/PHPMailer/PHPMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,9 @@ protected function mailSend($header, $body)
$params = sprintf('-f%s', $this->Sender);
}
$old_from = ini_get('sendmail_from');
ini_set('sendmail_from', $this->Sender);
if ( function_exists('ini_set') ) {
ini_set('sendmail_from', $this->Sender);
}
}
$result = false;
if ($this->SingleTo && count($toArr) > 1) {
Expand All @@ -1969,7 +1971,9 @@ protected function mailSend($header, $body)
$this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From, []);
}
if (isset($old_from)) {
ini_set('sendmail_from', $old_from);
if ( function_exists('ini_set') ) {
ini_set('sendmail_from', $old_from);
}
}
if (!$result) {
throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);
Expand Down
4 changes: 3 additions & 1 deletion src/wp-includes/default-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ function wp_initial_constants() {
// Set memory limits.
$wp_limit_int = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
if ( -1 !== $current_limit_int && ( -1 === $wp_limit_int || $wp_limit_int > $current_limit_int ) ) {
ini_set( 'memory_limit', WP_MEMORY_LIMIT );
if ( function_exists( 'ini_set' ) ) {
ini_set( 'memory_limit', WP_MEMORY_LIMIT );
}
}

if ( ! isset( $blog_id ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7883,13 +7883,13 @@ function wp_raise_memory_limit( $context = 'admin' ) {
$filtered_limit_int = wp_convert_hr_to_bytes( $filtered_limit );

if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
if ( false !== ini_set( 'memory_limit', $filtered_limit ) ) {
if ( function_exists( 'ini_set' ) && false !== ini_set( 'memory_limit', $filtered_limit ) ) {
return $filtered_limit;
} else {
return false;
}
} elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
if ( false !== ini_set( 'memory_limit', $wp_max_limit ) ) {
if ( function_exists( 'ini_set' ) && false !== ini_set( 'memory_limit', $wp_max_limit ) ) {
return $wp_max_limit;
} else {
return false;
Expand Down
18 changes: 13 additions & 5 deletions src/wp-includes/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,13 @@ function wp_debug_mode() {
error_reporting( E_ALL );

if ( WP_DEBUG_DISPLAY ) {
ini_set( 'display_errors', 1 );
if ( function_exists( 'ini_set' ) ) {
ini_set( 'display_errors', 1 );
}
} elseif ( null !== WP_DEBUG_DISPLAY ) {
ini_set( 'display_errors', 0 );
if ( function_exists( 'ini_set' ) ) {
ini_set( 'display_errors', 0 );
}
}

if ( in_array( strtolower( (string) WP_DEBUG_LOG ), array( 'true', '1' ), true ) ) {
Expand All @@ -599,8 +603,10 @@ function wp_debug_mode() {
}

if ( $log_path ) {
ini_set( 'log_errors', 1 );
ini_set( 'error_log', $log_path );
if ( function_exists( 'ini_set' ) ) {
ini_set( 'log_errors', 1 );
ini_set( 'error_log', $log_path );
}
}
} else {
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
Expand All @@ -614,7 +620,9 @@ function wp_debug_mode() {
|| ( defined( 'WP_INSTALLING' ) && WP_INSTALLING )
|| wp_doing_ajax() || wp_is_json_request()
) {
ini_set( 'display_errors', 0 );
if ( function_exists( 'ini_set' ) ) {
ini_set( 'display_errors', 0 );
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/wp-includes/pomo/po.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
* which still use the old MacOS standalone `\r` as a line ending.
* This fix should be revisited when PHP 9.0 is in alpha/beta.
*/
@ini_set( 'auto_detect_line_endings', 1 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( function_exists( 'ini_set' ) ) {
@ini_set( 'auto_detect_line_endings', 1 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
}

/**
* Routines for working with PO files
Expand Down
Loading