Make WordPress Core

Changeset 58964


Ignore:
Timestamp:
09/02/2024 08:43:00 PM (15 months ago)
Author:
dmsnell
Message:

WP_Debug_Data: Extract wp-database data into separate method.

This is the part three in a larger modularization of the data in WP_Debug_Data. Previously this was a single massive method drawing in debug data from various groups of related data, where the groups were independent from each other.

This patch separates the third of twelve groups, the wp-database info, into a separate method focused on that data.

This work precedes changes to make the WP_Debug_Data class more extensible for better use by plugin and theme code.

Developed in https://github.com/wordpress/wordpress-develop/7143
Discussed in https://core.trac.wordpress.org/ticket/61648

Props dmsnell, kebbet, apermo.
See #61648.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r58884 r58964  
    2828     *              and timezone information.
    2929     * @since 5.5.0 Added pretty permalinks support information.
     30     * @since 6.7.0 Modularized into separate theme-oriented methods.
    3031     *
    3132     * @throws ImagickException
    32      * @global wpdb  $wpdb               WordPress database abstraction object.
    3333     * @global array $_wp_theme_features
    3434     *
     
    3636     */
    3737    public static function debug_data() {
    38         global $wpdb, $_wp_theme_features;
     38        global $_wp_theme_features;
    3939
    4040        // Save few function calls.
     
    693693            'label' => __( 'Current Server time' ),
    694694            'value' => wp_date( 'c', $_SERVER['REQUEST_TIME'] ),
    695         );
    696 
    697         // Populate the database debug fields.
    698         if ( is_object( $wpdb->dbh ) ) {
    699             // mysqli or PDO.
    700             $extension = get_class( $wpdb->dbh );
    701         } else {
    702             // Unknown sql extension.
    703             $extension = null;
    704         }
    705 
    706         $server = $wpdb->get_var( 'SELECT VERSION()' );
    707 
    708         $client_version = $wpdb->dbh->client_info;
    709 
    710         $info['wp-database']['fields']['extension'] = array(
    711             'label' => __( 'Extension' ),
    712             'value' => $extension,
    713         );
    714 
    715         $info['wp-database']['fields']['server_version'] = array(
    716             'label' => __( 'Server version' ),
    717             'value' => $server,
    718         );
    719 
    720         $info['wp-database']['fields']['client_version'] = array(
    721             'label' => __( 'Client version' ),
    722             'value' => $client_version,
    723         );
    724 
    725         $info['wp-database']['fields']['database_user'] = array(
    726             'label'   => __( 'Database username' ),
    727             'value'   => $wpdb->dbuser,
    728             'private' => true,
    729         );
    730 
    731         $info['wp-database']['fields']['database_host'] = array(
    732             'label'   => __( 'Database host' ),
    733             'value'   => $wpdb->dbhost,
    734             'private' => true,
    735         );
    736 
    737         $info['wp-database']['fields']['database_name'] = array(
    738             'label'   => __( 'Database name' ),
    739             'value'   => $wpdb->dbname,
    740             'private' => true,
    741         );
    742 
    743         $info['wp-database']['fields']['database_prefix'] = array(
    744             'label'   => __( 'Table prefix' ),
    745             'value'   => $wpdb->prefix,
    746             'private' => true,
    747         );
    748 
    749         $info['wp-database']['fields']['database_charset'] = array(
    750             'label'   => __( 'Database charset' ),
    751             'value'   => $wpdb->charset,
    752             'private' => true,
    753         );
    754 
    755         $info['wp-database']['fields']['database_collate'] = array(
    756             'label'   => __( 'Database collation' ),
    757             'value'   => $wpdb->collate,
    758             'private' => true,
    759         );
    760 
    761         $info['wp-database']['fields']['max_allowed_packet'] = array(
    762             'label' => __( 'Max allowed packet size' ),
    763             'value' => self::get_mysql_var( 'max_allowed_packet' ),
    764         );
    765 
    766         $info['wp-database']['fields']['max_connections'] = array(
    767             'label' => __( 'Max connections number' ),
    768             'value' => self::get_mysql_var( 'max_connections' ),
    769695        );
    770696
     
    12301156
    12311157        $info['wp-constants']  = self::get_wp_constants();
     1158        $info['wp-database']   = self::get_wp_database();
    12321159        $info['wp-filesystem'] = self::get_wp_filesystem();
    12331160
     
    14491376
    14501377    /**
     1378     * Gets the WordPress database section of the debug data.
     1379     *
     1380     * @since 6.7.0
     1381     *
     1382     * @global wpdb $wpdb WordPress database abstraction object.
     1383     *
     1384     * @return array
     1385     */
     1386    public static function get_wp_database(): array {
     1387        global $wpdb;
     1388
     1389        // Populate the database debug fields.
     1390        if ( is_object( $wpdb->dbh ) ) {
     1391            // mysqli or PDO.
     1392            $extension = get_class( $wpdb->dbh );
     1393        } else {
     1394            // Unknown sql extension.
     1395            $extension = null;
     1396        }
     1397
     1398        $server = $wpdb->get_var( 'SELECT VERSION()' );
     1399
     1400        $client_version = $wpdb->dbh->client_info;
     1401
     1402        $fields = array(
     1403            'extension'          => array(
     1404                'label' => __( 'Database Extension' ),
     1405                'value' => $extension,
     1406            ),
     1407            'server_version'     => array(
     1408                'label' => __( 'Server version' ),
     1409                'value' => $server,
     1410            ),
     1411            'client_version'     => array(
     1412                'label' => __( 'Client version' ),
     1413                'value' => $client_version,
     1414            ),
     1415            'database_user'      => array(
     1416                'label'   => __( 'Database username' ),
     1417                'value'   => $wpdb->dbuser,
     1418                'private' => true,
     1419            ),
     1420            'database_host'      => array(
     1421                'label'   => __( 'Database host' ),
     1422                'value'   => $wpdb->dbhost,
     1423                'private' => true,
     1424            ),
     1425            'database_name'      => array(
     1426                'label'   => __( 'Database name' ),
     1427                'value'   => $wpdb->dbname,
     1428                'private' => true,
     1429            ),
     1430            'database_prefix'    => array(
     1431                'label'   => __( 'Table prefix' ),
     1432                'value'   => $wpdb->prefix,
     1433                'private' => true,
     1434            ),
     1435            'database_charset'   => array(
     1436                'label'   => __( 'Database charset' ),
     1437                'value'   => $wpdb->charset,
     1438                'private' => true,
     1439            ),
     1440            'database_collate'   => array(
     1441                'label'   => __( 'Database collation' ),
     1442                'value'   => $wpdb->collate,
     1443                'private' => true,
     1444            ),
     1445            'max_allowed_packet' => array(
     1446                'label' => __( 'Max allowed packet size' ),
     1447                'value' => self::get_mysql_var( 'max_allowed_packet' ),
     1448            ),
     1449            'max_connections'    => array(
     1450                'label' => __( 'Max connections number' ),
     1451                'value' => self::get_mysql_var( 'max_connections' ),
     1452            ),
     1453        );
     1454
     1455        return array(
     1456            'label'  => __( 'Database' ),
     1457            'fields' => $fields,
     1458        );
     1459    }
     1460
     1461    /**
    14511462     * Gets the file system section of the debug data.
    14521463     *
Note: See TracChangeset for help on using the changeset viewer.