[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> class-wp-debug-data.php (source)

   1  <?php
   2  /**
   3   * Class for providing debug data based on a users WordPress environment.
   4   *
   5   * @package WordPress
   6   * @subpackage Site_Health
   7   * @since 5.2.0
   8   */
   9  
  10  #[AllowDynamicProperties]
  11  class WP_Debug_Data {
  12      /**
  13       * Calls all core functions to check for updates.
  14       *
  15       * @since 5.2.0
  16       */
  17  	public static function check_for_updates() {
  18          wp_version_check();
  19          wp_update_plugins();
  20          wp_update_themes();
  21      }
  22  
  23      /**
  24       * Static function for generating site debug data when required.
  25       *
  26       * @since 5.2.0
  27       * @since 5.3.0 Added database charset, database collation,
  28       *              and timezone information.
  29       * @since 5.5.0 Added pretty permalinks support information.
  30       * @since 6.7.0 Modularized into separate theme-oriented methods.
  31       *
  32       * @throws ImagickException
  33       *
  34       * @return array The debug data for the site.
  35       */
  36  	public static function debug_data() {
  37          /*
  38           * Set up the array that holds all debug information.
  39           *
  40           * When iterating through the debug data, the ordering of the sections
  41           * occurs in insertion-order of the assignments into this array.
  42           *
  43           * This is the single assignment of the sections before filtering. Null-entries will
  44           * be automatically be removed.
  45           */
  46          $info = array(
  47              'wp-core'             => self::get_wp_core(),
  48              'wp-paths-sizes'      => self::get_wp_paths_sizes(),
  49              'wp-dropins'          => self::get_wp_dropins(),
  50              'wp-active-theme'     => self::get_wp_active_theme(),
  51              'wp-parent-theme'     => self::get_wp_parent_theme(),
  52              'wp-themes-inactive'  => self::get_wp_themes_inactive(),
  53              'wp-mu-plugins'       => self::get_wp_mu_plugins(),
  54              'wp-plugins-active'   => self::get_wp_plugins_active(),
  55              'wp-plugins-inactive' => self::get_wp_plugins_inactive(),
  56              'wp-media'            => self::get_wp_media(),
  57              'wp-server'           => self::get_wp_server(),
  58              'wp-database'         => self::get_wp_database(),
  59              'wp-constants'        => self::get_wp_constants(),
  60              'wp-filesystem'       => self::get_wp_filesystem(),
  61          );
  62  
  63          /*
  64           * Remove null elements from the array. The individual methods are
  65           * allowed to return `null`, which communicates that the category
  66           * of debug data isn't relevant and shouldn't be passed through.
  67           */
  68          $info = array_filter(
  69              $info,
  70              static function ( $section ) {
  71                  return isset( $section );
  72              }
  73          );
  74  
  75          /**
  76           * Filters the debug information shown on the Tools -> Site Health -> Info screen.
  77           *
  78           * Plugin or themes may wish to introduce their own debug information without creating
  79           * additional admin pages. They can utilize this filter to introduce their own sections
  80           * or add more data to existing sections.
  81           *
  82           * Array keys for sections added by core are all prefixed with `wp-`. Plugins and themes
  83           * should use their own slug as a prefix, both for consistency as well as avoiding
  84           * key collisions. Note that the array keys are used as labels for the copied data.
  85           *
  86           * All strings are expected to be plain text except `$description` that can contain
  87           * inline HTML tags (see below).
  88           *
  89           * @since 5.2.0
  90           *
  91           * @param array $args {
  92           *     The debug information to be added to the core information page.
  93           *
  94           *     This is an associative multi-dimensional array, up to three levels deep.
  95           *     The topmost array holds the sections, keyed by section ID.
  96           *
  97           *     @type array ...$0 {
  98           *         Each section has a `$fields` associative array (see below), and each `$value` in `$fields`
  99           *         can be another associative array of name/value pairs when there is more structured data
 100           *         to display.
 101           *
 102           *         @type string $label       Required. The title for this section of the debug output.
 103           *         @type string $description Optional. A description for your information section which
 104           *                                   may contain basic HTML markup, inline tags only as it is
 105           *                                   outputted in a paragraph.
 106           *         @type bool   $show_count  Optional. If set to `true`, the amount of fields will be included
 107           *                                   in the title for this section. Default false.
 108           *         @type bool   $private     Optional. If set to `true`, the section and all associated fields
 109           *                                   will be excluded from the copied data. Default false.
 110           *         @type array  $fields {
 111           *             Required. An associative array containing the fields to be displayed in the section,
 112           *             keyed by field ID.
 113           *
 114           *             @type array ...$0 {
 115           *                 An associative array containing the data to be displayed for the field.
 116           *
 117           *                 @type string $label    Required. The label for this piece of information.
 118           *                 @type mixed  $value    Required. The output that is displayed for this field.
 119           *                                        Text should be translated. Can be an associative array
 120           *                                        that is displayed as name/value pairs.
 121           *                                        Accepted types: `string|int|float|(string|int|float)[]`.
 122           *                 @type string $debug    Optional. The output that is used for this field when
 123           *                                        the user copies the data. It should be more concise and
 124           *                                        not translated. If not set, the content of `$value`
 125           *                                        is used. Note that the array keys are used as labels
 126           *                                        for the copied data.
 127           *                 @type bool   $private  Optional. If set to `true`, the field will be excluded
 128           *                                        from the copied data, allowing you to show, for example,
 129           *                                        API keys here. Default false.
 130           *             }
 131           *         }
 132           *     }
 133           * }
 134           */
 135          $info = apply_filters( 'debug_information', $info );
 136  
 137          return $info;
 138      }
 139  
 140      /**
 141       * Gets the WordPress core section of the debug data.
 142       *
 143       * @since 6.7.0
 144       *
 145       * @return array
 146       */
 147  	private static function get_wp_core(): array {
 148          // Save few function calls.
 149          $permalink_structure    = get_option( 'permalink_structure' );
 150          $is_ssl                 = is_ssl();
 151          $users_can_register     = get_option( 'users_can_register' );
 152          $blog_public            = get_option( 'blog_public' );
 153          $default_comment_status = get_option( 'default_comment_status' );
 154          $environment_type       = wp_get_environment_type();
 155          $core_version           = wp_get_wp_version();
 156          $core_updates           = get_core_updates();
 157          $core_update_needed     = '';
 158  
 159          if ( is_array( $core_updates ) ) {
 160              foreach ( $core_updates as $core => $update ) {
 161                  if ( 'upgrade' === $update->response ) {
 162                      /* translators: %s: Latest WordPress version number. */
 163                      $core_update_needed = ' ' . sprintf( __( '(Latest version: %s)' ), $update->version );
 164                  } else {
 165                      $core_update_needed = '';
 166                  }
 167              }
 168          }
 169  
 170          $fields = array(
 171              'version'                => array(
 172                  'label' => __( 'Version' ),
 173                  'value' => $core_version . $core_update_needed,
 174                  'debug' => $core_version,
 175              ),
 176              'site_language'          => array(
 177                  'label' => __( 'Site Language' ),
 178                  'value' => get_locale(),
 179              ),
 180              'user_language'          => array(
 181                  'label' => __( 'User Language' ),
 182                  'value' => get_user_locale(),
 183              ),
 184              'timezone'               => array(
 185                  'label' => __( 'Timezone' ),
 186                  'value' => wp_timezone_string(),
 187              ),
 188              'home_url'               => array(
 189                  'label'   => __( 'Home URL' ),
 190                  'value'   => get_bloginfo( 'url' ),
 191                  'private' => true,
 192              ),
 193              'site_url'               => array(
 194                  'label'   => __( 'Site URL' ),
 195                  'value'   => get_bloginfo( 'wpurl' ),
 196                  'private' => true,
 197              ),
 198              'permalink'              => array(
 199                  'label' => __( 'Permalink structure' ),
 200                  'value' => $permalink_structure ? $permalink_structure : __( 'No permalink structure set' ),
 201                  'debug' => $permalink_structure,
 202              ),
 203              'https_status'           => array(
 204                  'label' => __( 'Is this site using HTTPS?' ),
 205                  'value' => $is_ssl ? __( 'Yes' ) : __( 'No' ),
 206                  'debug' => $is_ssl,
 207              ),
 208              'multisite'              => array(
 209                  'label' => __( 'Is this a multisite?' ),
 210                  'value' => is_multisite() ? __( 'Yes' ) : __( 'No' ),
 211                  'debug' => is_multisite(),
 212              ),
 213              'user_registration'      => array(
 214                  'label' => __( 'Can anyone register on this site?' ),
 215                  'value' => $users_can_register ? __( 'Yes' ) : __( 'No' ),
 216                  'debug' => $users_can_register,
 217              ),
 218              'blog_public'            => array(
 219                  'label' => __( 'Is this site discouraging search engines?' ),
 220                  'value' => $blog_public ? __( 'No' ) : __( 'Yes' ),
 221                  'debug' => $blog_public,
 222              ),
 223              'default_comment_status' => array(
 224                  'label' => __( 'Default comment status' ),
 225                  'value' => 'open' === $default_comment_status ? _x( 'Open', 'comment status' ) : _x( 'Closed', 'comment status' ),
 226                  'debug' => $default_comment_status,
 227              ),
 228              'environment_type'       => array(
 229                  'label' => __( 'Environment type' ),
 230                  'value' => $environment_type,
 231                  'debug' => $environment_type,
 232              ),
 233          );
 234  
 235          // Conditionally add debug information for multisite setups.
 236          if ( is_multisite() ) {
 237              $site_id = get_current_blog_id();
 238  
 239              $fields['site_id'] = array(
 240                  'label' => __( 'Site ID' ),
 241                  'value' => $site_id,
 242                  'debug' => $site_id,
 243              );
 244  
 245              $network_query = new WP_Network_Query();
 246              $network_ids   = $network_query->query(
 247                  array(
 248                      'fields'        => 'ids',
 249                      'number'        => 100,
 250                      'no_found_rows' => false,
 251                  )
 252              );
 253  
 254              $site_count = 0;
 255              foreach ( $network_ids as $network_id ) {
 256                  $site_count += get_blog_count( $network_id );
 257              }
 258  
 259              $fields['site_count'] = array(
 260                  'label' => __( 'Site count' ),
 261                  'value' => $site_count,
 262              );
 263  
 264              $fields['network_count'] = array(
 265                  'label' => __( 'Network count' ),
 266                  'value' => $network_query->found_networks,
 267              );
 268          }
 269  
 270          $fields['user_count'] = array(
 271              'label' => __( 'User count' ),
 272              'value' => get_user_count(),
 273          );
 274  
 275          // WordPress features requiring processing.
 276          $wp_dotorg = wp_remote_get( 'https://wordpress.org', array( 'timeout' => 10 ) );
 277  
 278          if ( ! is_wp_error( $wp_dotorg ) ) {
 279              $fields['dotorg_communication'] = array(
 280                  'label' => __( 'Communication with WordPress.org' ),
 281                  'value' => __( 'WordPress.org is reachable' ),
 282                  'debug' => 'true',
 283              );
 284          } else {
 285              $fields['dotorg_communication'] = array(
 286                  'label' => __( 'Communication with WordPress.org' ),
 287                  'value' => sprintf(
 288                  /* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
 289                      __( 'Unable to reach WordPress.org at %1$s: %2$s' ),
 290                      gethostbyname( 'wordpress.org' ),
 291                      $wp_dotorg->get_error_message()
 292                  ),
 293                  'debug' => $wp_dotorg->get_error_message(),
 294              );
 295          }
 296  
 297          return array(
 298              'label'  => __( 'WordPress' ),
 299              'fields' => $fields,
 300          );
 301      }
 302  
 303      /**
 304       * Gets the WordPress drop-in section of the debug data.
 305       *
 306       * @since 6.7.0
 307       *
 308       * @return array
 309       */
 310  	private static function get_wp_dropins(): array {
 311          // Get a list of all drop-in replacements.
 312          $dropins = get_dropins();
 313  
 314          // Get drop-ins descriptions.
 315          $dropin_descriptions = _get_dropins();
 316  
 317          $fields = array();
 318          foreach ( $dropins as $dropin_key => $dropin ) {
 319              $fields[ sanitize_text_field( $dropin_key ) ] = array(
 320                  'label' => $dropin_key,
 321                  'value' => $dropin_descriptions[ $dropin_key ][0],
 322                  'debug' => 'true',
 323              );
 324          }
 325  
 326          return array(
 327              'label'       => __( 'Drop-ins' ),
 328              'show_count'  => true,
 329              'description' => sprintf(
 330                  /* translators: %s: wp-content directory name. */
 331                  __( 'Drop-ins are single files, found in the %s directory, that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ),
 332                  '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>'
 333              ),
 334              'fields'      => $fields,
 335          );
 336      }
 337  
 338      /**
 339       * Gets the WordPress server section of the debug data.
 340       *
 341       * @since 6.7.0
 342       *
 343       * @return array
 344       */
 345  	private static function get_wp_server(): array {
 346          // Populate the server debug fields.
 347          if ( function_exists( 'php_uname' ) ) {
 348              $server_architecture = sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) );
 349          } else {
 350              $server_architecture = 'unknown';
 351          }
 352  
 353          $php_version_debug = PHP_VERSION;
 354          // Whether PHP supports 64-bit.
 355          $php64bit = ( PHP_INT_SIZE * 8 === 64 );
 356  
 357          $php_version = sprintf(
 358              '%s %s',
 359              $php_version_debug,
 360              ( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
 361          );
 362  
 363          if ( $php64bit ) {
 364              $php_version_debug .= ' 64bit';
 365          }
 366  
 367          $fields = array();
 368  
 369          $fields['server_architecture'] = array(
 370              'label' => __( 'Server architecture' ),
 371              'value' => ( 'unknown' !== $server_architecture ? $server_architecture : __( 'Unable to determine server architecture' ) ),
 372              'debug' => $server_architecture,
 373          );
 374          $fields['httpd_software']      = array(
 375              'label' => __( 'Web server' ),
 376              'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used' ) ),
 377              'debug' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'unknown' ),
 378          );
 379          $fields['php_version']         = array(
 380              'label' => __( 'PHP version' ),
 381              'value' => $php_version,
 382              'debug' => $php_version_debug,
 383          );
 384          $fields['php_sapi']            = array(
 385              'label' => __( 'PHP SAPI' ),
 386              'value' => PHP_SAPI,
 387              'debug' => PHP_SAPI,
 388          );
 389  
 390          // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
 391          if ( ! function_exists( 'ini_get' ) ) {
 392              $fields['ini_get'] = array(
 393                  'label' => __( 'Server settings' ),
 394                  'value' => sprintf(
 395                  /* translators: %s: ini_get() */
 396                      __( 'Unable to determine some settings, as the %s function has been disabled.' ),
 397                      'ini_get()'
 398                  ),
 399                  'debug' => 'ini_get() is disabled',
 400              );
 401          } else {
 402              $fields['max_input_variables'] = array(
 403                  'label' => __( 'PHP max input variables' ),
 404                  'value' => ini_get( 'max_input_vars' ),
 405              );
 406              $fields['time_limit']          = array(
 407                  'label' => __( 'PHP time limit' ),
 408                  'value' => ini_get( 'max_execution_time' ),
 409              );
 410  
 411              if ( WP_Site_Health::get_instance()->php_memory_limit !== ini_get( 'memory_limit' ) ) {
 412                  $fields['memory_limit']       = array(
 413                      'label' => __( 'PHP memory limit' ),
 414                      'value' => WP_Site_Health::get_instance()->php_memory_limit,
 415                  );
 416                  $fields['admin_memory_limit'] = array(
 417                      'label' => __( 'PHP memory limit (only for admin screens)' ),
 418                      'value' => ini_get( 'memory_limit' ),
 419                  );
 420              } else {
 421                  $fields['memory_limit'] = array(
 422                      'label' => __( 'PHP memory limit' ),
 423                      'value' => ini_get( 'memory_limit' ),
 424                  );
 425              }
 426  
 427              $fields['max_input_time']      = array(
 428                  'label' => __( 'Max input time' ),
 429                  'value' => ini_get( 'max_input_time' ),
 430              );
 431              $fields['upload_max_filesize'] = array(
 432                  'label' => __( 'Upload max filesize' ),
 433                  'value' => ini_get( 'upload_max_filesize' ),
 434              );
 435              $fields['php_post_max_size']   = array(
 436                  'label' => __( 'PHP post max size' ),
 437                  'value' => ini_get( 'post_max_size' ),
 438              );
 439          }
 440  
 441          if ( function_exists( 'curl_version' ) ) {
 442              $curl = curl_version();
 443  
 444              $fields['curl_version'] = array(
 445                  'label' => __( 'cURL version' ),
 446                  'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ),
 447              );
 448          } else {
 449              $fields['curl_version'] = array(
 450                  'label' => __( 'cURL version' ),
 451                  'value' => __( 'Not available' ),
 452                  'debug' => 'not available',
 453              );
 454          }
 455  
 456          // SUHOSIN.
 457          $suhosin_loaded = ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) );
 458  
 459          $fields['suhosin'] = array(
 460              'label' => __( 'Is SUHOSIN installed?' ),
 461              'value' => ( $suhosin_loaded ? __( 'Yes' ) : __( 'No' ) ),
 462              'debug' => $suhosin_loaded,
 463          );
 464  
 465          // Imagick.
 466          $imagick_loaded = extension_loaded( 'imagick' );
 467  
 468          $fields['imagick_availability'] = array(
 469              'label' => __( 'Is the Imagick library available?' ),
 470              'value' => ( $imagick_loaded ? __( 'Yes' ) : __( 'No' ) ),
 471              'debug' => $imagick_loaded,
 472          );
 473  
 474          // Pretty permalinks.
 475          $pretty_permalinks_supported = got_url_rewrite();
 476  
 477          $fields['pretty_permalinks'] = array(
 478              'label' => __( 'Are pretty permalinks supported?' ),
 479              'value' => ( $pretty_permalinks_supported ? __( 'Yes' ) : __( 'No' ) ),
 480              'debug' => $pretty_permalinks_supported,
 481          );
 482  
 483          // Check if a .htaccess file exists.
 484          if ( is_file( ABSPATH . '.htaccess' ) ) {
 485              // If the file exists, grab the content of it.
 486              $htaccess_content = file_get_contents( ABSPATH . '.htaccess' );
 487  
 488              // Filter away the core WordPress rules.
 489              $filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) );
 490              $filtered_htaccess_content = ! empty( $filtered_htaccess_content );
 491  
 492              if ( $filtered_htaccess_content ) {
 493                  /* translators: %s: .htaccess */
 494                  $htaccess_rules_string = sprintf( __( 'Custom rules have been added to your %s file.' ), '.htaccess' );
 495              } else {
 496                  /* translators: %s: .htaccess */
 497                  $htaccess_rules_string = sprintf( __( 'Your %s file contains only core WordPress features.' ), '.htaccess' );
 498              }
 499  
 500              $fields['htaccess_extra_rules'] = array(
 501                  'label' => __( '.htaccess rules' ),
 502                  'value' => $htaccess_rules_string,
 503                  'debug' => $filtered_htaccess_content,
 504              );
 505          }
 506  
 507          // Check if a robots.txt file exists.
 508          if ( is_file( ABSPATH . 'robots.txt' ) ) {
 509              // If the file exists, turn debug info to true.
 510              $robotstxt_debug = true;
 511  
 512              /* translators: %s: robots.txt */
 513              $robotstxt_string = sprintf( __( 'There is a static %s file in your installation folder. WordPress cannot dynamically serve one.' ), 'robots.txt' );
 514          } elseif ( got_url_rewrite() ) {
 515              // No robots.txt file available and rewrite rules in place, turn debug info to false.
 516              $robotstxt_debug = false;
 517  
 518              /* translators: %s: robots.txt */
 519              $robotstxt_string = sprintf( __( 'Your site is using the dynamic %s file which is generated by WordPress.' ), 'robots.txt' );
 520          } else {
 521              // No robots.txt file, but without rewrite rules WP can't serve one.
 522              $robotstxt_debug = true;
 523  
 524              /* translators: %s: robots.txt */
 525              $robotstxt_string = sprintf( __( 'WordPress cannot dynamically serve a %s file due to a lack of rewrite rule support' ), 'robots.txt' );
 526  
 527          }
 528  
 529          $fields['static_robotstxt_file'] = array(
 530              'label' => __( 'robots.txt' ),
 531              'value' => $robotstxt_string,
 532              'debug' => $robotstxt_debug,
 533          );
 534  
 535          // Server time.
 536          $date = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
 537  
 538          $fields['current']     = array(
 539              'label' => __( 'Current time' ),
 540              'value' => $date->format( DateTime::ATOM ),
 541          );
 542          $fields['utc-time']    = array(
 543              'label' => __( 'Current UTC time' ),
 544              'value' => $date->format( DateTime::RFC850 ),
 545          );
 546          $fields['server-time'] = array(
 547              'label' => __( 'Current Server time' ),
 548              'value' => wp_date( 'c', $_SERVER['REQUEST_TIME'] ),
 549          );
 550  
 551          return array(
 552              'label'       => __( 'Server' ),
 553              'description' => __( 'The options shown below relate to your server setup. If changes are required, you may need your web host&#8217;s assistance.' ),
 554              'fields'      => $fields,
 555          );
 556      }
 557  
 558      /**
 559       * Gets the WordPress media section of the debug data.
 560       *
 561       * @since 6.7.0
 562       *
 563       * @throws ImagickException
 564       * @return array
 565       */
 566  	private static function get_wp_media(): array {
 567          // Spare few function calls.
 568          $not_available = __( 'Not available' );
 569  
 570          // Populate the media fields.
 571          $fields['image_editor'] = array(
 572              'label' => __( 'Active editor' ),
 573              'value' => _wp_image_editor_choose(),
 574          );
 575  
 576          // Get ImageMagic information, if available.
 577          if ( class_exists( 'Imagick' ) ) {
 578              // Save the Imagick instance for later use.
 579              $imagick             = new Imagick();
 580              $imagemagick_version = $imagick->getVersion();
 581          } else {
 582              $imagemagick_version = __( 'Not available' );
 583          }
 584  
 585          $fields['imagick_module_version'] = array(
 586              'label' => __( 'ImageMagick version number' ),
 587              'value' => ( is_array( $imagemagick_version ) ? $imagemagick_version['versionNumber'] : $imagemagick_version ),
 588          );
 589  
 590          $fields['imagemagick_version'] = array(
 591              'label' => __( 'ImageMagick version string' ),
 592              'value' => ( is_array( $imagemagick_version ) ? $imagemagick_version['versionString'] : $imagemagick_version ),
 593          );
 594  
 595          $imagick_version = phpversion( 'imagick' );
 596  
 597          $fields['imagick_version'] = array(
 598              'label' => __( 'Imagick version' ),
 599              'value' => ( $imagick_version ) ? $imagick_version : __( 'Not available' ),
 600          );
 601  
 602          if ( ! function_exists( 'ini_get' ) ) {
 603              $fields['ini_get'] = array(
 604                  'label' => __( 'File upload settings' ),
 605                  'value' => sprintf(
 606                  /* translators: %s: ini_get() */
 607                      __( 'Unable to determine some settings, as the %s function has been disabled.' ),
 608                      'ini_get()'
 609                  ),
 610                  'debug' => 'ini_get() is disabled',
 611              );
 612          } else {
 613              // Get the PHP ini directive values.
 614              $file_uploads        = ini_get( 'file_uploads' );
 615              $post_max_size       = ini_get( 'post_max_size' );
 616              $upload_max_filesize = ini_get( 'upload_max_filesize' );
 617              $max_file_uploads    = ini_get( 'max_file_uploads' );
 618              $effective           = min( wp_convert_hr_to_bytes( $post_max_size ), wp_convert_hr_to_bytes( $upload_max_filesize ) );
 619  
 620              // Add info in Media section.
 621              $fields['file_uploads']        = array(
 622                  'label' => __( 'File uploads' ),
 623                  'value' => $file_uploads ? __( 'Enabled' ) : __( 'Disabled' ),
 624                  'debug' => $file_uploads,
 625              );
 626              $fields['post_max_size']       = array(
 627                  'label' => __( 'Max size of post data allowed' ),
 628                  'value' => $post_max_size,
 629              );
 630              $fields['upload_max_filesize'] = array(
 631                  'label' => __( 'Max size of an uploaded file' ),
 632                  'value' => $upload_max_filesize,
 633              );
 634              $fields['max_effective_size']  = array(
 635                  'label' => __( 'Max effective file size' ),
 636                  'value' => size_format( $effective ),
 637              );
 638              $fields['max_file_uploads']    = array(
 639                  'label' => __( 'Max simultaneous file uploads' ),
 640                  'value' => $max_file_uploads,
 641              );
 642          }
 643  
 644          // If Imagick is used as our editor, provide some more information about its limitations.
 645          if ( 'WP_Image_Editor_Imagick' === _wp_image_editor_choose() && isset( $imagick ) && $imagick instanceof Imagick ) {
 646              $limits = array(
 647                  'area'   => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : $not_available ),
 648                  'disk'   => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : $not_available ),
 649                  'file'   => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : $not_available ),
 650                  'map'    => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : $not_available ),
 651                  'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : $not_available ),
 652                  'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : $not_available ),
 653                  'time'   => ( defined( 'imagick::RESOURCETYPE_TIME' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_TIME ) : $not_available ),
 654              );
 655  
 656              $limits_debug = array(
 657                  'imagick::RESOURCETYPE_AREA'   => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : 'not available' ),
 658                  'imagick::RESOURCETYPE_DISK'   => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : 'not available' ),
 659                  'imagick::RESOURCETYPE_FILE'   => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : 'not available' ),
 660                  'imagick::RESOURCETYPE_MAP'    => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : 'not available' ),
 661                  'imagick::RESOURCETYPE_MEMORY' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : 'not available' ),
 662                  'imagick::RESOURCETYPE_THREAD' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : 'not available' ),
 663                  'imagick::RESOURCETYPE_TIME'   => ( defined( 'imagick::RESOURCETYPE_TIME' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_TIME ) : 'not available' ),
 664              );
 665  
 666              $fields['imagick_limits'] = array(
 667                  'label' => __( 'Imagick Resource Limits' ),
 668                  'value' => $limits,
 669                  'debug' => $limits_debug,
 670              );
 671  
 672              try {
 673                  $formats = Imagick::queryFormats( '*' );
 674              } catch ( Exception $e ) {
 675                  $formats = array();
 676              }
 677  
 678              $fields['imagemagick_file_formats'] = array(
 679                  'label' => __( 'ImageMagick supported file formats' ),
 680                  'value' => ( empty( $formats ) ) ? __( 'Unable to determine' ) : implode( ', ', $formats ),
 681                  'debug' => ( empty( $formats ) ) ? 'Unable to determine' : implode( ', ', $formats ),
 682              );
 683          }
 684  
 685          // Get GD information, if available.
 686          if ( function_exists( 'gd_info' ) ) {
 687              $gd = gd_info();
 688          } else {
 689              $gd = false;
 690          }
 691  
 692          $fields['gd_version'] = array(
 693              'label' => __( 'GD version' ),
 694              'value' => ( is_array( $gd ) ? $gd['GD Version'] : $not_available ),
 695              'debug' => ( is_array( $gd ) ? $gd['GD Version'] : 'not available' ),
 696          );
 697  
 698          $gd_image_formats     = array();
 699          $gd_supported_formats = array(
 700              'GIF Create' => 'GIF',
 701              'JPEG'       => 'JPEG',
 702              'PNG'        => 'PNG',
 703              'WebP'       => 'WebP',
 704              'BMP'        => 'BMP',
 705              'AVIF'       => 'AVIF',
 706              'HEIF'       => 'HEIF',
 707              'TIFF'       => 'TIFF',
 708              'XPM'        => 'XPM',
 709          );
 710  
 711          foreach ( $gd_supported_formats as $format_key => $format ) {
 712              $index = $format_key . ' Support';
 713              if ( isset( $gd[ $index ] ) && $gd[ $index ] ) {
 714                  array_push( $gd_image_formats, $format );
 715              }
 716          }
 717  
 718          if ( ! empty( $gd_image_formats ) ) {
 719              $fields['gd_formats'] = array(
 720                  'label' => __( 'GD supported file formats' ),
 721                  'value' => implode( ', ', $gd_image_formats ),
 722              );
 723          }
 724  
 725          // Get Ghostscript information, if available.
 726          if ( function_exists( 'exec' ) ) {
 727              $gs = exec( 'gs --version' );
 728  
 729              if ( empty( $gs ) ) {
 730                  $gs       = $not_available;
 731                  $gs_debug = 'not available';
 732              } else {
 733                  $gs_debug = $gs;
 734              }
 735          } else {
 736              $gs       = __( 'Unable to determine if Ghostscript is installed' );
 737              $gs_debug = 'unknown';
 738          }
 739  
 740          $fields['ghostscript_version'] = array(
 741              'label' => __( 'Ghostscript version' ),
 742              'value' => $gs,
 743              'debug' => $gs_debug,
 744          );
 745  
 746          return array(
 747              'label'  => __( 'Media Handling' ),
 748              'fields' => $fields,
 749          );
 750      }
 751  
 752      /**
 753       * Gets the WordPress MU plugins section of the debug data.
 754       *
 755       * @since 6.7.0
 756       *
 757       * @return array
 758       */
 759  	private static function get_wp_mu_plugins(): array {
 760          // List must use plugins if there are any.
 761          $mu_plugins = get_mu_plugins();
 762          $fields     = array();
 763  
 764          foreach ( $mu_plugins as $plugin_path => $plugin ) {
 765              $plugin_version = $plugin['Version'];
 766              $plugin_author  = $plugin['Author'];
 767  
 768              $plugin_version_string       = __( 'No version or author information is available.' );
 769              $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
 770  
 771              if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
 772                  /* translators: 1: Plugin version number. 2: Plugin author name. */
 773                  $plugin_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
 774                  $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
 775              } else {
 776                  if ( ! empty( $plugin_author ) ) {
 777                      /* translators: %s: Plugin author name. */
 778                      $plugin_version_string       = sprintf( __( 'By %s' ), $plugin_author );
 779                      $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
 780                  }
 781  
 782                  if ( ! empty( $plugin_version ) ) {
 783                      /* translators: %s: Plugin version number. */
 784                      $plugin_version_string       = sprintf( __( 'Version %s' ), $plugin_version );
 785                      $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
 786                  }
 787              }
 788  
 789              $fields[ sanitize_text_field( $plugin['Name'] ) ] = array(
 790                  'label' => $plugin['Name'],
 791                  'value' => $plugin_version_string,
 792                  'debug' => $plugin_version_string_debug,
 793              );
 794          }
 795  
 796          return array(
 797              'label'      => __( 'Must Use Plugins' ),
 798              'show_count' => true,
 799              'fields'     => $fields,
 800          );
 801      }
 802  
 803      /**
 804       * Gets the WordPress paths and sizes section of the debug data.
 805       *
 806       * @since 6.7.0
 807       *
 808       * @return array|null Paths and sizes debug data for single sites,
 809       *                    otherwise `null` for multi-site installs.
 810       */
 811  	private static function get_wp_paths_sizes(): ?array {
 812          if ( is_multisite() ) {
 813              return null;
 814          }
 815  
 816          $loading = __( 'Loading&hellip;' );
 817  
 818          $fields = array(
 819              'wordpress_path' => array(
 820                  'label' => __( 'WordPress directory location' ),
 821                  'value' => untrailingslashit( ABSPATH ),
 822              ),
 823              'wordpress_size' => array(
 824                  'label' => __( 'WordPress directory size' ),
 825                  'value' => $loading,
 826                  'debug' => 'loading...',
 827              ),
 828              'uploads_path'   => array(
 829                  'label' => __( 'Uploads directory location' ),
 830                  'value' => wp_upload_dir()['basedir'],
 831              ),
 832              'uploads_size'   => array(
 833                  'label' => __( 'Uploads directory size' ),
 834                  'value' => $loading,
 835                  'debug' => 'loading...',
 836              ),
 837              'themes_path'    => array(
 838                  'label' => __( 'Themes directory location' ),
 839                  'value' => get_theme_root(),
 840              ),
 841              'themes_size'    => array(
 842                  'label' => __( 'Themes directory size' ),
 843                  'value' => $loading,
 844                  'debug' => 'loading...',
 845              ),
 846              'plugins_path'   => array(
 847                  'label' => __( 'Plugins directory location' ),
 848                  'value' => WP_PLUGIN_DIR,
 849              ),
 850              'plugins_size'   => array(
 851                  'label' => __( 'Plugins directory size' ),
 852                  'value' => $loading,
 853                  'debug' => 'loading...',
 854              ),
 855              'fonts_path'     => array(
 856                  'label' => __( 'Fonts directory location' ),
 857                  'value' => wp_get_font_dir()['basedir'],
 858              ),
 859              'fonts_size'     => array(
 860                  'label' => __( 'Fonts directory size' ),
 861                  'value' => $loading,
 862                  'debug' => 'loading...',
 863              ),
 864              'database_size'  => array(
 865                  'label' => __( 'Database size' ),
 866                  'value' => $loading,
 867                  'debug' => 'loading...',
 868              ),
 869              'total_size'     => array(
 870                  'label' => __( 'Total installation size' ),
 871                  'value' => $loading,
 872                  'debug' => 'loading...',
 873              ),
 874          );
 875  
 876          return array(
 877              /* translators: Filesystem directory paths and storage sizes. */
 878              'label'  => __( 'Directories and Sizes' ),
 879              'fields' => $fields,
 880          );
 881      }
 882  
 883      /**
 884       * Gets the WordPress active plugins section of the debug data.
 885       *
 886       * @since 6.7.0
 887       *
 888       * @return array
 889       */
 890  	private static function get_wp_plugins_active(): array {
 891          return array(
 892              'label'      => __( 'Active Plugins' ),
 893              'show_count' => true,
 894              'fields'     => self::get_wp_plugins_raw_data()['wp-plugins-active'],
 895          );
 896      }
 897  
 898      /**
 899       * Gets the WordPress inactive plugins section of the debug data.
 900       *
 901       * @since 6.7.0
 902       *
 903       * @return array
 904       */
 905  	private static function get_wp_plugins_inactive(): array {
 906          return array(
 907              'label'      => __( 'Inactive Plugins' ),
 908              'show_count' => true,
 909              'fields'     => self::get_wp_plugins_raw_data()['wp-plugins-inactive'],
 910          );
 911      }
 912  
 913      /**
 914       * Gets the raw plugin data for the WordPress active and inactive sections of the debug data.
 915       *
 916       * @since 6.7.0
 917       *
 918       * @return array
 919       */
 920  	private static function get_wp_plugins_raw_data(): array {
 921          // List all available plugins.
 922          $plugins        = get_plugins();
 923          $plugin_updates = get_plugin_updates();
 924          $transient      = get_site_transient( 'update_plugins' );
 925  
 926          $auto_updates = array();
 927          $fields       = array(
 928              'wp-plugins-active'   => array(),
 929              'wp-plugins-inactive' => array(),
 930          );
 931  
 932          $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' );
 933  
 934          if ( $auto_updates_enabled ) {
 935              $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
 936          }
 937  
 938          foreach ( $plugins as $plugin_path => $plugin ) {
 939              $plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';
 940  
 941              $plugin_version = $plugin['Version'];
 942              $plugin_author  = $plugin['Author'];
 943  
 944              $plugin_version_string       = __( 'No version or author information is available.' );
 945              $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
 946  
 947              if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
 948                  /* translators: 1: Plugin version number. 2: Plugin author name. */
 949                  $plugin_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
 950                  $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
 951              } else {
 952                  if ( ! empty( $plugin_author ) ) {
 953                      /* translators: %s: Plugin author name. */
 954                      $plugin_version_string       = sprintf( __( 'By %s' ), $plugin_author );
 955                      $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
 956                  }
 957  
 958                  if ( ! empty( $plugin_version ) ) {
 959                      /* translators: %s: Plugin version number. */
 960                      $plugin_version_string       = sprintf( __( 'Version %s' ), $plugin_version );
 961                      $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
 962                  }
 963              }
 964  
 965              if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
 966                  /* translators: %s: Latest plugin version number. */
 967                  $plugin_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $plugin_updates[ $plugin_path ]->update->new_version );
 968                  $plugin_version_string_debug .= sprintf( ' (latest version: %s)', $plugin_updates[ $plugin_path ]->update->new_version );
 969              }
 970  
 971              if ( $auto_updates_enabled ) {
 972                  if ( isset( $transient->response[ $plugin_path ] ) ) {
 973                      $item = $transient->response[ $plugin_path ];
 974                  } elseif ( isset( $transient->no_update[ $plugin_path ] ) ) {
 975                      $item = $transient->no_update[ $plugin_path ];
 976                  } else {
 977                      $item = array(
 978                          'id'            => $plugin_path,
 979                          'slug'          => '',
 980                          'plugin'        => $plugin_path,
 981                          'new_version'   => '',
 982                          'url'           => '',
 983                          'package'       => '',
 984                          'icons'         => array(),
 985                          'banners'       => array(),
 986                          'banners_rtl'   => array(),
 987                          'tested'        => '',
 988                          'requires_php'  => '',
 989                          'compatibility' => new stdClass(),
 990                      );
 991                      $item = wp_parse_args( $plugin, $item );
 992                  }
 993  
 994                  $auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, (object) $item );
 995  
 996                  if ( ! is_null( $auto_update_forced ) ) {
 997                      $enabled = $auto_update_forced;
 998                  } else {
 999                      $enabled = in_array( $plugin_path, $auto_updates, true );
1000                  }
1001  
1002                  if ( $enabled ) {
1003                      $auto_updates_string = __( 'Auto-updates enabled' );
1004                  } else {
1005                      $auto_updates_string = __( 'Auto-updates disabled' );
1006                  }
1007  
1008                  /**
1009                   * Filters the text string of the auto-updates setting for each plugin in the Site Health debug data.
1010                   *
1011                   * @since 5.5.0
1012                   *
1013                   * @param string $auto_updates_string The string output for the auto-updates column.
1014                   * @param string $plugin_path         The path to the plugin file.
1015                   * @param array  $plugin              An array of plugin data.
1016                   * @param bool   $enabled             Whether auto-updates are enabled for this item.
1017                   */
1018                  $auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled );
1019  
1020                  $plugin_version_string       .= ' | ' . $auto_updates_string;
1021                  $plugin_version_string_debug .= ', ' . $auto_updates_string;
1022              }
1023  
1024              $fields[ $plugin_part ][ sanitize_text_field( $plugin['Name'] ) ] = array(
1025                  'label' => $plugin['Name'],
1026                  'value' => $plugin_version_string,
1027                  'debug' => $plugin_version_string_debug,
1028              );
1029          }
1030  
1031          return $fields;
1032      }
1033  
1034      /**
1035       * Gets the WordPress active theme section of the debug data.
1036       *
1037       * @since 6.7.0
1038       *
1039       * @global array $_wp_theme_features
1040       *
1041       * @return array
1042       */
1043  	private static function get_wp_active_theme(): array {
1044          global $_wp_theme_features;
1045  
1046          // Populate the section for the currently active theme.
1047          $theme_features = array();
1048  
1049          if ( ! empty( $_wp_theme_features ) ) {
1050              foreach ( $_wp_theme_features as $feature => $options ) {
1051                  $theme_features[] = $feature;
1052              }
1053          }
1054  
1055          $active_theme  = wp_get_theme();
1056          $theme_updates = get_theme_updates();
1057          $transient     = get_site_transient( 'update_themes' );
1058  
1059          $active_theme_version       = $active_theme->version;
1060          $active_theme_version_debug = $active_theme_version;
1061  
1062          $auto_updates         = array();
1063          $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
1064          if ( $auto_updates_enabled ) {
1065              $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
1066          }
1067  
1068          if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
1069              $theme_update_new_version = $theme_updates[ $active_theme->stylesheet ]->update['new_version'];
1070  
1071              /* translators: %s: Latest theme version number. */
1072              $active_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_update_new_version );
1073              $active_theme_version_debug .= sprintf( ' (latest version: %s)', $theme_update_new_version );
1074          }
1075  
1076          $active_theme_author_uri = $active_theme->display( 'AuthorURI' );
1077  
1078          if ( $active_theme->parent_theme ) {
1079              $active_theme_parent_theme = sprintf(
1080                  /* translators: 1: Theme name. 2: Theme slug. */
1081                  __( '%1$s (%2$s)' ),
1082                  $active_theme->parent_theme,
1083                  $active_theme->template
1084              );
1085              $active_theme_parent_theme_debug = sprintf(
1086                  '%s (%s)',
1087                  $active_theme->parent_theme,
1088                  $active_theme->template
1089              );
1090          } else {
1091              $active_theme_parent_theme       = __( 'None' );
1092              $active_theme_parent_theme_debug = 'none';
1093          }
1094  
1095          $fields = array(
1096              'name'           => array(
1097                  'label' => __( 'Name' ),
1098                  'value' => sprintf(
1099                      /* translators: 1: Theme name. 2: Theme slug. */
1100                      __( '%1$s (%2$s)' ),
1101                      $active_theme->name,
1102                      $active_theme->stylesheet
1103                  ),
1104              ),
1105              'version'        => array(
1106                  'label' => __( 'Version' ),
1107                  'value' => $active_theme_version,
1108                  'debug' => $active_theme_version_debug,
1109              ),
1110              'author'         => array(
1111                  'label' => __( 'Author' ),
1112                  'value' => wp_kses( $active_theme->author, array() ),
1113              ),
1114              'author_website' => array(
1115                  'label' => __( 'Author website' ),
1116                  'value' => ( $active_theme_author_uri ? $active_theme_author_uri : __( 'Undefined' ) ),
1117                  'debug' => ( $active_theme_author_uri ? $active_theme_author_uri : '(undefined)' ),
1118              ),
1119              'parent_theme'   => array(
1120                  'label' => __( 'Parent theme' ),
1121                  'value' => $active_theme_parent_theme,
1122                  'debug' => $active_theme_parent_theme_debug,
1123              ),
1124              'theme_features' => array(
1125                  'label' => __( 'Theme features' ),
1126                  'value' => implode( ', ', $theme_features ),
1127              ),
1128              'theme_path'     => array(
1129                  'label' => __( 'Theme directory location' ),
1130                  'value' => get_stylesheet_directory(),
1131              ),
1132          );
1133  
1134          if ( $auto_updates_enabled ) {
1135              if ( isset( $transient->response[ $active_theme->stylesheet ] ) ) {
1136                  $item = $transient->response[ $active_theme->stylesheet ];
1137              } elseif ( isset( $transient->no_update[ $active_theme->stylesheet ] ) ) {
1138                  $item = $transient->no_update[ $active_theme->stylesheet ];
1139              } else {
1140                  $item = array(
1141                      'theme'        => $active_theme->stylesheet,
1142                      'new_version'  => $active_theme->version,
1143                      'url'          => '',
1144                      'package'      => '',
1145                      'requires'     => '',
1146                      'requires_php' => '',
1147                  );
1148              }
1149  
1150              $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
1151  
1152              if ( ! is_null( $auto_update_forced ) ) {
1153                  $enabled = $auto_update_forced;
1154              } else {
1155                  $enabled = in_array( $active_theme->stylesheet, $auto_updates, true );
1156              }
1157  
1158              if ( $enabled ) {
1159                  $auto_updates_string = __( 'Enabled' );
1160              } else {
1161                  $auto_updates_string = __( 'Disabled' );
1162              }
1163  
1164              /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
1165              $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled );
1166  
1167              $fields['auto_update'] = array(
1168                  'label' => __( 'Auto-updates' ),
1169                  'value' => $auto_updates_string,
1170                  'debug' => $auto_updates_string,
1171              );
1172          }
1173  
1174          return array(
1175              'label'  => __( 'Active Theme' ),
1176              'fields' => $fields,
1177          );
1178      }
1179  
1180      /**
1181       * Gets the WordPress parent theme section of the debug data.
1182       *
1183       * @since 6.7.0
1184       *
1185       * @return array
1186       */
1187  	private static function get_wp_parent_theme(): array {
1188          $theme_updates = get_theme_updates();
1189          $transient     = get_site_transient( 'update_themes' );
1190  
1191          $auto_updates         = array();
1192          $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
1193          if ( $auto_updates_enabled ) {
1194              $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
1195          }
1196  
1197          $active_theme = wp_get_theme();
1198          $parent_theme = $active_theme->parent();
1199          $fields       = array();
1200  
1201          if ( $parent_theme ) {
1202              $parent_theme_version       = $parent_theme->version;
1203              $parent_theme_version_debug = $parent_theme_version;
1204  
1205              if ( array_key_exists( $parent_theme->stylesheet, $theme_updates ) ) {
1206                  $parent_theme_update_new_version = $theme_updates[ $parent_theme->stylesheet ]->update['new_version'];
1207  
1208                  /* translators: %s: Latest theme version number. */
1209                  $parent_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $parent_theme_update_new_version );
1210                  $parent_theme_version_debug .= sprintf( ' (latest version: %s)', $parent_theme_update_new_version );
1211              }
1212  
1213              $parent_theme_author_uri = $parent_theme->display( 'AuthorURI' );
1214  
1215              $fields = array(
1216                  'name'           => array(
1217                      'label' => __( 'Name' ),
1218                      'value' => sprintf(
1219                          /* translators: 1: Theme name. 2: Theme slug. */
1220                          __( '%1$s (%2$s)' ),
1221                          $parent_theme->name,
1222                          $parent_theme->stylesheet
1223                      ),
1224                  ),
1225                  'version'        => array(
1226                      'label' => __( 'Version' ),
1227                      'value' => $parent_theme_version,
1228                      'debug' => $parent_theme_version_debug,
1229                  ),
1230                  'author'         => array(
1231                      'label' => __( 'Author' ),
1232                      'value' => wp_kses( $parent_theme->author, array() ),
1233                  ),
1234                  'author_website' => array(
1235                      'label' => __( 'Author website' ),
1236                      'value' => ( $parent_theme_author_uri ? $parent_theme_author_uri : __( 'Undefined' ) ),
1237                      'debug' => ( $parent_theme_author_uri ? $parent_theme_author_uri : '(undefined)' ),
1238                  ),
1239                  'theme_path'     => array(
1240                      'label' => __( 'Theme directory location' ),
1241                      'value' => get_template_directory(),
1242                  ),
1243              );
1244  
1245              if ( $auto_updates_enabled ) {
1246                  if ( isset( $transient->response[ $parent_theme->stylesheet ] ) ) {
1247                      $item = $transient->response[ $parent_theme->stylesheet ];
1248                  } elseif ( isset( $transient->no_update[ $parent_theme->stylesheet ] ) ) {
1249                      $item = $transient->no_update[ $parent_theme->stylesheet ];
1250                  } else {
1251                      $item = array(
1252                          'theme'        => $parent_theme->stylesheet,
1253                          'new_version'  => $parent_theme->version,
1254                          'url'          => '',
1255                          'package'      => '',
1256                          'requires'     => '',
1257                          'requires_php' => '',
1258                      );
1259                  }
1260  
1261                  $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
1262  
1263                  if ( ! is_null( $auto_update_forced ) ) {
1264                      $enabled = $auto_update_forced;
1265                  } else {
1266                      $enabled = in_array( $parent_theme->stylesheet, $auto_updates, true );
1267                  }
1268  
1269                  if ( $enabled ) {
1270                      $parent_theme_auto_update_string = __( 'Enabled' );
1271                  } else {
1272                      $parent_theme_auto_update_string = __( 'Disabled' );
1273                  }
1274  
1275                  /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
1276                  $parent_theme_auto_update_string = apply_filters( 'theme_auto_update_debug_string', $parent_theme_auto_update_string, $parent_theme, $enabled );
1277  
1278                  $fields['auto_update'] = array(
1279                      'label' => __( 'Auto-update' ),
1280                      'value' => $parent_theme_auto_update_string,
1281                      'debug' => $parent_theme_auto_update_string,
1282                  );
1283              }
1284          }
1285  
1286          return array(
1287              'label'  => __( 'Parent Theme' ),
1288              'fields' => $fields,
1289          );
1290      }
1291  
1292      /**
1293       * Gets the WordPress inactive themes section of the debug data.
1294       *
1295       * @since 6.7.0
1296       *
1297       * @return array
1298       */
1299  	private static function get_wp_themes_inactive(): array {
1300          $active_theme  = wp_get_theme();
1301          $parent_theme  = $active_theme->parent();
1302          $theme_updates = get_theme_updates();
1303          $transient     = get_site_transient( 'update_themes' );
1304  
1305          $auto_updates         = array();
1306          $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
1307          if ( $auto_updates_enabled ) {
1308              $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
1309          }
1310  
1311          // Populate a list of all themes available in the installation.
1312          $all_themes = wp_get_themes();
1313          $fields     = array();
1314  
1315          foreach ( $all_themes as $theme_slug => $theme ) {
1316              // Exclude the currently active theme from the list of all themes.
1317              if ( $active_theme->stylesheet === $theme_slug ) {
1318                  continue;
1319              }
1320  
1321              // Exclude the currently active parent theme from the list of all themes.
1322              if ( ! empty( $parent_theme ) && $parent_theme->stylesheet === $theme_slug ) {
1323                  continue;
1324              }
1325  
1326              $theme_version = $theme->version;
1327              $theme_author  = $theme->author;
1328  
1329              // Sanitize.
1330              $theme_author = wp_kses( $theme_author, array() );
1331  
1332              $theme_version_string       = __( 'No version or author information is available.' );
1333              $theme_version_string_debug = 'undefined';
1334  
1335              if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) {
1336                  /* translators: 1: Theme version number. 2: Theme author name. */
1337                  $theme_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $theme_version, $theme_author );
1338                  $theme_version_string_debug = sprintf( 'version: %s, author: %s', $theme_version, $theme_author );
1339              } else {
1340                  if ( ! empty( $theme_author ) ) {
1341                      /* translators: %s: Theme author name. */
1342                      $theme_version_string       = sprintf( __( 'By %s' ), $theme_author );
1343                      $theme_version_string_debug = sprintf( 'author: %s, version: (undefined)', $theme_author );
1344                  }
1345  
1346                  if ( ! empty( $theme_version ) ) {
1347                      /* translators: %s: Theme version number. */
1348                      $theme_version_string       = sprintf( __( 'Version %s' ), $theme_version );
1349                      $theme_version_string_debug = sprintf( 'author: (undefined), version: %s', $theme_version );
1350                  }
1351              }
1352  
1353              if ( array_key_exists( $theme_slug, $theme_updates ) ) {
1354                  /* translators: %s: Latest theme version number. */
1355                  $theme_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $theme_slug ]->update['new_version'] );
1356                  $theme_version_string_debug .= sprintf( ' (latest version: %s)', $theme_updates[ $theme_slug ]->update['new_version'] );
1357              }
1358  
1359              if ( $auto_updates_enabled ) {
1360                  if ( isset( $transient->response[ $theme_slug ] ) ) {
1361                      $item = $transient->response[ $theme_slug ];
1362                  } elseif ( isset( $transient->no_update[ $theme_slug ] ) ) {
1363                      $item = $transient->no_update[ $theme_slug ];
1364                  } else {
1365                      $item = array(
1366                          'theme'        => $theme_slug,
1367                          'new_version'  => $theme->version,
1368                          'url'          => '',
1369                          'package'      => '',
1370                          'requires'     => '',
1371                          'requires_php' => '',
1372                      );
1373                  }
1374  
1375                  $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );
1376  
1377                  if ( ! is_null( $auto_update_forced ) ) {
1378                      $enabled = $auto_update_forced;
1379                  } else {
1380                      $enabled = in_array( $theme_slug, $auto_updates, true );
1381                  }
1382  
1383                  if ( $enabled ) {
1384                      $auto_updates_string = __( 'Auto-updates enabled' );
1385                  } else {
1386                      $auto_updates_string = __( 'Auto-updates disabled' );
1387                  }
1388  
1389                  /**
1390                   * Filters the text string of the auto-updates setting for each theme in the Site Health debug data.
1391                   *
1392                   * @since 5.5.0
1393                   *
1394                   * @param string   $auto_updates_string The string output for the auto-updates column.
1395                   * @param WP_Theme $theme               An object of theme data.
1396                   * @param bool     $enabled             Whether auto-updates are enabled for this item.
1397                   */
1398                  $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled );
1399  
1400                  $theme_version_string       .= ' | ' . $auto_updates_string;
1401                  $theme_version_string_debug .= ', ' . $auto_updates_string;
1402              }
1403  
1404              $fields[ sanitize_text_field( $theme->name ) ] = array(
1405                  'label' => sprintf(
1406                      /* translators: 1: Theme name. 2: Theme slug. */
1407                      __( '%1$s (%2$s)' ),
1408                      $theme->name,
1409                      $theme_slug
1410                  ),
1411                  'value' => $theme_version_string,
1412                  'debug' => $theme_version_string_debug,
1413              );
1414          }
1415  
1416          return array(
1417              'label'      => __( 'Inactive Themes' ),
1418              'show_count' => true,
1419              'fields'     => $fields,
1420          );
1421      }
1422  
1423      /**
1424       * Gets the WordPress constants section of the debug data.
1425       *
1426       * @since 6.7.0
1427       *
1428       * @return array
1429       */
1430  	private static function get_wp_constants(): array {
1431          // Check if WP_DEBUG_LOG is set.
1432          $wp_debug_log_value = __( 'Disabled' );
1433          if ( is_string( WP_DEBUG_LOG ) ) {
1434              $wp_debug_log_value = WP_DEBUG_LOG;
1435          } elseif ( WP_DEBUG_LOG ) {
1436              $wp_debug_log_value = __( 'Enabled' );
1437          }
1438  
1439          // Check CONCATENATE_SCRIPTS.
1440          if ( defined( 'CONCATENATE_SCRIPTS' ) ) {
1441              $concatenate_scripts       = CONCATENATE_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' );
1442              $concatenate_scripts_debug = CONCATENATE_SCRIPTS ? 'true' : 'false';
1443          } else {
1444              $concatenate_scripts       = __( 'Undefined' );
1445              $concatenate_scripts_debug = 'undefined';
1446          }
1447  
1448          // Check COMPRESS_SCRIPTS.
1449          if ( defined( 'COMPRESS_SCRIPTS' ) ) {
1450              $compress_scripts       = COMPRESS_SCRIPTS ? __( 'Enabled' ) : __( 'Disabled' );
1451              $compress_scripts_debug = COMPRESS_SCRIPTS ? 'true' : 'false';
1452          } else {
1453              $compress_scripts       = __( 'Undefined' );
1454              $compress_scripts_debug = 'undefined';
1455          }
1456  
1457          // Check COMPRESS_CSS.
1458          if ( defined( 'COMPRESS_CSS' ) ) {
1459              $compress_css       = COMPRESS_CSS ? __( 'Enabled' ) : __( 'Disabled' );
1460              $compress_css_debug = COMPRESS_CSS ? 'true' : 'false';
1461          } else {
1462              $compress_css       = __( 'Undefined' );
1463              $compress_css_debug = 'undefined';
1464          }
1465  
1466          // Check WP_ENVIRONMENT_TYPE.
1467          if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
1468              $wp_environment_type       = WP_ENVIRONMENT_TYPE ? WP_ENVIRONMENT_TYPE : __( 'Empty value' );
1469              $wp_environment_type_debug = WP_ENVIRONMENT_TYPE;
1470          } else {
1471              $wp_environment_type       = __( 'Undefined' );
1472              $wp_environment_type_debug = 'undefined';
1473          }
1474  
1475          // Check DB_COLLATE.
1476          if ( defined( 'DB_COLLATE' ) ) {
1477              $db_collate       = DB_COLLATE ? DB_COLLATE : __( 'Empty value' );
1478              $db_collate_debug = DB_COLLATE;
1479          } else {
1480              $db_collate       = __( 'Undefined' );
1481              $db_collate_debug = 'undefined';
1482          }
1483  
1484          $fields = array(
1485              'ABSPATH'             => array(
1486                  'label'   => 'ABSPATH',
1487                  'value'   => ABSPATH,
1488                  'private' => true,
1489              ),
1490              'WP_HOME'             => array(
1491                  'label' => 'WP_HOME',
1492                  'value' => ( defined( 'WP_HOME' ) ? WP_HOME : __( 'Undefined' ) ),
1493                  'debug' => ( defined( 'WP_HOME' ) ? WP_HOME : 'undefined' ),
1494              ),
1495              'WP_SITEURL'          => array(
1496                  'label' => 'WP_SITEURL',
1497                  'value' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : __( 'Undefined' ) ),
1498                  'debug' => ( defined( 'WP_SITEURL' ) ? WP_SITEURL : 'undefined' ),
1499              ),
1500              'WP_CONTENT_DIR'      => array(
1501                  'label' => 'WP_CONTENT_DIR',
1502                  'value' => WP_CONTENT_DIR,
1503              ),
1504              'WP_PLUGIN_DIR'       => array(
1505                  'label' => 'WP_PLUGIN_DIR',
1506                  'value' => WP_PLUGIN_DIR,
1507              ),
1508              'WP_MEMORY_LIMIT'     => array(
1509                  'label' => 'WP_MEMORY_LIMIT',
1510                  'value' => WP_MEMORY_LIMIT,
1511              ),
1512              'WP_MAX_MEMORY_LIMIT' => array(
1513                  'label' => 'WP_MAX_MEMORY_LIMIT',
1514                  'value' => WP_MAX_MEMORY_LIMIT,
1515              ),
1516              'WP_DEBUG'            => array(
1517                  'label' => 'WP_DEBUG',
1518                  'value' => WP_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ),
1519                  'debug' => WP_DEBUG,
1520              ),
1521              'WP_DEBUG_DISPLAY'    => array(
1522                  'label' => 'WP_DEBUG_DISPLAY',
1523                  'value' => WP_DEBUG_DISPLAY ? __( 'Enabled' ) : __( 'Disabled' ),
1524                  'debug' => WP_DEBUG_DISPLAY,
1525              ),
1526              'WP_DEBUG_LOG'        => array(
1527                  'label' => 'WP_DEBUG_LOG',
1528                  'value' => $wp_debug_log_value,
1529                  'debug' => WP_DEBUG_LOG,
1530              ),
1531              'SCRIPT_DEBUG'        => array(
1532                  'label' => 'SCRIPT_DEBUG',
1533                  'value' => SCRIPT_DEBUG ? __( 'Enabled' ) : __( 'Disabled' ),
1534                  'debug' => SCRIPT_DEBUG,
1535              ),
1536              'WP_CACHE'            => array(
1537                  'label' => 'WP_CACHE',
1538                  'value' => WP_CACHE ? __( 'Enabled' ) : __( 'Disabled' ),
1539                  'debug' => WP_CACHE,
1540              ),
1541              'CONCATENATE_SCRIPTS' => array(
1542                  'label' => 'CONCATENATE_SCRIPTS',
1543                  'value' => $concatenate_scripts,
1544                  'debug' => $concatenate_scripts_debug,
1545              ),
1546              'COMPRESS_SCRIPTS'    => array(
1547                  'label' => 'COMPRESS_SCRIPTS',
1548                  'value' => $compress_scripts,
1549                  'debug' => $compress_scripts_debug,
1550              ),
1551              'COMPRESS_CSS'        => array(
1552                  'label' => 'COMPRESS_CSS',
1553                  'value' => $compress_css,
1554                  'debug' => $compress_css_debug,
1555              ),
1556              'WP_ENVIRONMENT_TYPE' => array(
1557                  'label' => 'WP_ENVIRONMENT_TYPE',
1558                  'value' => $wp_environment_type,
1559                  'debug' => $wp_environment_type_debug,
1560              ),
1561              'WP_DEVELOPMENT_MODE' => array(
1562                  'label' => 'WP_DEVELOPMENT_MODE',
1563                  'value' => WP_DEVELOPMENT_MODE ? WP_DEVELOPMENT_MODE : __( 'Disabled' ),
1564                  'debug' => WP_DEVELOPMENT_MODE,
1565              ),
1566              'DB_CHARSET'          => array(
1567                  'label' => 'DB_CHARSET',
1568                  'value' => ( defined( 'DB_CHARSET' ) ? DB_CHARSET : __( 'Undefined' ) ),
1569                  'debug' => ( defined( 'DB_CHARSET' ) ? DB_CHARSET : 'undefined' ),
1570              ),
1571              'DB_COLLATE'          => array(
1572                  'label' => 'DB_COLLATE',
1573                  'value' => $db_collate,
1574                  'debug' => $db_collate_debug,
1575              ),
1576          );
1577  
1578          return array(
1579              'label'       => __( 'WordPress Constants' ),
1580              'description' => __( 'These settings alter where and how parts of WordPress are loaded.' ),
1581              'fields'      => $fields,
1582          );
1583      }
1584  
1585      /**
1586       * Gets the WordPress database section of the debug data.
1587       *
1588       * @since 6.7.0
1589       *
1590       * @global wpdb $wpdb WordPress database abstraction object.
1591       *
1592       * @return array
1593       */
1594  	private static function get_wp_database(): array {
1595          global $wpdb;
1596  
1597          // Populate the database debug fields.
1598          if ( is_object( $wpdb->dbh ) ) {
1599              // mysqli or PDO.
1600              $extension = get_class( $wpdb->dbh );
1601          } else {
1602              // Unknown sql extension.
1603              $extension = null;
1604          }
1605  
1606          $server = $wpdb->get_var( 'SELECT VERSION()' );
1607  
1608          $client_version = $wpdb->dbh->client_info;
1609  
1610          $fields = array(
1611              'extension'          => array(
1612                  'label' => __( 'Database Extension' ),
1613                  'value' => $extension,
1614              ),
1615              'server_version'     => array(
1616                  'label' => __( 'Server version' ),
1617                  'value' => $server,
1618              ),
1619              'client_version'     => array(
1620                  'label' => __( 'Client version' ),
1621                  'value' => $client_version,
1622              ),
1623              'database_user'      => array(
1624                  'label'   => __( 'Database username' ),
1625                  'value'   => $wpdb->dbuser,
1626                  'private' => true,
1627              ),
1628              'database_host'      => array(
1629                  'label'   => __( 'Database host' ),
1630                  'value'   => $wpdb->dbhost,
1631                  'private' => true,
1632              ),
1633              'database_name'      => array(
1634                  'label'   => __( 'Database name' ),
1635                  'value'   => $wpdb->dbname,
1636                  'private' => true,
1637              ),
1638              'database_prefix'    => array(
1639                  'label'   => __( 'Table prefix' ),
1640                  'value'   => $wpdb->prefix,
1641                  'private' => true,
1642              ),
1643              'database_charset'   => array(
1644                  'label'   => __( 'Database charset' ),
1645                  'value'   => $wpdb->charset,
1646                  'private' => true,
1647              ),
1648              'database_collate'   => array(
1649                  'label'   => __( 'Database collation' ),
1650                  'value'   => $wpdb->collate,
1651                  'private' => true,
1652              ),
1653              'max_allowed_packet' => array(
1654                  'label' => __( 'Max allowed packet size' ),
1655                  'value' => self::get_mysql_var( 'max_allowed_packet' ),
1656              ),
1657              'max_connections'    => array(
1658                  'label' => __( 'Max connections number' ),
1659                  'value' => self::get_mysql_var( 'max_connections' ),
1660              ),
1661          );
1662  
1663          return array(
1664              'label'  => __( 'Database' ),
1665              'fields' => $fields,
1666          );
1667      }
1668  
1669      /**
1670       * Gets the file system section of the debug data.
1671       *
1672       * @since 6.7.0
1673       *
1674       * @return array
1675       */
1676  	private static function get_wp_filesystem(): array {
1677          $upload_dir                     = wp_upload_dir();
1678          $fonts_dir_exists               = file_exists( wp_get_font_dir()['basedir'] );
1679          $is_writable_abspath            = wp_is_writable( ABSPATH );
1680          $is_writable_wp_content_dir     = wp_is_writable( WP_CONTENT_DIR );
1681          $is_writable_upload_dir         = wp_is_writable( $upload_dir['basedir'] );
1682          $is_writable_wp_plugin_dir      = wp_is_writable( WP_PLUGIN_DIR );
1683          $is_writable_template_directory = wp_is_writable( get_theme_root( get_template() ) );
1684          $is_writable_fonts_dir          = $fonts_dir_exists ? wp_is_writable( wp_get_font_dir()['basedir'] ) : false;
1685  
1686          $fields = array(
1687              'wordpress'  => array(
1688                  'label' => __( 'The main WordPress directory' ),
1689                  'value' => ( $is_writable_abspath ? __( 'Writable' ) : __( 'Not writable' ) ),
1690                  'debug' => ( $is_writable_abspath ? 'writable' : 'not writable' ),
1691              ),
1692              'wp-content' => array(
1693                  'label' => __( 'The wp-content directory' ),
1694                  'value' => ( $is_writable_wp_content_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
1695                  'debug' => ( $is_writable_wp_content_dir ? 'writable' : 'not writable' ),
1696              ),
1697              'uploads'    => array(
1698                  'label' => __( 'The uploads directory' ),
1699                  'value' => ( $is_writable_upload_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
1700                  'debug' => ( $is_writable_upload_dir ? 'writable' : 'not writable' ),
1701              ),
1702              'plugins'    => array(
1703                  'label' => __( 'The plugins directory' ),
1704                  'value' => ( $is_writable_wp_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
1705                  'debug' => ( $is_writable_wp_plugin_dir ? 'writable' : 'not writable' ),
1706              ),
1707              'themes'     => array(
1708                  'label' => __( 'The themes directory' ),
1709                  'value' => ( $is_writable_template_directory ? __( 'Writable' ) : __( 'Not writable' ) ),
1710                  'debug' => ( $is_writable_template_directory ? 'writable' : 'not writable' ),
1711              ),
1712              'fonts'      => array(
1713                  'label' => __( 'The fonts directory' ),
1714                  'value' => $fonts_dir_exists
1715                      ? ( $is_writable_fonts_dir ? __( 'Writable' ) : __( 'Not writable' ) )
1716                      : __( 'Does not exist' ),
1717                  'debug' => $fonts_dir_exists
1718                      ? ( $is_writable_fonts_dir ? 'writable' : 'not writable' )
1719                      : 'does not exist',
1720              ),
1721          );
1722  
1723          // Add more filesystem checks.
1724          if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
1725              $is_writable_wpmu_plugin_dir = wp_is_writable( WPMU_PLUGIN_DIR );
1726  
1727              $fields['mu-plugins'] = array(
1728                  'label' => __( 'The must use plugins directory' ),
1729                  'value' => ( $is_writable_wpmu_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
1730                  'debug' => ( $is_writable_wpmu_plugin_dir ? 'writable' : 'not writable' ),
1731              );
1732          }
1733  
1734          return array(
1735              'label'       => __( 'Filesystem Permissions' ),
1736              'description' => __( 'Shows whether WordPress is able to write to the directories it needs access to.' ),
1737              'fields'      => $fields,
1738          );
1739      }
1740  
1741      /**
1742       * Returns the value of a MySQL system variable.
1743       *
1744       * @since 5.9.0
1745       *
1746       * @global wpdb $wpdb WordPress database abstraction object.
1747       *
1748       * @param string $mysql_var Name of the MySQL system variable.
1749       * @return string|null The variable value on success. Null if the variable does not exist.
1750       */
1751  	public static function get_mysql_var( $mysql_var ) {
1752          global $wpdb;
1753  
1754          $result = $wpdb->get_row(
1755              $wpdb->prepare( 'SHOW VARIABLES LIKE %s', $mysql_var ),
1756              ARRAY_A
1757          );
1758  
1759          if ( ! empty( $result ) && array_key_exists( 'Value', $result ) ) {
1760              return $result['Value'];
1761          }
1762  
1763          return null;
1764      }
1765  
1766      /**
1767       * Formats the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
1768       *
1769       * @since 5.2.0
1770       *
1771       * @param array  $info_array Information gathered from the `WP_Debug_Data::debug_data()` function.
1772       * @param string $data_type  The data type to return, either 'info' or 'debug'.
1773       * @return string The formatted data.
1774       */
1775  	public static function format( $info_array, $data_type ) {
1776          $return = "`\n";
1777  
1778          foreach ( $info_array as $section => $details ) {
1779              // Skip this section if there are no fields, or the section has been declared as private.
1780              if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
1781                  continue;
1782              }
1783  
1784              $section_label = 'debug' === $data_type ? $section : $details['label'];
1785  
1786              $return .= sprintf(
1787                  "### %s%s ###\n\n",
1788                  $section_label,
1789                  ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
1790              );
1791  
1792              foreach ( $details['fields'] as $field_name => $field ) {
1793                  if ( isset( $field['private'] ) && true === $field['private'] ) {
1794                      continue;
1795                  }
1796  
1797                  if ( 'debug' === $data_type && isset( $field['debug'] ) ) {
1798                      $debug_data = $field['debug'];
1799                  } else {
1800                      $debug_data = $field['value'];
1801                  }
1802  
1803                  // Can be array, one level deep only.
1804                  if ( is_array( $debug_data ) ) {
1805                      $value = '';
1806  
1807                      foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
1808                          $value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
1809                      }
1810                  } elseif ( is_bool( $debug_data ) ) {
1811                      $value = $debug_data ? 'true' : 'false';
1812                  } elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
1813                      $value = 'undefined';
1814                  } else {
1815                      $value = $debug_data;
1816                  }
1817  
1818                  if ( 'debug' === $data_type ) {
1819                      $label = $field_name;
1820                  } else {
1821                      $label = $field['label'];
1822                  }
1823  
1824                  $return .= sprintf( "%s: %s\n", $label, $value );
1825              }
1826  
1827              $return .= "\n";
1828          }
1829  
1830          $return .= '`';
1831  
1832          return $return;
1833      }
1834  
1835      /**
1836       * Fetches the total size of all the database tables for the active database user.
1837       *
1838       * @since 5.2.0
1839       *
1840       * @global wpdb $wpdb WordPress database abstraction object.
1841       *
1842       * @return int The size of the database, in bytes.
1843       */
1844  	public static function get_database_size() {
1845          global $wpdb;
1846          $size = 0;
1847          $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
1848  
1849          if ( $wpdb->num_rows > 0 ) {
1850              foreach ( $rows as $row ) {
1851                  $size += $row['Data_length'] + $row['Index_length'];
1852              }
1853          }
1854  
1855          return (int) $size;
1856      }
1857  
1858      /**
1859       * Fetches the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
1860       * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
1861       *
1862       * @since 5.2.0
1863       *
1864       * @return array The sizes of the directories, also the database size and total installation size.
1865       */
1866  	public static function get_sizes() {
1867          $size_db    = self::get_database_size();
1868          $upload_dir = wp_get_upload_dir();
1869  
1870          /*
1871           * We will be using the PHP max execution time to prevent the size calculations
1872           * from causing a timeout. The default value is 30 seconds, and some
1873           * hosts do not allow you to read configuration values.
1874           */
1875          if ( function_exists( 'ini_get' ) ) {
1876              $max_execution_time = ini_get( 'max_execution_time' );
1877          }
1878  
1879          /*
1880           * The max_execution_time defaults to 0 when PHP runs from cli.
1881           * We still want to limit it below.
1882           */
1883          if ( empty( $max_execution_time ) ) {
1884              $max_execution_time = 30; // 30 seconds.
1885          }
1886  
1887          if ( $max_execution_time > 20 ) {
1888              /*
1889               * If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
1890               * edge-case timeouts that may happen after the size loop has finished running.
1891               */
1892              $max_execution_time -= 2;
1893          }
1894  
1895          /*
1896           * Go through the various installation directories and calculate their sizes.
1897           * No trailing slashes.
1898           */
1899          $paths = array(
1900              'wordpress_size' => untrailingslashit( ABSPATH ),
1901              'themes_size'    => get_theme_root(),
1902              'plugins_size'   => WP_PLUGIN_DIR,
1903              'uploads_size'   => $upload_dir['basedir'],
1904              'fonts_size'     => wp_get_font_dir()['basedir'],
1905          );
1906  
1907          $exclude = $paths;
1908          unset( $exclude['wordpress_size'] );
1909          $exclude = array_values( $exclude );
1910  
1911          $size_total = 0;
1912          $all_sizes  = array();
1913  
1914          // Loop over all the directories we want to gather the sizes for.
1915          foreach ( $paths as $name => $path ) {
1916              $dir_size = null; // Default to timeout.
1917              $results  = array(
1918                  'path' => $path,
1919                  'raw'  => 0,
1920              );
1921  
1922              // If the directory does not exist, skip checking it, as it will skew the other results.
1923              if ( ! is_dir( $path ) ) {
1924                  $all_sizes[ $name ] = array(
1925                      'path'  => $path,
1926                      'raw'   => 0,
1927                      'size'  => __( 'The directory does not exist.' ),
1928                      'debug' => 'directory not found',
1929                  );
1930  
1931                  continue;
1932              }
1933  
1934              if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
1935                  if ( 'wordpress_size' === $name ) {
1936                      $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
1937                  } else {
1938                      $dir_size = recurse_dirsize( $path, null, $max_execution_time );
1939                  }
1940              }
1941  
1942              if ( false === $dir_size ) {
1943                  // Error reading.
1944                  $results['size']  = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
1945                  $results['debug'] = 'not accessible';
1946  
1947                  // Stop total size calculation.
1948                  $size_total = null;
1949              } elseif ( null === $dir_size ) {
1950                  // Timeout.
1951                  $results['size']  = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
1952                  $results['debug'] = 'timeout while calculating size';
1953  
1954                  // Stop total size calculation.
1955                  $size_total = null;
1956              } else {
1957                  if ( null !== $size_total ) {
1958                      $size_total += $dir_size;
1959                  }
1960  
1961                  $results['raw']   = $dir_size;
1962                  $results['size']  = size_format( $dir_size, 2 );
1963                  $results['debug'] = $results['size'] . " ({$dir_size} bytes)";
1964              }
1965  
1966              $all_sizes[ $name ] = $results;
1967          }
1968  
1969          if ( $size_db > 0 ) {
1970              $database_size = size_format( $size_db, 2 );
1971  
1972              $all_sizes['database_size'] = array(
1973                  'raw'   => $size_db,
1974                  'size'  => $database_size,
1975                  'debug' => $database_size . " ({$size_db} bytes)",
1976              );
1977          } else {
1978              $all_sizes['database_size'] = array(
1979                  'size'  => __( 'Not available' ),
1980                  'debug' => 'not available',
1981              );
1982          }
1983  
1984          if ( null !== $size_total && $size_db > 0 ) {
1985              $total_size    = $size_total + $size_db;
1986              $total_size_mb = size_format( $total_size, 2 );
1987  
1988              $all_sizes['total_size'] = array(
1989                  'raw'   => $total_size,
1990                  'size'  => $total_size_mb,
1991                  'debug' => $total_size_mb . " ({$total_size} bytes)",
1992              );
1993          } else {
1994              $all_sizes['total_size'] = array(
1995                  'size'  => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
1996                  'debug' => 'not available',
1997              );
1998          }
1999  
2000          return $all_sizes;
2001      }
2002  }


Generated : Tue Apr 29 08:20:01 2025 Cross-referenced by PHPXref