[ 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          $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 Imagick is used as our editor, provide some more information about its limitations.
 523          if ( 'WP_Image_Editor_Imagick' === _wp_image_editor_choose() && isset( $imagick ) && $imagick instanceof Imagick ) {
 524              $limits = array(
 525                  'area'   => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : $not_available ),
 526                  'disk'   => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : $not_available ),
 527                  'file'   => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : $not_available ),
 528                  'map'    => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : $not_available ),
 529                  'memory' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : $not_available ),
 530                  'thread' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : $not_available ),
 531              );
 532  
 533              $limits_debug = array(
 534                  'imagick::RESOURCETYPE_AREA'   => ( defined( 'imagick::RESOURCETYPE_AREA' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_AREA ) ) : 'not available' ),
 535                  'imagick::RESOURCETYPE_DISK'   => ( defined( 'imagick::RESOURCETYPE_DISK' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_DISK ) : 'not available' ),
 536                  'imagick::RESOURCETYPE_FILE'   => ( defined( 'imagick::RESOURCETYPE_FILE' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_FILE ) : 'not available' ),
 537                  'imagick::RESOURCETYPE_MAP'    => ( defined( 'imagick::RESOURCETYPE_MAP' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MAP ) ) : 'not available' ),
 538                  'imagick::RESOURCETYPE_MEMORY' => ( defined( 'imagick::RESOURCETYPE_MEMORY' ) ? size_format( $imagick->getResourceLimit( imagick::RESOURCETYPE_MEMORY ) ) : 'not available' ),
 539                  'imagick::RESOURCETYPE_THREAD' => ( defined( 'imagick::RESOURCETYPE_THREAD' ) ? $imagick->getResourceLimit( imagick::RESOURCETYPE_THREAD ) : 'not available' ),
 540              );
 541  
 542              $info['wp-media']['fields']['imagick_limits'] = array(
 543                  'label' => __( 'Imagick Resource Limits' ),
 544                  'value' => $limits,
 545                  'debug' => $limits_debug,
 546              );
 547          }
 548  
 549          // Get GD information, if available.
 550          if ( function_exists( 'gd_info' ) ) {
 551              $gd = gd_info();
 552          } else {
 553              $gd = false;
 554          }
 555  
 556          $info['wp-media']['fields']['gd_version'] = array(
 557              'label' => __( 'GD version' ),
 558              'value' => ( is_array( $gd ) ? $gd['GD Version'] : $not_available ),
 559              'debug' => ( is_array( $gd ) ? $gd['GD Version'] : 'not available' ),
 560          );
 561  
 562          // Get Ghostscript information, if available.
 563          if ( function_exists( 'exec' ) ) {
 564              $gs = exec( 'gs --version' );
 565  
 566              if ( empty( $gs ) ) {
 567                  $gs       = $not_available;
 568                  $gs_debug = 'not available';
 569              } else {
 570                  $gs_debug = $gs;
 571              }
 572          } else {
 573              $gs       = __( 'Unable to determine if Ghostscript is installed' );
 574              $gs_debug = 'unknown';
 575          }
 576  
 577          $info['wp-media']['fields']['ghostscript_version'] = array(
 578              'label' => __( 'Ghostscript version' ),
 579              'value' => $gs,
 580              'debug' => $gs_debug,
 581          );
 582  
 583          // Populate the server debug fields.
 584          if ( function_exists( 'php_uname' ) ) {
 585              $server_architecture = sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) );
 586          } else {
 587              $server_architecture = 'unknown';
 588          }
 589  
 590          if ( function_exists( 'phpversion' ) ) {
 591              $php_version_debug = phpversion();
 592              // Whether PHP supports 64-bit.
 593              $php64bit = ( PHP_INT_SIZE * 8 === 64 );
 594  
 595              $php_version = sprintf(
 596                  '%s %s',
 597                  $php_version_debug,
 598                  ( $php64bit ? __( '(Supports 64bit values)' ) : __( '(Does not support 64bit values)' ) )
 599              );
 600  
 601              if ( $php64bit ) {
 602                  $php_version_debug .= ' 64bit';
 603              }
 604          } else {
 605              $php_version       = __( 'Unable to determine PHP version' );
 606              $php_version_debug = 'unknown';
 607          }
 608  
 609          if ( function_exists( 'php_sapi_name' ) ) {
 610              $php_sapi = php_sapi_name();
 611          } else {
 612              $php_sapi = 'unknown';
 613          }
 614  
 615          $info['wp-server']['fields']['server_architecture'] = array(
 616              'label' => __( 'Server architecture' ),
 617              'value' => ( 'unknown' !== $server_architecture ? $server_architecture : __( 'Unable to determine server architecture' ) ),
 618              'debug' => $server_architecture,
 619          );
 620          $info['wp-server']['fields']['httpd_software']      = array(
 621              'label' => __( 'Web server' ),
 622              'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used' ) ),
 623              'debug' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'unknown' ),
 624          );
 625          $info['wp-server']['fields']['php_version']         = array(
 626              'label' => __( 'PHP version' ),
 627              'value' => $php_version,
 628              'debug' => $php_version_debug,
 629          );
 630          $info['wp-server']['fields']['php_sapi']            = array(
 631              'label' => __( 'PHP SAPI' ),
 632              'value' => ( 'unknown' !== $php_sapi ? $php_sapi : __( 'Unable to determine PHP SAPI' ) ),
 633              'debug' => $php_sapi,
 634          );
 635  
 636          // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
 637          if ( ! function_exists( 'ini_get' ) ) {
 638              $info['wp-server']['fields']['ini_get'] = array(
 639                  'label' => __( 'Server settings' ),
 640                  'value' => sprintf(
 641                      /* translators: %s: ini_get() */
 642                      __( 'Unable to determine some settings, as the %s function has been disabled.' ),
 643                      'ini_get()'
 644                  ),
 645                  'debug' => 'ini_get() is disabled',
 646              );
 647          } else {
 648              $info['wp-server']['fields']['max_input_variables'] = array(
 649                  'label' => __( 'PHP max input variables' ),
 650                  'value' => ini_get( 'max_input_vars' ),
 651              );
 652              $info['wp-server']['fields']['time_limit']          = array(
 653                  'label' => __( 'PHP time limit' ),
 654                  'value' => ini_get( 'max_execution_time' ),
 655              );
 656  
 657              if ( WP_Site_Health::get_instance()->php_memory_limit !== ini_get( 'memory_limit' ) ) {
 658                  $info['wp-server']['fields']['memory_limit']       = array(
 659                      'label' => __( 'PHP memory limit' ),
 660                      'value' => WP_Site_Health::get_instance()->php_memory_limit,
 661                  );
 662                  $info['wp-server']['fields']['admin_memory_limit'] = array(
 663                      'label' => __( 'PHP memory limit (only for admin screens)' ),
 664                      'value' => ini_get( 'memory_limit' ),
 665                  );
 666              } else {
 667                  $info['wp-server']['fields']['memory_limit'] = array(
 668                      'label' => __( 'PHP memory limit' ),
 669                      'value' => ini_get( 'memory_limit' ),
 670                  );
 671              }
 672  
 673              $info['wp-server']['fields']['max_input_time']    = array(
 674                  'label' => __( 'Max input time' ),
 675                  'value' => ini_get( 'max_input_time' ),
 676              );
 677              $info['wp-server']['fields']['upload_max_size']   = array(
 678                  'label' => __( 'Upload max filesize' ),
 679                  'value' => ini_get( 'upload_max_filesize' ),
 680              );
 681              $info['wp-server']['fields']['php_post_max_size'] = array(
 682                  'label' => __( 'PHP post max size' ),
 683                  'value' => ini_get( 'post_max_size' ),
 684              );
 685          }
 686  
 687          if ( function_exists( 'curl_version' ) ) {
 688              $curl = curl_version();
 689  
 690              $info['wp-server']['fields']['curl_version'] = array(
 691                  'label' => __( 'cURL version' ),
 692                  'value' => sprintf( '%s %s', $curl['version'], $curl['ssl_version'] ),
 693              );
 694          } else {
 695              $info['wp-server']['fields']['curl_version'] = array(
 696                  'label' => __( 'cURL version' ),
 697                  'value' => $not_available,
 698                  'debug' => 'not available',
 699              );
 700          }
 701  
 702          // SUHOSIN.
 703          $suhosin_loaded = ( extension_loaded( 'suhosin' ) || ( defined( 'SUHOSIN_PATCH' ) && constant( 'SUHOSIN_PATCH' ) ) );
 704  
 705          $info['wp-server']['fields']['suhosin'] = array(
 706              'label' => __( 'Is SUHOSIN installed?' ),
 707              'value' => ( $suhosin_loaded ? __( 'Yes' ) : __( 'No' ) ),
 708              'debug' => $suhosin_loaded,
 709          );
 710  
 711          // Imagick.
 712          $imagick_loaded = extension_loaded( 'imagick' );
 713  
 714          $info['wp-server']['fields']['imagick_availability'] = array(
 715              'label' => __( 'Is the Imagick library available?' ),
 716              'value' => ( $imagick_loaded ? __( 'Yes' ) : __( 'No' ) ),
 717              'debug' => $imagick_loaded,
 718          );
 719  
 720          // Pretty permalinks.
 721          $pretty_permalinks_supported = got_url_rewrite();
 722  
 723          $info['wp-server']['fields']['pretty_permalinks'] = array(
 724              'label' => __( 'Are pretty permalinks supported?' ),
 725              'value' => ( $pretty_permalinks_supported ? __( 'Yes' ) : __( 'No' ) ),
 726              'debug' => $pretty_permalinks_supported,
 727          );
 728  
 729          // Check if a .htaccess file exists.
 730          if ( is_file( ABSPATH . '.htaccess' ) ) {
 731              // If the file exists, grab the content of it.
 732              $htaccess_content = file_get_contents( ABSPATH . '.htaccess' );
 733  
 734              // Filter away the core WordPress rules.
 735              $filtered_htaccess_content = trim( preg_replace( '/\# BEGIN WordPress[\s\S]+?# END WordPress/si', '', $htaccess_content ) );
 736              $filtered_htaccess_content = ! empty( $filtered_htaccess_content );
 737  
 738              if ( $filtered_htaccess_content ) {
 739                  /* translators: %s: .htaccess */
 740                  $htaccess_rules_string = sprintf( __( 'Custom rules have been added to your %s file.' ), '.htaccess' );
 741              } else {
 742                  /* translators: %s: .htaccess */
 743                  $htaccess_rules_string = sprintf( __( 'Your %s file contains only core WordPress features.' ), '.htaccess' );
 744              }
 745  
 746              $info['wp-server']['fields']['htaccess_extra_rules'] = array(
 747                  'label' => __( '.htaccess rules' ),
 748                  'value' => $htaccess_rules_string,
 749                  'debug' => $filtered_htaccess_content,
 750              );
 751          }
 752  
 753          // Populate the database debug fields.
 754          if ( is_resource( $wpdb->dbh ) ) {
 755              // Old mysql extension.
 756              $extension = 'mysql';
 757          } elseif ( is_object( $wpdb->dbh ) ) {
 758              // mysqli or PDO.
 759              $extension = get_class( $wpdb->dbh );
 760          } else {
 761              // Unknown sql extension.
 762              $extension = null;
 763          }
 764  
 765          $server = $wpdb->get_var( 'SELECT VERSION()' );
 766  
 767          if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) {
 768              $client_version = $wpdb->dbh->client_info;
 769          } else {
 770              // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
 771              if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) {
 772                  $client_version = $matches[0];
 773              } else {
 774                  $client_version = null;
 775              }
 776          }
 777  
 778          $info['wp-database']['fields']['extension'] = array(
 779              'label' => __( 'Extension' ),
 780              'value' => $extension,
 781          );
 782  
 783          $info['wp-database']['fields']['server_version'] = array(
 784              'label' => __( 'Server version' ),
 785              'value' => $server,
 786          );
 787  
 788          $info['wp-database']['fields']['client_version'] = array(
 789              'label' => __( 'Client version' ),
 790              'value' => $client_version,
 791          );
 792  
 793          $info['wp-database']['fields']['database_user'] = array(
 794              'label'   => __( 'Database username' ),
 795              'value'   => $wpdb->dbuser,
 796              'private' => true,
 797          );
 798  
 799          $info['wp-database']['fields']['database_host'] = array(
 800              'label'   => __( 'Database host' ),
 801              'value'   => $wpdb->dbhost,
 802              'private' => true,
 803          );
 804  
 805          $info['wp-database']['fields']['database_name'] = array(
 806              'label'   => __( 'Database name' ),
 807              'value'   => $wpdb->dbname,
 808              'private' => true,
 809          );
 810  
 811          $info['wp-database']['fields']['database_prefix'] = array(
 812              'label'   => __( 'Table prefix' ),
 813              'value'   => $wpdb->prefix,
 814              'private' => true,
 815          );
 816  
 817          $info['wp-database']['fields']['database_charset'] = array(
 818              'label'   => __( 'Database charset' ),
 819              'value'   => $wpdb->charset,
 820              'private' => true,
 821          );
 822  
 823          $info['wp-database']['fields']['database_collate'] = array(
 824              'label'   => __( 'Database collation' ),
 825              'value'   => $wpdb->collate,
 826              'private' => true,
 827          );
 828  
 829          // List must use plugins if there are any.
 830          $mu_plugins = get_mu_plugins();
 831  
 832          foreach ( $mu_plugins as $plugin_path => $plugin ) {
 833              $plugin_version = $plugin['Version'];
 834              $plugin_author  = $plugin['Author'];
 835  
 836              $plugin_version_string       = __( 'No version or author information is available.' );
 837              $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
 838  
 839              if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
 840                  /* translators: 1: Plugin version number. 2: Plugin author name. */
 841                  $plugin_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
 842                  $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
 843              } else {
 844                  if ( ! empty( $plugin_author ) ) {
 845                      /* translators: %s: Plugin author name. */
 846                      $plugin_version_string       = sprintf( __( 'By %s' ), $plugin_author );
 847                      $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
 848                  }
 849  
 850                  if ( ! empty( $plugin_version ) ) {
 851                      /* translators: %s: Plugin version number. */
 852                      $plugin_version_string       = sprintf( __( 'Version %s' ), $plugin_version );
 853                      $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
 854                  }
 855              }
 856  
 857              $info['wp-mu-plugins']['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
 858                  'label' => $plugin['Name'],
 859                  'value' => $plugin_version_string,
 860                  'debug' => $plugin_version_string_debug,
 861              );
 862          }
 863  
 864          // List all available plugins.
 865          $plugins        = get_plugins();
 866          $plugin_updates = get_plugin_updates();
 867          $auto_updates   = array();
 868  
 869          $auto_updates_enabled      = wp_is_auto_update_enabled_for_type( 'plugin' );
 870          $auto_updates_enabled_str  = __( 'Auto-updates enabled' );
 871          $auto_updates_disabled_str = __( 'Auto-updates disabled' );
 872  
 873          if ( $auto_updates_enabled ) {
 874              $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
 875          }
 876  
 877          foreach ( $plugins as $plugin_path => $plugin ) {
 878              $plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';
 879  
 880              $plugin_version = $plugin['Version'];
 881              $plugin_author  = $plugin['Author'];
 882  
 883              $plugin_version_string       = __( 'No version or author information is available.' );
 884              $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
 885  
 886              if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
 887                  /* translators: 1: Plugin version number. 2: Plugin author name. */
 888                  $plugin_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
 889                  $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
 890              } else {
 891                  if ( ! empty( $plugin_author ) ) {
 892                      /* translators: %s: Plugin author name. */
 893                      $plugin_version_string       = sprintf( __( 'By %s' ), $plugin_author );
 894                      $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
 895                  }
 896  
 897                  if ( ! empty( $plugin_version ) ) {
 898                      /* translators: %s: Plugin version number. */
 899                      $plugin_version_string       = sprintf( __( 'Version %s' ), $plugin_version );
 900                      $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
 901                  }
 902              }
 903  
 904              if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
 905                  /* translators: %s: Latest plugin version number. */
 906                  $plugin_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $plugin_updates[ $plugin_path ]->update->new_version );
 907                  $plugin_version_string_debug .= sprintf( ' (latest version: %s)', $plugin_updates[ $plugin_path ]->update->new_version );
 908              }
 909  
 910              if ( $auto_updates_enabled ) {
 911                  if ( in_array( $plugin_path, $auto_updates, true ) ) {
 912                      $plugin_version_string       .= ' | ' . $auto_updates_enabled_str;
 913                      $plugin_version_string_debug .= ', ' . $auto_updates_enabled_str;
 914                  } else {
 915                      $plugin_version_string       .= ' | ' . $auto_updates_disabled_str;
 916                      $plugin_version_string_debug .= ', ' . $auto_updates_disabled_str;
 917                  }
 918              }
 919  
 920              $info[ $plugin_part ]['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
 921                  'label' => $plugin['Name'],
 922                  'value' => $plugin_version_string,
 923                  'debug' => $plugin_version_string_debug,
 924              );
 925          }
 926  
 927          // Populate the section for the currently active theme.
 928          global $_wp_theme_features;
 929          $theme_features = array();
 930  
 931          if ( ! empty( $_wp_theme_features ) ) {
 932              foreach ( $_wp_theme_features as $feature => $options ) {
 933                  $theme_features[] = $feature;
 934              }
 935          }
 936  
 937          $active_theme  = wp_get_theme();
 938          $theme_updates = get_theme_updates();
 939  
 940          $active_theme_version       = $active_theme->version;
 941          $active_theme_version_debug = $active_theme_version;
 942  
 943          $auto_updates         = array();
 944          $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
 945          if ( $auto_updates_enabled ) {
 946              $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
 947          }
 948  
 949          if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
 950              $theme_update_new_version = $theme_updates[ $active_theme->stylesheet ]->update['new_version'];
 951  
 952              /* translators: %s: Latest theme version number. */
 953              $active_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_update_new_version );
 954              $active_theme_version_debug .= sprintf( ' (latest version: %s)', $theme_update_new_version );
 955          }
 956  
 957          $active_theme_author_uri = $active_theme->display( 'AuthorURI' );
 958  
 959          if ( $active_theme->parent_theme ) {
 960              $active_theme_parent_theme = sprintf(
 961                  /* translators: 1: Theme name. 2: Theme slug. */
 962                  __( '%1$s (%2$s)' ),
 963                  $active_theme->parent_theme,
 964                  $active_theme->template
 965              );
 966              $active_theme_parent_theme_debug = sprintf(
 967                  '%s (%s)',
 968                  $active_theme->parent_theme,
 969                  $active_theme->template
 970              );
 971          } else {
 972              $active_theme_parent_theme       = __( 'None' );
 973              $active_theme_parent_theme_debug = 'none';
 974          }
 975  
 976          $info['wp-active-theme']['fields'] = array(
 977              'name'           => array(
 978                  'label' => __( 'Name' ),
 979                  'value' => sprintf(
 980                      /* translators: 1: Theme name. 2: Theme slug. */
 981                      __( '%1$s (%2$s)' ),
 982                      $active_theme->name,
 983                      $active_theme->stylesheet
 984                  ),
 985              ),
 986              'version'        => array(
 987                  'label' => __( 'Version' ),
 988                  'value' => $active_theme_version,
 989                  'debug' => $active_theme_version_debug,
 990              ),
 991              'author'         => array(
 992                  'label' => __( 'Author' ),
 993                  'value' => wp_kses( $active_theme->author, array() ),
 994              ),
 995              'author_website' => array(
 996                  'label' => __( 'Author website' ),
 997                  'value' => ( $active_theme_author_uri ? $active_theme_author_uri : __( 'Undefined' ) ),
 998                  'debug' => ( $active_theme_author_uri ? $active_theme_author_uri : '(undefined)' ),
 999              ),
1000              'parent_theme'   => array(
1001                  'label' => __( 'Parent theme' ),
1002                  'value' => $active_theme_parent_theme,
1003                  'debug' => $active_theme_parent_theme_debug,
1004              ),
1005              'theme_features' => array(
1006                  'label' => __( 'Theme features' ),
1007                  'value' => implode( ', ', $theme_features ),
1008              ),
1009              'theme_path'     => array(
1010                  'label' => __( 'Theme directory location' ),
1011                  'value' => get_stylesheet_directory(),
1012              ),
1013          );
1014          if ( $auto_updates_enabled ) {
1015              if ( in_array( $active_theme->stylesheet, $auto_updates, true ) ) {
1016                  $theme_auto_update_string = __( 'Enabled' );
1017              } else {
1018                  $theme_auto_update_string = __( 'Disabled' );
1019              }
1020  
1021              $info['wp-active-theme']['fields']['auto_update'] = array(
1022                  'label' => __( 'Auto-update' ),
1023                  'value' => $theme_auto_update_string,
1024                  'debug' => $theme_auto_update_string,
1025              );
1026          }
1027          $parent_theme = $active_theme->parent();
1028  
1029          if ( $parent_theme ) {
1030              $parent_theme_version       = $parent_theme->version;
1031              $parent_theme_version_debug = $parent_theme_version;
1032  
1033              if ( array_key_exists( $parent_theme->stylesheet, $theme_updates ) ) {
1034                  $parent_theme_update_new_version = $theme_updates[ $parent_theme->stylesheet ]->update['new_version'];
1035  
1036                  /* translators: %s: Latest theme version number. */
1037                  $parent_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $parent_theme_update_new_version );
1038                  $parent_theme_version_debug .= sprintf( ' (latest version: %s)', $parent_theme_update_new_version );
1039              }
1040  
1041              $parent_theme_author_uri = $parent_theme->display( 'AuthorURI' );
1042  
1043              $info['wp-parent-theme']['fields'] = array(
1044                  'name'           => array(
1045                      'label' => __( 'Name' ),
1046                      'value' => sprintf(
1047                          /* translators: 1: Theme name. 2: Theme slug. */
1048                          __( '%1$s (%2$s)' ),
1049                          $parent_theme->name,
1050                          $parent_theme->stylesheet
1051                      ),
1052                  ),
1053                  'version'        => array(
1054                      'label' => __( 'Version' ),
1055                      'value' => $parent_theme_version,
1056                      'debug' => $parent_theme_version_debug,
1057                  ),
1058                  'author'         => array(
1059                      'label' => __( 'Author' ),
1060                      'value' => wp_kses( $parent_theme->author, array() ),
1061                  ),
1062                  'author_website' => array(
1063                      'label' => __( 'Author website' ),
1064                      'value' => ( $parent_theme_author_uri ? $parent_theme_author_uri : __( 'Undefined' ) ),
1065                      'debug' => ( $parent_theme_author_uri ? $parent_theme_author_uri : '(undefined)' ),
1066                  ),
1067                  'theme_path'     => array(
1068                      'label' => __( 'Theme directory location' ),
1069                      'value' => get_template_directory(),
1070                  ),
1071              );
1072              if ( $auto_updates_enabled ) {
1073                  if ( in_array( $parent_theme->stylesheet, $auto_updates, true ) ) {
1074                      $parent_theme_auto_update_string = __( 'Enabled' );
1075                  } else {
1076                      $parent_theme_auto_update_string = __( 'Disabled' );
1077                  }
1078  
1079                  $info['wp-parent-theme']['fields']['auto_update'] = array(
1080                      'label' => __( 'Auto-update' ),
1081                      'value' => $parent_theme_auto_update_string,
1082                      'debug' => $parent_theme_auto_update_string,
1083                  );
1084              }
1085          }
1086  
1087          // Populate a list of all themes available in the install.
1088          $all_themes = wp_get_themes();
1089  
1090          foreach ( $all_themes as $theme_slug => $theme ) {
1091              // Exclude the currently active theme from the list of all themes.
1092              if ( $active_theme->stylesheet === $theme_slug ) {
1093                  continue;
1094              }
1095  
1096              // Exclude the currently active parent theme from the list of all themes.
1097              if ( ! empty( $parent_theme ) && $parent_theme->stylesheet === $theme_slug ) {
1098                  continue;
1099              }
1100  
1101              $theme_version = $theme->version;
1102              $theme_author  = $theme->author;
1103  
1104              // Sanitize.
1105              $theme_author = wp_kses( $theme_author, array() );
1106  
1107              $theme_version_string       = __( 'No version or author information is available.' );
1108              $theme_version_string_debug = 'undefined';
1109  
1110              if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) {
1111                  /* translators: 1: Theme version number. 2: Theme author name. */
1112                  $theme_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $theme_version, $theme_author );
1113                  $theme_version_string_debug = sprintf( 'version: %s, author: %s', $theme_version, $theme_author );
1114              } else {
1115                  if ( ! empty( $theme_author ) ) {
1116                      /* translators: %s: Theme author name. */
1117                      $theme_version_string       = sprintf( __( 'By %s' ), $theme_author );
1118                      $theme_version_string_debug = sprintf( 'author: %s, version: (undefined)', $theme_author );
1119                  }
1120  
1121                  if ( ! empty( $theme_version ) ) {
1122                      /* translators: %s: Theme version number. */
1123                      $theme_version_string       = sprintf( __( 'Version %s' ), $theme_version );
1124                      $theme_version_string_debug = sprintf( 'author: (undefined), version: %s', $theme_version );
1125                  }
1126              }
1127  
1128              if ( array_key_exists( $theme_slug, $theme_updates ) ) {
1129                  /* translators: %s: Latest theme version number. */
1130                  $theme_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $theme_slug ]->update['new_version'] );
1131                  $theme_version_string_debug .= sprintf( ' (latest version: %s)', $theme_updates[ $theme_slug ]->update['new_version'] );
1132              }
1133  
1134              if ( $auto_updates_enabled ) {
1135                  if ( in_array( $theme_slug, $auto_updates, true ) ) {
1136                      $theme_version_string       .= ' | ' . $auto_updates_enabled_str;
1137                      $theme_version_string_debug .= ',' . $auto_updates_enabled_str;
1138                  } else {
1139                      $theme_version_string       .= ' | ' . $auto_updates_disabled_str;
1140                      $theme_version_string_debug .= ', ' . $auto_updates_disabled_str;
1141                  }
1142              }
1143  
1144              $info['wp-themes-inactive']['fields'][ sanitize_text_field( $theme->name ) ] = array(
1145                  'label' => sprintf(
1146                      /* translators: 1: Theme name. 2: Theme slug. */
1147                      __( '%1$s (%2$s)' ),
1148                      $theme->name,
1149                      $theme_slug
1150                  ),
1151                  'value' => $theme_version_string,
1152                  'debug' => $theme_version_string_debug,
1153              );
1154          }
1155  
1156          // Add more filesystem checks.
1157          if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
1158              $is_writable_wpmu_plugin_dir = wp_is_writable( WPMU_PLUGIN_DIR );
1159  
1160              $info['wp-filesystem']['fields']['mu-plugins'] = array(
1161                  'label' => __( 'The must use plugins directory' ),
1162                  'value' => ( $is_writable_wpmu_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
1163                  'debug' => ( $is_writable_wpmu_plugin_dir ? 'writable' : 'not writable' ),
1164              );
1165          }
1166  
1167          /**
1168           * Add or modify the debug information.
1169           *
1170           * Plugin or themes may wish to introduce their own debug information without creating additional admin pages
1171           * they can utilize this filter to introduce their own sections or add more data to existing sections.
1172           *
1173           * Array keys for sections added by core are all prefixed with `wp-`, plugins and themes should use their own slug as
1174           * a prefix, both for consistency as well as avoiding key collisions. Note that the array keys are used as labels
1175           * for the copied data.
1176           *
1177           * All strings are expected to be plain text except $description that can contain inline HTML tags (see below).
1178           *
1179           * @since 5.2.0
1180           *
1181           * @param array $args {
1182           *     The debug information to be added to the core information page.
1183           *
1184           *     This is an associative multi-dimensional array, up to three levels deep. The topmost array holds the sections.
1185           *     Each section has a `$fields` associative array (see below), and each `$value` in `$fields` can be
1186           *     another associative array of name/value pairs when there is more structured data to display.
1187           *
1188           *     @type string  $label        The title for this section of the debug output.
1189           *     @type string  $description  Optional. A description for your information section which may contain basic HTML
1190           *                                 markup, inline tags only as it is outputted in a paragraph.
1191           *     @type boolean $show_count   Optional. If set to `true` the amount of fields will be included in the title for
1192           *                                 this section.
1193           *     @type boolean $private      Optional. If set to `true` the section and all associated fields will be excluded
1194           *                                 from the copied data.
1195           *     @type array   $fields {
1196           *         An associative array containing the data to be displayed.
1197           *
1198           *         @type string  $label    The label for this piece of information.
1199           *         @type string  $value    The output that is displayed for this field. Text should be translated. Can be
1200           *                                 an associative array that is displayed as name/value pairs.
1201           *         @type string  $debug    Optional. The output that is used for this field when the user copies the data.
1202           *                                 It should be more concise and not translated. If not set, the content of `$value` is used.
1203           *                                 Note that the array keys are used as labels for the copied data.
1204           *         @type boolean $private  Optional. If set to `true` the field will not be included in the copied data
1205           *                                 allowing you to show, for example, API keys here.
1206           *     }
1207           * }
1208           */
1209          $info = apply_filters( 'debug_information', $info );
1210  
1211          return $info;
1212      }
1213  
1214      /**
1215       * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
1216       *
1217       * @since 5.2.0
1218       *
1219       * @param array $info_array Information gathered from the `WP_Debug_Data::debug_data` function.
1220       * @param string $type      The data type to return, either 'info' or 'debug'.
1221       * @return string The formatted data.
1222       */
1223  	public static function format( $info_array, $type ) {
1224          $return = "`\n";
1225  
1226          foreach ( $info_array as $section => $details ) {
1227              // Skip this section if there are no fields, or the section has been declared as private.
1228              if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
1229                  continue;
1230              }
1231  
1232              $section_label = 'debug' === $type ? $section : $details['label'];
1233  
1234              $return .= sprintf(
1235                  "### %s%s ###\n\n",
1236                  $section_label,
1237                  ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
1238              );
1239  
1240              foreach ( $details['fields'] as $field_name => $field ) {
1241                  if ( isset( $field['private'] ) && true === $field['private'] ) {
1242                      continue;
1243                  }
1244  
1245                  if ( 'debug' === $type && isset( $field['debug'] ) ) {
1246                      $debug_data = $field['debug'];
1247                  } else {
1248                      $debug_data = $field['value'];
1249                  }
1250  
1251                  // Can be array, one level deep only.
1252                  if ( is_array( $debug_data ) ) {
1253                      $value = '';
1254  
1255                      foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
1256                          $value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
1257                      }
1258                  } elseif ( is_bool( $debug_data ) ) {
1259                      $value = $debug_data ? 'true' : 'false';
1260                  } elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
1261                      $value = 'undefined';
1262                  } else {
1263                      $value = $debug_data;
1264                  }
1265  
1266                  if ( 'debug' === $type ) {
1267                      $label = $field_name;
1268                  } else {
1269                      $label = $field['label'];
1270                  }
1271  
1272                  $return .= sprintf( "%s: %s\n", $label, $value );
1273              }
1274  
1275              $return .= "\n";
1276          }
1277  
1278          $return .= '`';
1279  
1280          return $return;
1281      }
1282  
1283      /**
1284       * Fetch the total size of all the database tables for the active database user.
1285       *
1286       * @since 5.2.0
1287       *
1288       * @return int The size of the database, in bytes.
1289       */
1290  	public static function get_database_size() {
1291          global $wpdb;
1292          $size = 0;
1293          $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
1294  
1295          if ( $wpdb->num_rows > 0 ) {
1296              foreach ( $rows as $row ) {
1297                  $size += $row['Data_length'] + $row['Index_length'];
1298              }
1299          }
1300  
1301          return (int) $size;
1302      }
1303  
1304      /**
1305       * Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
1306       * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
1307       *
1308       * @since 5.2.0
1309       *
1310       * @return array The sizes of the directories, also the database size and total installation size.
1311       */
1312  	public static function get_sizes() {
1313          $size_db    = self::get_database_size();
1314          $upload_dir = wp_get_upload_dir();
1315  
1316          /*
1317           * We will be using the PHP max execution time to prevent the size calculations
1318           * from causing a timeout. The default value is 30 seconds, and some
1319           * hosts do not allow you to read configuration values.
1320           */
1321          if ( function_exists( 'ini_get' ) ) {
1322              $max_execution_time = ini_get( 'max_execution_time' );
1323          }
1324  
1325          // The max_execution_time defaults to 0 when PHP runs from cli.
1326          // We still want to limit it below.
1327          if ( empty( $max_execution_time ) ) {
1328              $max_execution_time = 30;
1329          }
1330  
1331          if ( $max_execution_time > 20 ) {
1332              // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
1333              // edge-case timeouts that may happen after the size loop has finished running.
1334              $max_execution_time -= 2;
1335          }
1336  
1337          // Go through the various installation directories and calculate their sizes.
1338          // No trailing slashes.
1339          $paths = array(
1340              'wordpress_size' => untrailingslashit( ABSPATH ),
1341              'themes_size'    => get_theme_root(),
1342              'plugins_size'   => WP_PLUGIN_DIR,
1343              'uploads_size'   => $upload_dir['basedir'],
1344          );
1345  
1346          $exclude = $paths;
1347          unset( $exclude['wordpress_size'] );
1348          $exclude = array_values( $exclude );
1349  
1350          $size_total = 0;
1351          $all_sizes  = array();
1352  
1353          // Loop over all the directories we want to gather the sizes for.
1354          foreach ( $paths as $name => $path ) {
1355              $dir_size = null; // Default to timeout.
1356              $results  = array(
1357                  'path' => $path,
1358                  'raw'  => 0,
1359              );
1360  
1361              if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
1362                  if ( 'wordpress_size' === $name ) {
1363                      $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
1364                  } else {
1365                      $dir_size = recurse_dirsize( $path, null, $max_execution_time );
1366                  }
1367              }
1368  
1369              if ( false === $dir_size ) {
1370                  // Error reading.
1371                  $results['size']  = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
1372                  $results['debug'] = 'not accessible';
1373  
1374                  // Stop total size calculation.
1375                  $size_total = null;
1376              } elseif ( null === $dir_size ) {
1377                  // Timeout.
1378                  $results['size']  = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
1379                  $results['debug'] = 'timeout while calculating size';
1380  
1381                  // Stop total size calculation.
1382                  $size_total = null;
1383              } else {
1384                  if ( null !== $size_total ) {
1385                      $size_total += $dir_size;
1386                  }
1387  
1388                  $results['raw']   = $dir_size;
1389                  $results['size']  = size_format( $dir_size, 2 );
1390                  $results['debug'] = $results['size'] . " ({$dir_size} bytes)";
1391              }
1392  
1393              $all_sizes[ $name ] = $results;
1394          }
1395  
1396          if ( $size_db > 0 ) {
1397              $database_size = size_format( $size_db, 2 );
1398  
1399              $all_sizes['database_size'] = array(
1400                  'raw'   => $size_db,
1401                  'size'  => $database_size,
1402                  'debug' => $database_size . " ({$size_db} bytes)",
1403              );
1404          } else {
1405              $all_sizes['database_size'] = array(
1406                  'size'  => __( 'Not available' ),
1407                  'debug' => 'not available',
1408              );
1409          }
1410  
1411          if ( null !== $size_total && $size_db > 0 ) {
1412              $total_size    = $size_total + $size_db;
1413              $total_size_mb = size_format( $total_size, 2 );
1414  
1415              $all_sizes['total_size'] = array(
1416                  'raw'   => $total_size,
1417                  'size'  => $total_size_mb,
1418                  'debug' => $total_size_mb . " ({$total_size} bytes)",
1419              );
1420          } else {
1421              $all_sizes['total_size'] = array(
1422                  'size'  => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
1423                  'debug' => 'not available',
1424              );
1425          }
1426  
1427          return $all_sizes;
1428      }
1429  }


Generated: Thu Jul 16 01:00:03 2020 Cross-referenced by PHPXref 0.7.1