WP_Debug_Data::get_sizes(): array

In this article

Fetches the sizes of the WordPress directories: wordpress (ABSPATH), plugins, themes, and uploads.

Description

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.

Source

		),
		'client_version'     => array(
			'label' => __( 'Client version' ),
			'value' => $client_version,
		),
		'database_user'      => array(
			'label'   => __( 'Database username' ),
			'value'   => $wpdb->dbuser,
			'private' => true,
		),
		'database_host'      => array(
			'label'   => __( 'Database host' ),
			'value'   => $wpdb->dbhost,
			'private' => true,
		),
		'database_name'      => array(
			'label'   => __( 'Database name' ),
			'value'   => $wpdb->dbname,
			'private' => true,
		),
		'database_prefix'    => array(
			'label'   => __( 'Table prefix' ),
			'value'   => $wpdb->prefix,
			'private' => true,
		),
		'database_charset'   => array(
			'label'   => __( 'Database charset' ),
			'value'   => $wpdb->charset,
			'private' => true,
		),
		'database_collate'   => array(
			'label'   => __( 'Database collation' ),
			'value'   => $wpdb->collate,
			'private' => true,
		),
		'max_allowed_packet' => array(
			'label' => __( 'Max allowed packet size' ),
			'value' => self::get_mysql_var( 'max_allowed_packet' ),
		),
		'max_connections'    => array(
			'label' => __( 'Max connections number' ),
			'value' => self::get_mysql_var( 'max_connections' ),
		),
	);

	return array(
		'label'  => __( 'Database' ),
		'fields' => $fields,
	);
}

/**
 * Gets the file system section of the debug data.
 *
 * @since 6.7.0
 *
 * @return array
 */
private static function get_wp_filesystem(): array {
	$upload_dir                     = wp_upload_dir();
	$fonts_dir_exists               = file_exists( wp_get_font_dir()['basedir'] );
	$is_writable_abspath            = wp_is_writable( ABSPATH );
	$is_writable_wp_content_dir     = wp_is_writable( WP_CONTENT_DIR );
	$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          = $fonts_dir_exists ? wp_is_writable( wp_get_font_dir()['basedir'] ) : false;

	$fields = array(
		'wordpress'  => array(
			'label' => __( 'The main WordPress directory' ),
			'value' => ( $is_writable_abspath ? __( 'Writable' ) : __( 'Not writable' ) ),
			'debug' => ( $is_writable_abspath ? 'writable' : 'not writable' ),
		),
		'wp-content' => array(
			'label' => __( 'The wp-content directory' ),
			'value' => ( $is_writable_wp_content_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
			'debug' => ( $is_writable_wp_content_dir ? 'writable' : 'not writable' ),
		),
		'uploads'    => array(
			'label' => __( 'The uploads directory' ),
			'value' => ( $is_writable_upload_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
			'debug' => ( $is_writable_upload_dir ? 'writable' : 'not writable' ),
		),
		'plugins'    => array(
			'label' => __( 'The plugins directory' ),
			'value' => ( $is_writable_wp_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
			'debug' => ( $is_writable_wp_plugin_dir ? 'writable' : 'not writable' ),
		),
		'themes'     => array(
			'label' => __( 'The themes directory' ),
			'value' => ( $is_writable_template_directory ? __( 'Writable' ) : __( 'Not writable' ) ),
			'debug' => ( $is_writable_template_directory ? 'writable' : 'not writable' ),
		),
		'fonts'      => array(
			'label' => __( 'The fonts directory' ),
			'value' => $fonts_dir_exists
				? ( $is_writable_fonts_dir ? __( 'Writable' ) : __( 'Not writable' ) )
				: __( 'Does not exist' ),
			'debug' => $fonts_dir_exists
				? ( $is_writable_fonts_dir ? 'writable' : 'not writable' )
				: 'does not exist',
		),
	);

	// Add more filesystem checks.
	if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
		$is_writable_wpmu_plugin_dir = wp_is_writable( WPMU_PLUGIN_DIR );

		$fields['mu-plugins'] = array(
			'label' => __( 'The must use plugins directory' ),
			'value' => ( $is_writable_wpmu_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
			'debug' => ( $is_writable_wpmu_plugin_dir ? 'writable' : 'not writable' ),
		);
	}

	return array(
		'label'       => __( 'Filesystem Permissions' ),
		'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.' ),
		'fields'      => $fields,
	);
}

/**
 * Returns the value of a MySQL system variable.
 *
 * @since 5.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $mysql_var Name of the MySQL system variable.
 * @return string|null The variable value on success. Null if the variable does not exist.
 */
public static function get_mysql_var( $mysql_var ) {
	global $wpdb;

Changelog

VersionDescription
5.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.