Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored WP_Debug_Data::debug_data() Part 1 #7065

Closed
wants to merge 8 commits into from
146 changes: 92 additions & 54 deletions src/wp-admin/includes/class-wp-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public static function check_for_updates() {
wp_update_themes();
}

/**
* Add the callbacks to the `debug_information` filter.
*
* @since tbd
*/
public static function init_filters(): void {
add_filter( 'debug_information', array( __CLASS__, 'wp_filesystem' ), 9 );
apermo marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Static function for generating site debug data when required.
*
Expand All @@ -34,7 +43,7 @@ public static function check_for_updates() {
*
* @return array The debug data for the site.
*/
public static function debug_data() {
public static function debug_data(): array {
apermo marked this conversation as resolved.
Show resolved Hide resolved
global $wpdb, $_wp_theme_features;

// Save few function calls.
Expand Down Expand Up @@ -342,50 +351,6 @@ public static function debug_data() {
),
);

$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'] );

$info['wp-filesystem'] = array(
'label' => __( 'Filesystem Permissions' ),
'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.' ),
'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' ),
),
),
);

// Conditionally add debug information for multisite setups.
if ( is_multisite() ) {
$site_id = get_current_blog_id();
Expand Down Expand Up @@ -1413,16 +1378,16 @@ public static function debug_data() {
);
}

// 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 );
self::init_filters();

$info['wp-filesystem']['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' ),
);
}
/**
* Fires before the debug information is gathered.
*
* This hook allows you to alter, add, or remove debug information before it is gathered.
*
* @since tbd
*/
do_action( 'pre_debug_information' );
apermo marked this conversation as resolved.
Show resolved Hide resolved

/**
* Filters the debug information shown on the Tools -> Site Health -> Info screen.
Expand Down Expand Up @@ -1489,6 +1454,79 @@ public static function debug_data() {
return $info;
}

/**
* Populate the file system section of the debug data.
*
* Using the {@see 'debug_information'} filter for this.
apermo marked this conversation as resolved.
Show resolved Hide resolved
*
* @since tbd
apermo marked this conversation as resolved.
Show resolved Hide resolved
*
* @param array $info The debug information to be added to the core information page.
*
* @return array
*/
public static function wp_filesystem( array $info ): array {
costdev marked this conversation as resolved.
Show resolved Hide resolved
$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' ),
);
}

$info['wp-filesystem'] = array(
'label' => __( 'Filesystem Permissions' ),
'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.' ),
'fields' => $fields,
);

return $info;
}

/**
* Returns the value of a MySQL system variable.
*
Expand Down
Loading