From e83b03f5f601779edf9b44bb854842fd773a4590 Mon Sep 17 00:00:00 2001 From: Erik <11491369+kebbet@users.noreply.github.com> Date: Tue, 6 Aug 2024 09:48:22 +0200 Subject: [PATCH 1/4] Break out wp-database info to separate function. --- src/wp-admin/includes/class-wp-debug-data.php | 162 ++++++++++-------- 1 file changed, 86 insertions(+), 76 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index c07ae4e949bb7..02486b84ea6e2 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -29,13 +29,12 @@ public static function check_for_updates() { * @since 5.5.0 Added pretty permalinks support information. * * @throws ImagickException - * @global wpdb $wpdb WordPress database abstraction object. * @global array $_wp_theme_features * * @return array The debug data for the site. */ public static function debug_data() { - global $wpdb, $_wp_theme_features; + global $_wp_theme_features; // Save few function calls. $upload_dir = wp_upload_dir(); @@ -694,80 +693,6 @@ public static function debug_data() { 'value' => wp_date( 'c', $_SERVER['REQUEST_TIME'] ), ); - // Populate the database debug fields. - if ( is_object( $wpdb->dbh ) ) { - // mysqli or PDO. - $extension = get_class( $wpdb->dbh ); - } else { - // Unknown sql extension. - $extension = null; - } - - $server = $wpdb->get_var( 'SELECT VERSION()' ); - - $client_version = $wpdb->dbh->client_info; - - $info['wp-database']['fields']['extension'] = array( - 'label' => __( 'Extension' ), - 'value' => $extension, - ); - - $info['wp-database']['fields']['server_version'] = array( - 'label' => __( 'Server version' ), - 'value' => $server, - ); - - $info['wp-database']['fields']['client_version'] = array( - 'label' => __( 'Client version' ), - 'value' => $client_version, - ); - - $info['wp-database']['fields']['database_user'] = array( - 'label' => __( 'Database username' ), - 'value' => $wpdb->dbuser, - 'private' => true, - ); - - $info['wp-database']['fields']['database_host'] = array( - 'label' => __( 'Database host' ), - 'value' => $wpdb->dbhost, - 'private' => true, - ); - - $info['wp-database']['fields']['database_name'] = array( - 'label' => __( 'Database name' ), - 'value' => $wpdb->dbname, - 'private' => true, - ); - - $info['wp-database']['fields']['database_prefix'] = array( - 'label' => __( 'Table prefix' ), - 'value' => $wpdb->prefix, - 'private' => true, - ); - - $info['wp-database']['fields']['database_charset'] = array( - 'label' => __( 'Database charset' ), - 'value' => $wpdb->charset, - 'private' => true, - ); - - $info['wp-database']['fields']['database_collate'] = array( - 'label' => __( 'Database collation' ), - 'value' => $wpdb->collate, - 'private' => true, - ); - - $info['wp-database']['fields']['max_allowed_packet'] = array( - 'label' => __( 'Max allowed packet size' ), - 'value' => self::get_mysql_var( 'max_allowed_packet' ), - ); - - $info['wp-database']['fields']['max_connections'] = array( - 'label' => __( 'Max connections number' ), - 'value' => self::get_mysql_var( 'max_connections' ), - ); - // List must use plugins if there are any. $mu_plugins = get_mu_plugins(); @@ -1228,6 +1153,7 @@ public static function debug_data() { ); } + $info['wp-database'] = self::get_wp_database(); $info['wp-constants'] = self::get_wp_constants(); $info['wp-filesystem'] = self::get_wp_filesystem(); @@ -1296,6 +1222,90 @@ public static function debug_data() { return $info; } + /** + * Gets the WordPress database section of the debug data. + * + * @since 6.7.0 + * + * @global wpdb $wpdb WordPress database abstraction object. + * + * @return array + */ + public static function get_wp_database(): array { + global $wpdb; + + // Populate the database debug fields. + if ( is_object( $wpdb->dbh ) ) { + // mysqli or PDO. + $extension = get_class( $wpdb->dbh ); + } else { + // Unknown sql extension. + $extension = null; + } + + $server = $wpdb->get_var( 'SELECT VERSION()' ); + + $client_version = $wpdb->dbh->client_info; + + $fields = array( + 'extension' => array( + 'label' => __( 'Database Extension' ), + 'value' => $extension, + ), + 'server_version' => array( + 'label' => __( 'Server version' ), + 'value' => $server, + ), + '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 WordPress constants section of the debug data. * From c5061a1cb16b418d2a0fa88128ae1c88b1e26006 Mon Sep 17 00:00:00 2001 From: Erik <11491369+kebbet@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:01:51 +0200 Subject: [PATCH 2/4] Coding standards --- src/wp-admin/includes/class-wp-debug-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 02486b84ea6e2..9e77d0999f420 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -1297,7 +1297,7 @@ public static function get_wp_database(): array { 'max_connections' => array( 'label' => __( 'Max connections number' ), 'value' => self::get_mysql_var( 'max_connections' ), - ) + ), ); return array( From 9583389864bacae4661d3796b00fae146194f747 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 2 Sep 2024 15:18:32 -0500 Subject: [PATCH 3/4] Alphabetize and add `@since` tag to docblock. --- src/wp-admin/includes/class-wp-debug-data.php | 172 +++++++++--------- 1 file changed, 87 insertions(+), 85 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index 55d8d1b2999c6..e2106a59a98b4 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -27,6 +27,7 @@ public static function check_for_updates() { * @since 5.3.0 Added database charset, database collation, * and timezone information. * @since 5.5.0 Added pretty permalinks support information. + * @since 6.7.0 Modularized into separate theme-oriented methods. * * @throws ImagickException * @global array $_wp_theme_features @@ -1153,8 +1154,8 @@ public static function debug_data() { ); } - $info['wp-database'] = self::get_wp_database(); $info['wp-constants'] = self::get_wp_constants(); + $info['wp-database'] = self::get_wp_database(); $info['wp-filesystem'] = self::get_wp_filesystem(); /** @@ -1222,90 +1223,6 @@ public static function debug_data() { return $info; } - /** - * Gets the WordPress database section of the debug data. - * - * @since 6.7.0 - * - * @global wpdb $wpdb WordPress database abstraction object. - * - * @return array - */ - public static function get_wp_database(): array { - global $wpdb; - - // Populate the database debug fields. - if ( is_object( $wpdb->dbh ) ) { - // mysqli or PDO. - $extension = get_class( $wpdb->dbh ); - } else { - // Unknown sql extension. - $extension = null; - } - - $server = $wpdb->get_var( 'SELECT VERSION()' ); - - $client_version = $wpdb->dbh->client_info; - - $fields = array( - 'extension' => array( - 'label' => __( 'Database Extension' ), - 'value' => $extension, - ), - 'server_version' => array( - 'label' => __( 'Server version' ), - 'value' => $server, - ), - '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 WordPress constants section of the debug data. * @@ -1457,6 +1374,91 @@ public static function get_wp_constants(): array { ); } + /** + * Gets the WordPress database section of the debug data. + * + * @since 6.7.0 + * + * @global wpdb $wpdb WordPress database abstraction object. + * + * @return array + */ + public static function get_wp_database(): array { + global $wpdb; + + // Populate the database debug fields. + if ( is_object( $wpdb->dbh ) ) { + // mysqli or PDO. + $extension = get_class( $wpdb->dbh ); + } else { + // Unknown sql extension. + $extension = null; + } + + $server = $wpdb->get_var( 'SELECT VERSION()' ); + + $client_version = $wpdb->dbh->client_info; + + $fields = array( + 'extension' => array( + 'label' => __( 'Database Extension' ), + 'value' => $extension, + ), + 'server_version' => array( + 'label' => __( 'Server version' ), + 'value' => $server, + ), + '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. * From ef711c7473b81e6f6e66d79261ae77b521a019b2 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Mon, 2 Sep 2024 15:20:05 -0500 Subject: [PATCH 4/4] fixup! Alphabetize and add `@since` tag to docblock. --- src/wp-admin/includes/class-wp-debug-data.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index e2106a59a98b4..4b1982454c528 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -1458,7 +1458,6 @@ public static function get_wp_database(): array { ); } - /** * Gets the file system section of the debug data. *