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


Generated: Tue Apr 7 01:00:07 2020 Cross-referenced by PHPXref 0.7.1