Skip to content

Commit

Permalink
WP_Debug_Data: Extract wp-mu-plugins data into separate method.
Browse files Browse the repository at this point in the history
This is the part five 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 fifth of twelve groups, the `wp-mu-plugins` 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/7305
Discussed in https://core.trac.wordpress.org/ticket/61648

Props apermo, dmsnell.
See #61648.



git-svn-id: https://develop.svn.wordpress.org/trunk@59011 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
dmsnell committed Sep 11, 2024
1 parent 55352ab commit 38243be
Showing 1 changed file with 52 additions and 42 deletions.
94 changes: 52 additions & 42 deletions src/wp-admin/includes/class-wp-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function debug_data() {
'wp-active-theme' => array(),
'wp-parent-theme' => array(),
'wp-themes-inactive' => array(),
'wp-mu-plugins' => array(),
'wp-mu-plugins' => self::get_wp_mu_plugins(),
'wp-plugins-active' => array(),
'wp-plugins-inactive' => array(),
'wp-media' => array(),
Expand Down Expand Up @@ -199,12 +199,6 @@ public static function debug_data() {
'fields' => array(),
);

$info['wp-mu-plugins'] = array(
'label' => __( 'Must Use Plugins' ),
'show_count' => true,
'fields' => array(),
);

$info['wp-plugins-active'] = array(
'label' => __( 'Active Plugins' ),
'show_count' => true,
Expand Down Expand Up @@ -540,41 +534,6 @@ public static function debug_data() {
'debug' => $gs_debug,
);

// List must use plugins if there are any.
$mu_plugins = get_mu_plugins();

foreach ( $mu_plugins as $plugin_path => $plugin ) {
$plugin_version = $plugin['Version'];
$plugin_author = $plugin['Author'];

$plugin_version_string = __( 'No version or author information is available.' );
$plugin_version_string_debug = 'author: (undefined), version: (undefined)';

if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
/* translators: 1: Plugin version number. 2: Plugin author name. */
$plugin_version_string = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
$plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
} else {
if ( ! empty( $plugin_author ) ) {
/* translators: %s: Plugin author name. */
$plugin_version_string = sprintf( __( 'By %s' ), $plugin_author );
$plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
}

if ( ! empty( $plugin_version ) ) {
/* translators: %s: Plugin version number. */
$plugin_version_string = sprintf( __( 'Version %s' ), $plugin_version );
$plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
}
}

$info['wp-mu-plugins']['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
'label' => $plugin['Name'],
'value' => $plugin_version_string,
'debug' => $plugin_version_string_debug,
);
}

// List all available plugins.
$plugins = get_plugins();
$plugin_updates = get_plugin_updates();
Expand Down Expand Up @@ -1257,6 +1216,57 @@ public static function get_wp_server(): array {
);
}

/**
* Gets the WordPress plugins section of the debug data.
*
* @since 6.7.0
*
* @return array
*/
public static function get_wp_mu_plugins(): array {
// List must use plugins if there are any.
$mu_plugins = get_mu_plugins();
$fields = array();

foreach ( $mu_plugins as $plugin_path => $plugin ) {
$plugin_version = $plugin['Version'];
$plugin_author = $plugin['Author'];

$plugin_version_string = __( 'No version or author information is available.' );
$plugin_version_string_debug = 'author: (undefined), version: (undefined)';

if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
/* translators: 1: Plugin version number. 2: Plugin author name. */
$plugin_version_string = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
$plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
} else {
if ( ! empty( $plugin_author ) ) {
/* translators: %s: Plugin author name. */
$plugin_version_string = sprintf( __( 'By %s' ), $plugin_author );
$plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
}

if ( ! empty( $plugin_version ) ) {
/* translators: %s: Plugin version number. */
$plugin_version_string = sprintf( __( 'Version %s' ), $plugin_version );
$plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
}
}

$fields[ sanitize_text_field( $plugin['Name'] ) ] = array(
'label' => $plugin['Name'],
'value' => $plugin_version_string,
'debug' => $plugin_version_string_debug,
);
}

return array(
'label' => __( 'Must Use Plugins' ),
'show_count' => true,
'fields' => $fields,
);
}

/**
* Gets the WordPress constants section of the debug data.
*
Expand Down

0 comments on commit 38243be

Please sign in to comment.