From b3fff8ffbe5c5f7251ec6a69598dc6e1e9da3f5a Mon Sep 17 00:00:00 2001 From: Christoph Daum Date: Sat, 20 Jul 2024 13:05:28 +0200 Subject: [PATCH] Refactored WP_Debug_Data::debug_data() Part 1 Changed: Moving $info['wp-filesystem'] to own function --- src/wp-admin/includes/class-wp-debug-data.php | 128 ++++++++++-------- 1 file changed, 73 insertions(+), 55 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 109e38b0635d6..4b0d1a13b6b88 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -34,7 +34,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 { global $wpdb, $_wp_theme_features; // Save few function calls. @@ -342,50 +342,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(); @@ -1413,16 +1369,7 @@ 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 ); - - $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' ), - ); - } + add_filter( 'debug_information', array( __CLASS__, 'wp_filesystem' ), 9 ); /** * Filters the debug information shown on the Tools -> Site Health -> Info screen. @@ -1489,6 +1436,77 @@ public static function debug_data() { return $info; } + /** + * Populate the file system section of the debug data. + * + * @since tbd + * + * @param array $info The debug information to be added to the core information page. + * + * @return array + */ + public static function wp_filesystem( array $info ): 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' ), + ); + } + + $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. *