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 3 #7143

Closed
wants to merge 10 commits into from
163 changes: 87 additions & 76 deletions src/wp-admin/includes/class-wp-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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 wpdb $wpdb WordPress database abstraction object.
kebbet marked this conversation as resolved.
Show resolved Hide resolved
* @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();
Expand Down Expand Up @@ -694,80 +694,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();

Expand Down Expand Up @@ -1229,6 +1155,7 @@ public static function debug_data() {
}

$info['wp-constants'] = self::get_wp_constants();
$info['wp-database'] = self::get_wp_database();
$info['wp-filesystem'] = self::get_wp_filesystem();

/**
Expand Down Expand Up @@ -1447,6 +1374,90 @@ 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.
*
Expand Down
Loading