[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

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


Generated : Mon Aug 3 08:20:02 2020 Cross-referenced by PHPXref