Make WordPress Core

Changeset 46268


Ignore:
Timestamp:
09/23/2019 07:49:06 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Site Health: Update PHP extension tests to reflect the current state of the Hosting Teams handbook recommendations.

Props Clorith, bronsonquick, jrf, johnbillion, galbaras, mikeschroder, jorbin.
Fixes #47454.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r46267 r46268  
    728728     *
    729729     * @since 5.2.0
     730     * @since 5.3.0 The `$constant` and `$class` parameters were added.
    730731     *
    731732     * @param string $extension Optional. The extension name to test. Default null.
    732733     * @param string $function  Optional. The function name to test. Default null.
     734     * @param string $constant  Optional. The constant name to test for. Default null.
     735     * @param string $class     Optional. The class name to test for. Default null.
    733736     *
    734737     * @return bool Whether or not the extension and function are available.
    735738     */
    736     private function test_php_extension_availability( $extension = null, $function = null ) {
     739    private function test_php_extension_availability( $extension = null, $function = null, $constant = null, $class = null ) {
    737740        // If no extension or function is passed, claim to fail testing, as we have nothing to test against.
    738         if ( ! $extension && ! $function ) {
     741        if ( ! $extension && ! $function && ! $constant && ! $class ) {
    739742            return false;
    740743        }
     
    744747        }
    745748        if ( $function && ! function_exists( $function ) ) {
     749            return false;
     750        }
     751        if ( $constant && ! defined( $constant ) ) {
     752            return false;
     753        }
     754        if ( $class && ! class_exists( $class ) ) {
    746755            return false;
    747756        }
     
    789798
    790799        $modules = array(
    791             'bcmath'    => array(
    792                 'function' => 'bcadd',
    793                 'required' => false,
    794             ),
    795800            'curl'      => array(
    796801                'function' => 'curl_version',
    797802                'required' => false,
    798803            ),
     804            'dom'       => array(
     805                'class'    => 'DOMNode',
     806                'required' => false,
     807            ),
    799808            'exif'      => array(
    800809                'function' => 'exif_read_data',
    801810                'required' => false,
    802811            ),
     812            'fileinfo'  => array(
     813                'function' => 'finfo_file',
     814                'required' => false,
     815            ),
     816            'hash'      => array(
     817                'function' => 'hash',
     818                'required' => false,
     819            ),
     820            'json'      => array(
     821                'function' => 'json_last_error',
     822                'required' => true,
     823            ),
     824            'mbstring'  => array(
     825                'function' => 'mb_check_encoding',
     826                'required' => false,
     827            ),
     828            'mysqli'    => array(
     829                'function' => 'mysqli_connect',
     830                'required' => false,
     831            ),
     832            'libsodium' => array(
     833                'constant'            => 'SODIUM_LIBRARY_VERSION',
     834                'required'            => false,
     835                'php_bundled_version' => '7.2.0',
     836            ),
     837            'openssl'   => array(
     838                'function' => 'openssl_encrypt',
     839                'required' => false,
     840            ),
     841            'pcre'      => array(
     842                'function' => 'preg_match',
     843                'required' => false,
     844            ),
     845            'imagick'   => array(
     846                'extension' => 'imagick',
     847                'required'  => false,
     848            ),
     849            'mod_xml'   => array(
     850                'extension' => 'libxml',
     851                'required'  => false,
     852            ),
     853            'zip'       => array(
     854                'class'    => 'ZipArchive',
     855                'required' => false,
     856            ),
    803857            'filter'    => array(
    804858                'function' => 'filter_list',
    805859                'required' => false,
    806             ),
    807             'fileinfo'  => array(
    808                 'function' => 'finfo_file',
    809                 'required' => false,
    810             ),
    811             'mod_xml'   => array(
    812                 'extension' => 'libxml',
    813                 'required'  => false,
    814             ),
    815             'mysqli'    => array(
    816                 'function' => 'mysqli_connect',
    817                 'required' => false,
    818             ),
    819             'libsodium' => array(
    820                 'function'            => 'sodium_compare',
    821                 'required'            => false,
    822                 'php_bundled_version' => '7.2.0',
    823             ),
    824             'openssl'   => array(
    825                 'function' => 'openssl_encrypt',
    826                 'required' => false,
    827             ),
    828             'pcre'      => array(
    829                 'function' => 'preg_match',
    830                 'required' => false,
    831             ),
    832             'imagick'   => array(
    833                 'extension' => 'imagick',
    834                 'required'  => false,
    835860            ),
    836861            'gd'        => array(
     
    839864                'fallback_for' => 'imagick',
    840865            ),
     866            'iconv'     => array(
     867                'function' => 'iconv',
     868                'required' => false,
     869            ),
    841870            'mcrypt'    => array(
    842871                'extension'    => 'mcrypt',
     
    844873                'fallback_for' => 'libsodium',
    845874            ),
     875            'simplexml' => array(
     876                'extension'    => 'simplexml',
     877                'required'     => false,
     878                'fallback_for' => 'mod_xml',
     879            ),
    846880            'xmlreader' => array(
    847881                'extension'    => 'xmlreader',
    848882                'required'     => false,
    849                 'fallback_for' => 'xml',
     883                'fallback_for' => 'mod_xml',
    850884            ),
    851885            'zlib'      => array(
     
    860894         *
    861895         * @since 5.2.0
     896         * @since 5.3.0 The `$constant` and `$class` parameters were added.
    862897         *
    863898         * @param array $modules {
     
    870905         *         string $function     Optional. A function name to test for the existence of.
    871906         *         string $extension    Optional. An extension to check if is loaded in PHP.
     907         *         string $constant     Optional. A constant name to check for to verify an extension exists.
     908         *         string $class        Optional. A class name to check for to verify an extension exists.
    872909         *         bool   $required     Is this a required feature or not.
    873910         *         string $fallback_for Optional. The module this module replaces as a fallback.
     
    880917
    881918        foreach ( $modules as $library => $module ) {
    882             $extension = ( isset( $module['extension'] ) ? $module['extension'] : null );
    883             $function  = ( isset( $module['function'] ) ? $module['function'] : null );
     919            $extension  = ( isset( $module['extension'] ) ? $module['extension'] : null );
     920            $function   = ( isset( $module['function'] ) ? $module['function'] : null );
     921            $constant   = ( isset( $module['constant'] ) ? $module['constant'] : null );
     922            $class_name = ( isset( $module['class'] ) ? $module['class'] : null );
    884923
    885924            // If this module is a fallback for another function, check if that other function passed.
     
    896935            }
    897936
    898             if ( ! $this->test_php_extension_availability( $extension, $function ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
     937            if ( ! $this->test_php_extension_availability( $extension, $function, $constant, $class_name ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
    899938                if ( $module['required'] ) {
    900939                    $result['status'] = 'critical';
Note: See TracChangeset for help on using the changeset viewer.