diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-admin/includes/class-wp-debug-data.php --- a/wp/wp-admin/includes/class-wp-debug-data.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-admin/includes/class-wp-debug-data.php Fri Sep 05 18:40:08 2025 +0200 @@ -7,6 +7,7 @@ * @since 5.2.0 */ +#[AllowDynamicProperties] class WP_Debug_Data { /** * Calls all core functions to check for updates. @@ -28,12 +29,13 @@ * @since 5.5.0 Added pretty permalinks support information. * * @throws ImagickException - * @global wpdb $wpdb WordPress database abstraction object. + * @global wpdb $wpdb WordPress database abstraction object. + * @global array $_wp_theme_features * * @return array The debug data for the site. */ public static function debug_data() { - global $wpdb; + global $wpdb, $_wp_theme_features; // Save few function calls. $upload_dir = wp_upload_dir(); @@ -132,6 +134,7 @@ if ( ! $is_multisite ) { $info['wp-paths-sizes'] = array( + /* translators: Filesystem directory paths and storage sizes. */ 'label' => __( 'Directories and Sizes' ), 'fields' => array(), ); @@ -235,7 +238,7 @@ } // Check WP_ENVIRONMENT_TYPE. - if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) { + if ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE ) { $wp_environment_type = WP_ENVIRONMENT_TYPE; } else { $wp_environment_type = __( 'Undefined' ); @@ -321,6 +324,11 @@ 'value' => $wp_environment_type, 'debug' => $wp_environment_type, ), + 'WP_DEVELOPMENT_MODE' => array( + 'label' => 'WP_DEVELOPMENT_MODE', + 'value' => WP_DEVELOPMENT_MODE ? WP_DEVELOPMENT_MODE : __( 'Disabled' ), + 'debug' => WP_DEVELOPMENT_MODE, + ), 'DB_CHARSET' => array( 'label' => 'DB_CHARSET', 'value' => ( defined( 'DB_CHARSET' ) ? DB_CHARSET : __( 'Undefined' ) ), @@ -339,6 +347,7 @@ $is_writable_upload_dir = wp_is_writable( $upload_dir['basedir'] ); $is_writable_wp_plugin_dir = wp_is_writable( WP_PLUGIN_DIR ); $is_writable_template_directory = wp_is_writable( get_theme_root( get_template() ) ); + $is_writable_fonts_dir = wp_is_writable( wp_get_font_dir()['basedir'] ); $info['wp-filesystem'] = array( 'label' => __( 'Filesystem Permissions' ), @@ -369,11 +378,24 @@ 'value' => ( $is_writable_template_directory ? __( 'Writable' ) : __( 'Not writable' ) ), 'debug' => ( $is_writable_template_directory ? 'writable' : 'not writable' ), ), + 'fonts' => array( + 'label' => __( 'The fonts directory' ), + 'value' => ( $is_writable_fonts_dir ? __( 'Writable' ) : __( 'Not writable' ) ), + 'debug' => ( $is_writable_fonts_dir ? 'writable' : 'not writable' ), + ), ), ); // Conditionally add debug information for multisite setups. if ( is_multisite() ) { + $site_id = get_current_blog_id(); + + $info['wp-core']['fields']['site_id'] = array( + 'label' => __( 'Site ID' ), + 'value' => $site_id, + 'debug' => $site_id, + ); + $network_query = new WP_Network_Query(); $network_ids = $network_query->query( array( @@ -467,6 +489,15 @@ 'value' => $loading, 'debug' => 'loading...', ), + 'fonts_path' => array( + 'label' => __( 'Fonts directory location' ), + 'value' => wp_get_font_dir()['basedir'], + ), + 'fonts_size' => array( + 'label' => __( 'Fonts directory size' ), + 'value' => $loading, + 'debug' => 'loading...', + ), 'database_size' => array( 'label' => __( 'Database size' ), 'value' => $loading, @@ -541,6 +572,7 @@ ); } else { // Get the PHP ini directive values. + $file_uploads = ini_get( 'file_uploads' ); $post_max_size = ini_get( 'post_max_size' ); $upload_max_filesize = ini_get( 'upload_max_filesize' ); $max_file_uploads = ini_get( 'max_file_uploads' ); @@ -549,8 +581,8 @@ // Add info in Media section. $info['wp-media']['fields']['file_uploads'] = array( 'label' => __( 'File uploads' ), - 'value' => empty( ini_get( 'file_uploads' ) ) ? __( 'Disabled' ) : __( 'Enabled' ), - 'debug' => 'File uploads is turned off', + 'value' => $file_uploads ? __( 'Enabled' ) : __( 'Disabled' ), + 'debug' => $file_uploads, ); $info['wp-media']['fields']['post_max_size'] = array( 'label' => __( 'Max size of post data allowed' ), @@ -579,6 +611,7 @@ 'map' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : $not_available ), 'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : $not_available ), 'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : $not_available ), + 'time' => ( defined( 'imagick::RESOURCETYPE_TIME' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_TIME ) : $not_available ), ); $limits_debug = array( @@ -588,6 +621,7 @@ 'imagick::RESOURCETYPE_MAP' => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : 'not available' ), 'imagick::RESOURCETYPE_MEMORY' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : 'not available' ), 'imagick::RESOURCETYPE_THREAD' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : 'not available' ), + 'imagick::RESOURCETYPE_TIME' => ( defined( 'imagick::RESOURCETYPE_TIME' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_TIME ) : 'not available' ), ); $info['wp-media']['fields']['imagick_limits'] = array( @@ -677,29 +711,18 @@ $server_architecture = 'unknown'; } - if ( function_exists( 'phpversion' ) ) { - $php_version_debug = phpversion(); - // Whether PHP supports 64-bit. - $php64bit = ( PHP_INT_SIZE * 8 === 64 ); - - $php_version = sprintf( - '%s %s', - $php_version_debug, - ( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) ) - ); + $php_version_debug = PHP_VERSION; + // Whether PHP supports 64-bit. + $php64bit = ( PHP_INT_SIZE * 8 === 64 ); - if ( $php64bit ) { - $php_version_debug .= ' 64bit'; - } - } else { - $php_version = __( 'Unable to determine PHP version' ); - $php_version_debug = 'unknown'; - } + $php_version = sprintf( + '%s %s', + $php_version_debug, + ( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) ) + ); - if ( function_exists( 'php_sapi_name' ) ) { - $php_sapi = php_sapi_name(); - } else { - $php_sapi = 'unknown'; + if ( $php64bit ) { + $php_version_debug .= ' 64bit'; } $info['wp-server']['fields']['server_architecture'] = array( @@ -719,8 +742,8 @@ ); $info['wp-server']['fields']['php_sapi'] = array( 'label' => __( 'PHP SAPI' ), - 'value' => ( 'unknown' !== $php_sapi ? $php_sapi : __( 'Unable to determine PHP SAPI' ) ), - 'debug' => $php_sapi, + 'value' => PHP_SAPI, + 'debug' => PHP_SAPI, ); // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values. @@ -840,11 +863,24 @@ ); } + // Server time. + $date = new DateTime( 'now', new DateTimeZone( 'UTC' ) ); + + $info['wp-server']['fields']['current'] = array( + 'label' => __( 'Current time' ), + 'value' => $date->format( DateTime::ATOM ), + ); + $info['wp-server']['fields']['utc-time'] = array( + 'label' => __( 'Current UTC time' ), + 'value' => $date->format( DateTime::RFC850 ), + ); + $info['wp-server']['fields']['server-time'] = array( + 'label' => __( 'Current Server time' ), + 'value' => wp_date( 'c', $_SERVER['REQUEST_TIME'] ), + ); + // Populate the database debug fields. - if ( is_resource( $wpdb->dbh ) ) { - // Old mysql extension. - $extension = 'mysql'; - } elseif ( is_object( $wpdb->dbh ) ) { + if ( is_object( $wpdb->dbh ) ) { // mysqli or PDO. $extension = get_class( $wpdb->dbh ); } else { @@ -854,16 +890,7 @@ $server = $wpdb->get_var( 'SELECT VERSION()' ); - if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) { - $client_version = $wpdb->dbh->client_info; - } else { - // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved - if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) { - $client_version = $matches[0]; - } else { - $client_version = null; - } - } + $client_version = $wpdb->dbh->client_info; $info['wp-database']['fields']['extension'] = array( 'label' => __( 'Extension' ), @@ -1068,7 +1095,6 @@ } // Populate the section for the currently active theme. - global $_wp_theme_features; $theme_features = array(); if ( ! empty( $_wp_theme_features ) ) { @@ -1399,7 +1425,7 @@ } /** - * Add to or modify the debug information shown on the Tools -> Site Health -> Info screen. + * Filters the debug information shown on the Tools -> Site Health -> Info screen. * * Plugin or themes may wish to introduce their own debug information without creating * additional admin pages. They can utilize this filter to introduce their own sections @@ -1489,7 +1515,7 @@ } /** - * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket. + * Formats the information gathered for debugging, in a manner suitable for copying to a forum or support ticket. * * @since 5.2.0 * @@ -1558,10 +1584,12 @@ } /** - * Fetch the total size of all the database tables for the active database user. + * Fetches the total size of all the database tables for the active database user. * * @since 5.2.0 * + * @global wpdb $wpdb WordPress database abstraction object. + * * @return int The size of the database, in bytes. */ public static function get_database_size() { @@ -1579,7 +1607,7 @@ } /** - * Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`. + * Fetches the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`. * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`. * * @since 5.2.0 @@ -1599,25 +1627,32 @@ $max_execution_time = ini_get( 'max_execution_time' ); } - // The max_execution_time defaults to 0 when PHP runs from cli. - // We still want to limit it below. + /* + * The max_execution_time defaults to 0 when PHP runs from cli. + * We still want to limit it below. + */ if ( empty( $max_execution_time ) ) { - $max_execution_time = 30; + $max_execution_time = 30; // 30 seconds. } if ( $max_execution_time > 20 ) { - // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent - // edge-case timeouts that may happen after the size loop has finished running. + /* + * If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent + * edge-case timeouts that may happen after the size loop has finished running. + */ $max_execution_time -= 2; } - // Go through the various installation directories and calculate their sizes. - // No trailing slashes. + /* + * Go through the various installation directories and calculate their sizes. + * No trailing slashes. + */ $paths = array( 'wordpress_size' => untrailingslashit( ABSPATH ), 'themes_size' => get_theme_root(), 'plugins_size' => WP_PLUGIN_DIR, 'uploads_size' => $upload_dir['basedir'], + 'fonts_size' => wp_get_font_dir()['basedir'], ); $exclude = $paths; @@ -1635,6 +1670,18 @@ 'raw' => 0, ); + // If the directory does not exist, skip checking it, as it will skew the other results. + if ( ! is_dir( $path ) ) { + $all_sizes[ $name ] = array( + 'path' => $path, + 'raw' => 0, + 'size' => __( 'The directory does not exist.' ), + 'debug' => 'directory not found', + ); + + continue; + } + if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) { if ( 'wordpress_size' === $name ) { $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );