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()
.
Source
'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();
$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 = wp_is_writable( wp_get_font_dir()['basedir'] );
$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' => ( $is_writable_fonts_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
'debug' => ( $is_writable_fonts_dir ? 'writable' : 'not writable' ),
),
);
// 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;
$result = $wpdb->get_row(
$wpdb->prepare( 'SHOW VARIABLES LIKE %s', $mysql_var ),
ARRAY_A
);
if ( ! empty( $result ) && array_key_exists( 'Value', $result ) ) {
return $result['Value'];
}
return null;
}
/**
* Formats the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
*
* @since 5.2.0
*
* @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 ) {
$return = "`\n";
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'] ) ) {
continue;
}
$section_label = 'debug' === $data_type ? $section : $details['label'];
$return .= sprintf(
Changelog
Version | Description |
---|---|
5.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.