[ Index ]

WordPress 5.4.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

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


Generated: Tue May 19 15:51:04 2020 Cross-referenced by PHPXref 0.7.1