Make WordPress Core

Ticket #47454: 47454.patch

File 47454.patch, 5.5 KB (added by Clorith, 5 years ago)
  • src/wp-admin/includes/class-wp-site-health.php

     
    714714         *
    715715         * @param string $extension Optional. The extension name to test. Default null.
    716716         * @param string $function  Optional. The function name to test. Default null.
     717         * @param string $constant  Optional. The constant name to test for. Default null.
     718         * @param string $class     Optional. The class name to test for. Default null.
    717719         *
    718720         * @return bool Whether or not the extension and function are available.
    719721         */
    720         private function test_php_extension_availability( $extension = null, $function = null ) {
     722        private function test_php_extension_availability( $extension = null, $function = null, $constant = null, $class = null ) {
    721723                // If no extension or function is passed, claim to fail testing, as we have nothing to test against.
    722                 if ( ! $extension && ! $function ) {
     724                if ( ! $extension && ! $function && ! $constant && ! $class ) {
    723725                        return false;
    724726                }
    725727
     
    729731                if ( $function && ! function_exists( $function ) ) {
    730732                        return false;
    731733                }
     734                if ( $constant && ! defined( $constant ) ) {
     735                        return false;
     736                }
     737                if ( $class && ! class_exists( $class ) ) {
     738                        return false;
     739                }
    732740
    733741                return true;
    734742        }
     
    772780                );
    773781
    774782                $modules = array(
    775                         'bcmath'    => array(
    776                                 'function' => 'bcadd',
    777                                 'required' => false,
    778                         ),
    779783                        'curl'      => array(
    780784                                'function' => 'curl_version',
    781785                                'required' => false,
    782786                        ),
     787                        'dom'       => array(
     788                                'class'    => 'DOMNode',
     789                                'required' => false,
     790                        ),
    783791                        'exif'      => array(
    784792                                'function' => 'exif_read_data',
    785793                                'required' => false,
    786                         ),
    787                         'filter'    => array(
    788                                 'function' => 'filter_list',
    789                                 'required' => false,
    790794                        ),
    791795                        'fileinfo'  => array(
    792796                                'function' => 'finfo_file',
    793797                                'required' => false,
    794798                        ),
    795                         'mod_xml'   => array(
    796                                 'extension' => 'libxml',
    797                                 'required'  => false,
     799                        'hash'      => array(
     800                                'function' => 'hash',
     801                                'required' => false,
     802                        ),
     803                        'json'      => array(
     804                                'function' => 'json_encode',
     805                                'required' => false,
     806                        ),
     807                        'mbstring'  => array(
     808                                'function' => 'mb_check_encoding',
     809                                'required' => false,
    798810                        ),
    799811                        'mysqli'    => array(
    800812                                'function' => 'mysqli_connect',
    801813                                'required' => false,
    802814                        ),
    803815                        'libsodium' => array(
    804                                 'function'            => 'sodium_compare',
     816                                'constant'            => 'SODIUM_LIBRARY_VERSION',
    805817                                'required'            => false,
    806818                                'php_bundled_version' => '7.2.0',
    807819                        ),
     
    817829                                'extension' => 'imagick',
    818830                                'required'  => false,
    819831                        ),
     832                        'mod_xml'   => array(
     833                                'extension' => 'libxml',
     834                                'required'  => false,
     835                        ),
     836                        'zip'       => array(
     837                                'class'    => 'ZipArchive',
     838                                'required' => false,
     839                        ),
     840                        'filter'    => array(
     841                                'function' => 'filter_list',
     842                                'required' => false,
     843                        ),
    820844                        'gd'        => array(
    821845                                'extension'    => 'gd',
    822846                                'required'     => false,
    823847                                'fallback_for' => 'imagick',
    824848                        ),
     849                        'iconv'     => array(
     850                                'function' => 'iconv',
     851                                'required' => false,
     852                        ),
    825853                        'mcrypt'    => array(
    826854                                'extension'    => 'mcrypt',
    827855                                'required'     => false,
    828856                                'fallback_for' => 'libsodium',
    829857                        ),
     858                        'simplexml' => array(
     859                                'extension'    => 'simplexml',
     860                                'required'     => false,
     861                                'fallback_for' => 'mod_xml',
     862                        ),
    830863                        'xmlreader' => array(
    831864                                'extension'    => 'xmlreader',
    832865                                'required'     => false,
    833                                 'fallback_for' => 'xml',
     866                                'fallback_for' => 'mod_xml',
    834867                        ),
    835868                        'zlib'      => array(
    836869                                'extension'    => 'zlib',
     
    853886                 *
    854887                 *         string $function     Optional. A function name to test for the existence of.
    855888                 *         string $extension    Optional. An extension to check if is loaded in PHP.
     889                 *         string $constant     Optional. A constant name to check for to verify an extension exists.
     890                 *         string $class        Optional. A class name to check for to verify an extension exists.
    856891                 *         bool   $required     Is this a required feature or not.
    857892                 *         string $fallback_for Optional. The module this module replaces as a fallback.
    858893                 *     }
     
    863898                $failures = array();
    864899
    865900                foreach ( $modules as $library => $module ) {
    866                         $extension = ( isset( $module['extension'] ) ? $module['extension'] : null );
    867                         $function  = ( isset( $module['function'] ) ? $module['function'] : null );
     901                        $extension  = ( isset( $module['extension'] ) ? $module['extension'] : null );
     902                        $function   = ( isset( $module['function'] ) ? $module['function'] : null );
     903                        $constant   = ( isset( $module['constant'] ) ? $module['constant'] : null );
     904                        $class_name = ( isset( $module['class'] ) ? $module['class'] : null );
    868905
    869906                        // If this module is a fallback for another function, check if that other function passed.
    870907                        if ( isset( $module['fallback_for'] ) ) {
     
    879916                                }
    880917                        }
    881918
    882                         if ( ! $this->test_php_extension_availability( $extension, $function ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
     919                        if ( ! $this->test_php_extension_availability( $extension, $function, $constant, $class_name ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
    883920                                if ( $module['required'] ) {
    884921                                        $result['status'] = 'critical';
    885922