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


Generated : Fri Oct 30 08:20:01 2020 Cross-referenced by PHPXref