[ Index ]

PHP Cross Reference of WordPress

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                  $type = 'plugin';
 981                  /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
 982                  $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
 983  
 984                  if ( ! is_null( $auto_update_forced ) ) {
 985                      $enabled = $auto_update_forced;
 986                  } else {
 987                      $enabled = in_array( $plugin_path, $auto_updates, true );
 988                  }
 989  
 990                  if ( $enabled ) {
 991                      $auto_updates_string = __( 'Auto-updates enabled' );
 992                  } else {
 993                      $auto_updates_string = __( 'Auto-updates disabled' );
 994                  }
 995  
 996                  /**
 997                   * Filters the text string of the auto-updates setting for each plugin in the Site Health debug data.
 998                   *
 999                   * @since 5.5.0
1000                   *
1001                   * @param string $auto_updates_string The string output for the auto-updates column.
1002                   * @param string $plugin_path         The path to the plugin file.
1003                   * @param array  $plugin              An array of plugin data.
1004                   * @param bool   $enabled             Whether auto-updates are enabled for this item.
1005                   */
1006                  $auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled );
1007  
1008                  $plugin_version_string       .= ' | ' . $auto_updates_string;
1009                  $plugin_version_string_debug .= ', ' . $auto_updates_string;
1010              }
1011  
1012              $info[ $plugin_part ]['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
1013                  'label' => $plugin['Name'],
1014                  'value' => $plugin_version_string,
1015                  'debug' => $plugin_version_string_debug,
1016              );
1017          }
1018  
1019          // Populate the section for the currently active theme.
1020          global $_wp_theme_features;
1021          $theme_features = array();
1022  
1023          if ( ! empty( $_wp_theme_features ) ) {
1024              foreach ( $_wp_theme_features as $feature => $options ) {
1025                  $theme_features[] = $feature;
1026              }
1027          }
1028  
1029          $active_theme  = wp_get_theme();
1030          $theme_updates = get_theme_updates();
1031          $transient     = get_site_transient( 'update_themes' );
1032  
1033          $active_theme_version       = $active_theme->version;
1034          $active_theme_version_debug = $active_theme_version;
1035  
1036          $auto_updates         = array();
1037          $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
1038          if ( $auto_updates_enabled ) {
1039              $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
1040          }
1041  
1042          if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
1043              $theme_update_new_version = $theme_updates[ $active_theme->stylesheet ]->update['new_version'];
1044  
1045              /* translators: %s: Latest theme version number. */
1046              $active_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_update_new_version );
1047              $active_theme_version_debug .= sprintf( ' (latest version: %s)', $theme_update_new_version );
1048          }
1049  
1050          $active_theme_author_uri = $active_theme->display( 'AuthorURI' );
1051  
1052          if ( $active_theme->parent_theme ) {
1053              $active_theme_parent_theme = sprintf(
1054                  /* translators: 1: Theme name. 2: Theme slug. */
1055                  __( '%1$s (%2$s)' ),
1056                  $active_theme->parent_theme,
1057                  $active_theme->template
1058              );
1059              $active_theme_parent_theme_debug = sprintf(
1060                  '%s (%s)',
1061                  $active_theme->parent_theme,
1062                  $active_theme->template
1063              );
1064          } else {
1065              $active_theme_parent_theme       = __( 'None' );
1066              $active_theme_parent_theme_debug = 'none';
1067          }
1068  
1069          $info['wp-active-theme']['fields'] = array(
1070              'name'           => array(
1071                  'label' => __( 'Name' ),
1072                  'value' => sprintf(
1073                      /* translators: 1: Theme name. 2: Theme slug. */
1074                      __( '%1$s (%2$s)' ),
1075                      $active_theme->name,
1076                      $active_theme->stylesheet
1077                  ),
1078              ),
1079              'version'        => array(
1080                  'label' => __( 'Version' ),
1081                  'value' => $active_theme_version,
1082                  'debug' => $active_theme_version_debug,
1083              ),
1084              'author'         => array(
1085                  'label' => __( 'Author' ),
1086                  'value' => wp_kses( $active_theme->author, array() ),
1087              ),
1088              'author_website' => array(
1089                  'label' => __( 'Author website' ),
1090                  'value' => ( $active_theme_author_uri ? $active_theme_author_uri : __( 'Undefined' ) ),
1091                  'debug' => ( $active_theme_author_uri ? $active_theme_author_uri : '(undefined)' ),
1092              ),
1093              'parent_theme'   => array(
1094                  'label' => __( 'Parent theme' ),
1095                  'value' => $active_theme_parent_theme,
1096                  'debug' => $active_theme_parent_theme_debug,
1097              ),
1098              'theme_features' => array(
1099                  'label' => __( 'Theme features' ),
1100                  'value' => implode( ', ', $theme_features ),
1101              ),
1102              'theme_path'     => array(
1103                  'label' => __( 'Theme directory location' ),
1104                  'value' => get_stylesheet_directory(),
1105              ),
1106          );
1107  
1108          if ( $auto_updates_enabled ) {
1109              if ( isset( $transient->response[ $active_theme->stylesheet ] ) ) {
1110                  $item = $transient->response[ $active_theme->stylesheet ];
1111              } elseif ( isset( $transient->no_update[ $active_theme->stylesheet ] ) ) {
1112                  $item = $transient->no_update[ $active_theme->stylesheet ];
1113              } else {
1114                  $item = array(
1115                      'theme'        => $active_theme->stylesheet,
1116                      'new_version'  => $active_theme->version,
1117                      'url'          => '',
1118                      'package'      => '',
1119                      'requires'     => '',
1120                      'requires_php' => '',
1121                  );
1122              }
1123  
1124              $type = 'theme';
1125              /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
1126              $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
1127  
1128              if ( ! is_null( $auto_update_forced ) ) {
1129                  $enabled = $auto_update_forced;
1130              } else {
1131                  $enabled = in_array( $active_theme->stylesheet, $auto_updates, true );
1132              }
1133  
1134              if ( $enabled ) {
1135                  $auto_updates_string = __( 'Enabled' );
1136              } else {
1137                  $auto_updates_string = __( 'Disabled' );
1138              }
1139  
1140              /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
1141              $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled );
1142  
1143              $info['wp-active-theme']['fields']['auto_update'] = array(
1144                  'label' => __( 'Auto-updates' ),
1145                  'value' => $auto_updates_string,
1146                  'debug' => $auto_updates_string,
1147              );
1148          }
1149  
1150          $parent_theme = $active_theme->parent();
1151  
1152          if ( $parent_theme ) {
1153              $parent_theme_version       = $parent_theme->version;
1154              $parent_theme_version_debug = $parent_theme_version;
1155  
1156              if ( array_key_exists( $parent_theme->stylesheet, $theme_updates ) ) {
1157                  $parent_theme_update_new_version = $theme_updates[ $parent_theme->stylesheet ]->update['new_version'];
1158  
1159                  /* translators: %s: Latest theme version number. */
1160                  $parent_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $parent_theme_update_new_version );
1161                  $parent_theme_version_debug .= sprintf( ' (latest version: %s)', $parent_theme_update_new_version );
1162              }
1163  
1164              $parent_theme_author_uri = $parent_theme->display( 'AuthorURI' );
1165  
1166              $info['wp-parent-theme']['fields'] = array(
1167                  'name'           => array(
1168                      'label' => __( 'Name' ),
1169                      'value' => sprintf(
1170                          /* translators: 1: Theme name. 2: Theme slug. */
1171                          __( '%1$s (%2$s)' ),
1172                          $parent_theme->name,
1173                          $parent_theme->stylesheet
1174                      ),
1175                  ),
1176                  'version'        => array(
1177                      'label' => __( 'Version' ),
1178                      'value' => $parent_theme_version,
1179                      'debug' => $parent_theme_version_debug,
1180                  ),
1181                  'author'         => array(
1182                      'label' => __( 'Author' ),
1183                      'value' => wp_kses( $parent_theme->author, array() ),
1184                  ),
1185                  'author_website' => array(
1186                      'label' => __( 'Author website' ),
1187                      'value' => ( $parent_theme_author_uri ? $parent_theme_author_uri : __( 'Undefined' ) ),
1188                      'debug' => ( $parent_theme_author_uri ? $parent_theme_author_uri : '(undefined)' ),
1189                  ),
1190                  'theme_path'     => array(
1191                      'label' => __( 'Theme directory location' ),
1192                      'value' => get_template_directory(),
1193                  ),
1194              );
1195  
1196              if ( $auto_updates_enabled ) {
1197                  if ( isset( $transient->response[ $parent_theme->stylesheet ] ) ) {
1198                      $item = $transient->response[ $parent_theme->stylesheet ];
1199                  } elseif ( isset( $transient->no_update[ $parent_theme->stylesheet ] ) ) {
1200                      $item = $transient->no_update[ $parent_theme->stylesheet ];
1201                  } else {
1202                      $item = array(
1203                          'theme'        => $parent_theme->stylesheet,
1204                          'new_version'  => $parent_theme->version,
1205                          'url'          => '',
1206                          'package'      => '',
1207                          'requires'     => '',
1208                          'requires_php' => '',
1209                      );
1210                  }
1211  
1212                  $type = 'theme';
1213                  /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
1214                  $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
1215  
1216                  if ( ! is_null( $auto_update_forced ) ) {
1217                      $enabled = $auto_update_forced;
1218                  } else {
1219                      $enabled = in_array( $parent_theme->stylesheet, $auto_updates, true );
1220                  }
1221  
1222                  if ( $enabled ) {
1223                      $parent_theme_auto_update_string = __( 'Enabled' );
1224                  } else {
1225                      $parent_theme_auto_update_string = __( 'Disabled' );
1226                  }
1227  
1228                  /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
1229                  $parent_theme_auto_update_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $parent_theme, $enabled );
1230  
1231                  $info['wp-parent-theme']['fields']['auto_update'] = array(
1232                      'label' => __( 'Auto-update' ),
1233                      'value' => $parent_theme_auto_update_string,
1234                      'debug' => $parent_theme_auto_update_string,
1235                  );
1236              }
1237          }
1238  
1239          // Populate a list of all themes available in the install.
1240          $all_themes = wp_get_themes();
1241  
1242          foreach ( $all_themes as $theme_slug => $theme ) {
1243              // Exclude the currently active theme from the list of all themes.
1244              if ( $active_theme->stylesheet === $theme_slug ) {
1245                  continue;
1246              }
1247  
1248              // Exclude the currently active parent theme from the list of all themes.
1249              if ( ! empty( $parent_theme ) && $parent_theme->stylesheet === $theme_slug ) {
1250                  continue;
1251              }
1252  
1253              $theme_version = $theme->version;
1254              $theme_author  = $theme->author;
1255  
1256              // Sanitize.
1257              $theme_author = wp_kses( $theme_author, array() );
1258  
1259              $theme_version_string       = __( 'No version or author information is available.' );
1260              $theme_version_string_debug = 'undefined';
1261  
1262              if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) {
1263                  /* translators: 1: Theme version number. 2: Theme author name. */
1264                  $theme_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $theme_version, $theme_author );
1265                  $theme_version_string_debug = sprintf( 'version: %s, author: %s', $theme_version, $theme_author );
1266              } else {
1267                  if ( ! empty( $theme_author ) ) {
1268                      /* translators: %s: Theme author name. */
1269                      $theme_version_string       = sprintf( __( 'By %s' ), $theme_author );
1270                      $theme_version_string_debug = sprintf( 'author: %s, version: (undefined)', $theme_author );
1271                  }
1272  
1273                  if ( ! empty( $theme_version ) ) {
1274                      /* translators: %s: Theme version number. */
1275                      $theme_version_string       = sprintf( __( 'Version %s' ), $theme_version );
1276                      $theme_version_string_debug = sprintf( 'author: (undefined), version: %s', $theme_version );
1277                  }
1278              }
1279  
1280              if ( array_key_exists( $theme_slug, $theme_updates ) ) {
1281                  /* translators: %s: Latest theme version number. */
1282                  $theme_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $theme_slug ]->update['new_version'] );
1283                  $theme_version_string_debug .= sprintf( ' (latest version: %s)', $theme_updates[ $theme_slug ]->update['new_version'] );
1284              }
1285  
1286              if ( $auto_updates_enabled ) {
1287                  if ( isset( $transient->response[ $theme_slug ] ) ) {
1288                      $item = $transient->response[ $theme_slug ];
1289                  } elseif ( isset( $transient->no_update[ $theme_slug ] ) ) {
1290                      $item = $transient->no_update[ $theme_slug ];
1291                  } else {
1292                      $item = array(
1293                          'theme'        => $theme_slug,
1294                          'new_version'  => $theme->version,
1295                          'url'          => '',
1296                          'package'      => '',
1297                          'requires'     => '',
1298                          'requires_php' => '',
1299                      );
1300                  }
1301  
1302                  $type = 'theme';
1303                  /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
1304                  $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $item );
1305  
1306                  if ( ! is_null( $auto_update_forced ) ) {
1307                      $enabled = $auto_update_forced;
1308                  } else {
1309                      $enabled = in_array( $theme_slug, $auto_updates, true );
1310                  }
1311  
1312                  if ( $enabled ) {
1313                      $auto_updates_string = __( 'Auto-updates enabled' );
1314                  } else {
1315                      $auto_updates_string = __( 'Auto-updates disabled' );
1316                  }
1317  
1318                  /**
1319                   * Filters the text string of the auto-updates setting for each theme in the Site Health debug data.
1320                   *
1321                   * @since 5.5.0
1322                   *
1323                   * @param string   $auto_updates_string The string output for the auto-updates column.
1324                   * @param WP_Theme $theme               An object of theme data.
1325                   * @param bool     $enabled             Whether auto-updates are enabled for this item.
1326                   */
1327                  $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled );
1328  
1329                  $theme_version_string       .= ' | ' . $auto_updates_string;
1330                  $theme_version_string_debug .= ',' . $auto_updates_string;
1331              }
1332  
1333              $info['wp-themes-inactive']['fields'][ sanitize_text_field( $theme->name ) ] = array(
1334                  'label' => sprintf(
1335                      /* translators: 1: Theme name. 2: Theme slug. */
1336                      __( '%1$s (%2$s)' ),
1337                      $theme->name,
1338                      $theme_slug
1339                  ),
1340                  'value' => $theme_version_string,
1341                  'debug' => $theme_version_string_debug,
1342              );
1343          }
1344  
1345          // Add more filesystem checks.
1346          if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
1347              $is_writable_wpmu_plugin_dir = wp_is_writable( WPMU_PLUGIN_DIR );
1348  
1349              $info['wp-filesystem']['fields']['mu-plugins'] = array(
1350                  'label' => __( 'The must use plugins directory' ),
1351                  'value' => ( $is_writable_wpmu_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
1352                  'debug' => ( $is_writable_wpmu_plugin_dir ? 'writable' : 'not writable' ),
1353              );
1354          }
1355  
1356          /**
1357           * Add or modify the debug information.
1358           *
1359           * Plugin or themes may wish to introduce their own debug information without creating additional admin pages
1360           * they can utilize this filter to introduce their own sections or add more data to existing sections.
1361           *
1362           * Array keys for sections added by core are all prefixed with `wp-`, plugins and themes should use their own slug as
1363           * a prefix, both for consistency as well as avoiding key collisions. Note that the array keys are used as labels
1364           * for the copied data.
1365           *
1366           * All strings are expected to be plain text except $description that can contain inline HTML tags (see below).
1367           *
1368           * @since 5.2.0
1369           *
1370           * @param array $args {
1371           *     The debug information to be added to the core information page.
1372           *
1373           *     This is an associative multi-dimensional array, up to three levels deep. The topmost array holds the sections.
1374           *     Each section has a `$fields` associative array (see below), and each `$value` in `$fields` can be
1375           *     another associative array of name/value pairs when there is more structured data to display.
1376           *
1377           *     @type string  $label        The title for this section of the debug output.
1378           *     @type string  $description  Optional. A description for your information section which may contain basic HTML
1379           *                                 markup, inline tags only as it is outputted in a paragraph.
1380           *     @type boolean $show_count   Optional. If set to `true` the amount of fields will be included in the title for
1381           *                                 this section.
1382           *     @type boolean $private      Optional. If set to `true` the section and all associated fields will be excluded
1383           *                                 from the copied data.
1384           *     @type array   $fields {
1385           *         An associative array containing the data to be displayed.
1386           *
1387           *         @type string  $label    The label for this piece of information.
1388           *         @type string  $value    The output that is displayed for this field. Text should be translated. Can be
1389           *                                 an associative array that is displayed as name/value pairs.
1390           *         @type string  $debug    Optional. The output that is used for this field when the user copies the data.
1391           *                                 It should be more concise and not translated. If not set, the content of `$value` is used.
1392           *                                 Note that the array keys are used as labels for the copied data.
1393           *         @type boolean $private  Optional. If set to `true` the field will not be included in the copied data
1394           *                                 allowing you to show, for example, API keys here.
1395           *     }
1396           * }
1397           */
1398          $info = apply_filters( 'debug_information', $info );
1399  
1400          return $info;
1401      }
1402  
1403      /**
1404       * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
1405       *
1406       * @since 5.2.0
1407       *
1408       * @param array  $info_array Information gathered from the `WP_Debug_Data::debug_data` function.
1409       * @param string $type       The data type to return, either 'info' or 'debug'.
1410       * @return string The formatted data.
1411       */
1412  	public static function format( $info_array, $type ) {
1413          $return = "`\n";
1414  
1415          foreach ( $info_array as $section => $details ) {
1416              // Skip this section if there are no fields, or the section has been declared as private.
1417              if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
1418                  continue;
1419              }
1420  
1421              $section_label = 'debug' === $type ? $section : $details['label'];
1422  
1423              $return .= sprintf(
1424                  "### %s%s ###\n\n",
1425                  $section_label,
1426                  ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
1427              );
1428  
1429              foreach ( $details['fields'] as $field_name => $field ) {
1430                  if ( isset( $field['private'] ) && true === $field['private'] ) {
1431                      continue;
1432                  }
1433  
1434                  if ( 'debug' === $type && isset( $field['debug'] ) ) {
1435                      $debug_data = $field['debug'];
1436                  } else {
1437                      $debug_data = $field['value'];
1438                  }
1439  
1440                  // Can be array, one level deep only.
1441                  if ( is_array( $debug_data ) ) {
1442                      $value = '';
1443  
1444                      foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
1445                          $value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
1446                      }
1447                  } elseif ( is_bool( $debug_data ) ) {
1448                      $value = $debug_data ? 'true' : 'false';
1449                  } elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
1450                      $value = 'undefined';
1451                  } else {
1452                      $value = $debug_data;
1453                  }
1454  
1455                  if ( 'debug' === $type ) {
1456                      $label = $field_name;
1457                  } else {
1458                      $label = $field['label'];
1459                  }
1460  
1461                  $return .= sprintf( "%s: %s\n", $label, $value );
1462              }
1463  
1464              $return .= "\n";
1465          }
1466  
1467          $return .= '`';
1468  
1469          return $return;
1470      }
1471  
1472      /**
1473       * Fetch the total size of all the database tables for the active database user.
1474       *
1475       * @since 5.2.0
1476       *
1477       * @return int The size of the database, in bytes.
1478       */
1479  	public static function get_database_size() {
1480          global $wpdb;
1481          $size = 0;
1482          $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
1483  
1484          if ( $wpdb->num_rows > 0 ) {
1485              foreach ( $rows as $row ) {
1486                  $size += $row['Data_length'] + $row['Index_length'];
1487              }
1488          }
1489  
1490          return (int) $size;
1491      }
1492  
1493      /**
1494       * Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
1495       * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
1496       *
1497       * @since 5.2.0
1498       *
1499       * @return array The sizes of the directories, also the database size and total installation size.
1500       */
1501  	public static function get_sizes() {
1502          $size_db    = self::get_database_size();
1503          $upload_dir = wp_get_upload_dir();
1504  
1505          /*
1506           * We will be using the PHP max execution time to prevent the size calculations
1507           * from causing a timeout. The default value is 30 seconds, and some
1508           * hosts do not allow you to read configuration values.
1509           */
1510          if ( function_exists( 'ini_get' ) ) {
1511              $max_execution_time = ini_get( 'max_execution_time' );
1512          }
1513  
1514          // The max_execution_time defaults to 0 when PHP runs from cli.
1515          // We still want to limit it below.
1516          if ( empty( $max_execution_time ) ) {
1517              $max_execution_time = 30;
1518          }
1519  
1520          if ( $max_execution_time > 20 ) {
1521              // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
1522              // edge-case timeouts that may happen after the size loop has finished running.
1523              $max_execution_time -= 2;
1524          }
1525  
1526          // Go through the various installation directories and calculate their sizes.
1527          // No trailing slashes.
1528          $paths = array(
1529              'wordpress_size' => untrailingslashit( ABSPATH ),
1530              'themes_size'    => get_theme_root(),
1531              'plugins_size'   => WP_PLUGIN_DIR,
1532              'uploads_size'   => $upload_dir['basedir'],
1533          );
1534  
1535          $exclude = $paths;
1536          unset( $exclude['wordpress_size'] );
1537          $exclude = array_values( $exclude );
1538  
1539          $size_total = 0;
1540          $all_sizes  = array();
1541  
1542          // Loop over all the directories we want to gather the sizes for.
1543          foreach ( $paths as $name => $path ) {
1544              $dir_size = null; // Default to timeout.
1545              $results  = array(
1546                  'path' => $path,
1547                  'raw'  => 0,
1548              );
1549  
1550              if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
1551                  if ( 'wordpress_size' === $name ) {
1552                      $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
1553                  } else {
1554                      $dir_size = recurse_dirsize( $path, null, $max_execution_time );
1555                  }
1556              }
1557  
1558              if ( false === $dir_size ) {
1559                  // Error reading.
1560                  $results['size']  = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
1561                  $results['debug'] = 'not accessible';
1562  
1563                  // Stop total size calculation.
1564                  $size_total = null;
1565              } elseif ( null === $dir_size ) {
1566                  // Timeout.
1567                  $results['size']  = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
1568                  $results['debug'] = 'timeout while calculating size';
1569  
1570                  // Stop total size calculation.
1571                  $size_total = null;
1572              } else {
1573                  if ( null !== $size_total ) {
1574                      $size_total += $dir_size;
1575                  }
1576  
1577                  $results['raw']   = $dir_size;
1578                  $results['size']  = size_format( $dir_size, 2 );
1579                  $results['debug'] = $results['size'] . " ({$dir_size} bytes)";
1580              }
1581  
1582              $all_sizes[ $name ] = $results;
1583          }
1584  
1585          if ( $size_db > 0 ) {
1586              $database_size = size_format( $size_db, 2 );
1587  
1588              $all_sizes['database_size'] = array(
1589                  'raw'   => $size_db,
1590                  'size'  => $database_size,
1591                  'debug' => $database_size . " ({$size_db} bytes)",
1592              );
1593          } else {
1594              $all_sizes['database_size'] = array(
1595                  'size'  => __( 'Not available' ),
1596                  'debug' => 'not available',
1597              );
1598          }
1599  
1600          if ( null !== $size_total && $size_db > 0 ) {
1601              $total_size    = $size_total + $size_db;
1602              $total_size_mb = size_format( $total_size, 2 );
1603  
1604              $all_sizes['total_size'] = array(
1605                  'raw'   => $total_size,
1606                  'size'  => $total_size_mb,
1607                  'debug' => $total_size_mb . " ({$total_size} bytes)",
1608              );
1609          } else {
1610              $all_sizes['total_size'] = array(
1611                  'size'  => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
1612                  'debug' => 'not available',
1613              );
1614          }
1615  
1616          return $all_sizes;
1617      }
1618  }


Generated: Thu Sep 24 01:02:16 2020 Cross-referenced by PHPXref 0.7.1