: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public static function get_mysql_var( $mysql_var ) {
$result = $wpdb->get_row(
$wpdb->prepare( 'SHOW VARIABLES LIKE %s', $mysql_var ),
if ( ! empty( $result ) && array_key_exists( 'Value', $result ) ) {
* Formats the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
* @param array $info_array Information gathered from the `WP_Debug_Data::debug_data()` function.
* @param string $data_type The data type to return, either 'info' or 'debug'.
* @return string The formatted data.
public static function format( $info_array, $data_type ) {
foreach ( $info_array as $section => $details ) {
// Skip this section if there are no fields, or the section has been declared as private.
if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
$section_label = 'debug' === $data_type ? $section : $details['label'];
( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
foreach ( $details['fields'] as $field_name => $field ) {
if ( isset( $field['private'] ) && true === $field['private'] ) {
if ( 'debug' === $data_type && isset( $field['debug'] ) ) {
$debug_data = $field['debug'];
$debug_data = $field['value'];
// Can be array, one level deep only.
if ( is_array( $debug_data ) ) {
foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
$value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
} elseif ( is_bool( $debug_data ) ) {
$value = $debug_data ? 'true' : 'false';
} elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
if ( 'debug' === $data_type ) {
$label = $field['label'];
$return .= sprintf( "%s: %s\n", $label, $value );
* Fetches the total size of all the database tables for the active database user.
* @global wpdb $wpdb WordPress database abstraction object.
* @return int The size of the database, in bytes.
public static function get_database_size() {
$rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
if ( $wpdb->num_rows > 0 ) {
foreach ( $rows as $row ) {
$size += $row['Data_length'] + $row['Index_length'];
* 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()`.
* @return array The sizes of the directories, also the database size and total installation size.
public static function get_sizes() {
$size_db = self::get_database_size();
$upload_dir = wp_get_upload_dir();
* We will be using the PHP max execution time to prevent the size calculations
* from causing a timeout. The default value is 30 seconds, and some
* hosts do not allow you to read configuration values.
if ( function_exists( 'ini_get' ) ) {
$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.
if ( empty( $max_execution_time ) ) {
$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.
$max_execution_time -= 2;
* Go through the various installation directories and calculate their sizes.
'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'],
unset( $exclude['wordpress_size'] );
$exclude = array_values( $exclude );
// Loop over all the directories we want to gather the sizes for.
foreach ( $paths as $name => $path ) {
$dir_size = null; // Default to timeout.
// If the directory does not exist, skip checking it, as it will skew the other results.
if ( ! is_dir( $path ) ) {
$all_sizes[ $name ] = array(
'size' => __( 'The directory does not exist.' ),
'debug' => 'directory not found',
if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
if ( 'wordpress_size' === $name ) {
$dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
$dir_size = recurse_dirsize( $path, null, $max_execution_time );
if ( false === $dir_size ) {
$results['size'] = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
$results['debug'] = 'not accessible';
// Stop total size calculation.
} elseif ( null === $dir_size ) {
$results['size'] = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
$results['debug'] = 'timeout while calculating size';
// Stop total size calculation.
if ( null !== $size_total ) {
$size_total += $dir_size;
$results['raw'] = $dir_size;
$results['size'] = size_format( $dir_size, 2 );
$results['debug'] = $results['size'] . " ({$dir_size} bytes)";
$all_sizes[ $name ] = $results;
$database_size = size_format( $size_db, 2 );
$all_sizes['database_size'] = array(
'size' => $database_size,
'debug' => $database_size . " ({$size_db} bytes)",
$all_sizes['database_size'] = array(
'size' => __( 'Not available' ),
'debug' => 'not available',
if ( null !== $size_total && $size_db > 0 ) {
$total_size = $size_total + $size_db;
$total_size_mb = size_format( $total_size, 2 );
$all_sizes['total_size'] = array(
'size' => $total_size_mb,
'debug' => $total_size_mb . " ({$total_size} bytes)",
$all_sizes['total_size'] = array(
'size' => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
'debug' => 'not available',