Make WordPress Core

Changeset 52585


Ignore:
Timestamp:
01/17/2022 11:39:35 AM (3 years ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Check if the disk_free_space() function exists before calling it.

In PHP 8+, @ no longer suppresses fatal errors:

The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE).

Reference: PHP 8: Backward Incompatible Changes.

disk_free_space() may be disabled by hosts, which will throw a fatal error on a call to undefined function.

This change prevents the fatal error, and falls back to false when disk_free_space() is unavailable.

Follow-up to [25540], [25774], [25776], [25831], [25869].

Props costdev, jrf, swb1192, SergeyBiryukov.
Fixes #54826. See #54730.

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r52425 r52585  
    16621662     */
    16631663    if ( wp_doing_cron() ) {
    1664         $available_space = @disk_free_space( WP_CONTENT_DIR );
     1664        $available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR ) : false;
    16651665
    16661666        if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) {
     
    18031803     */
    18041804    if ( wp_doing_cron() ) {
    1805         $available_space = @disk_free_space( WP_CONTENT_DIR );
     1805        $available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR ) : false;
    18061806
    18071807        if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) {
  • trunk/src/wp-admin/includes/update-core.php

    r52199 r52585  
    12431243        // If we don't have enough free space, it isn't worth trying again.
    12441244        // Unlikely to be hit due to the check in unzip_file().
    1245         $available_space = @disk_free_space( ABSPATH );
     1245        $available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( ABSPATH ) : false;
    12461246
    12471247        if ( $available_space && $total_size >= $available_space ) {
Note: See TracChangeset for help on using the changeset viewer.