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


Generated: Tue Dec 1 01:00:04 2020 Cross-referenced by PHPXref 0.7.1