[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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 ?: __( '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 64bit
 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              $info['wp-server']['fields']['htaccess_extra_rules'] = array(
 708                  'label' => __( '.htaccess rules' ),
 709                  'value' => ( $filtered_htaccess_content ? __( 'Custom rules have been added to your .htaccess file.' ) : __( 'Your .htaccess file contains only core WordPress features.' ) ),
 710                  'debug' => $filtered_htaccess_content,
 711              );
 712          }
 713  
 714          // Populate the database debug fields.
 715          if ( is_resource( $wpdb->dbh ) ) {
 716              // Old mysql extension.
 717              $extension = 'mysql';
 718          } elseif ( is_object( $wpdb->dbh ) ) {
 719              // mysqli or PDO.
 720              $extension = get_class( $wpdb->dbh );
 721          } else {
 722              // Unknown sql extension.
 723              $extension = null;
 724          }
 725  
 726          $server = $wpdb->get_var( 'SELECT VERSION()' );
 727  
 728          if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) {
 729              $client_version = $wpdb->dbh->client_info;
 730          } else {
 731              // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
 732              if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) {
 733                  $client_version = $matches[0];
 734              } else {
 735                  $client_version = null;
 736              }
 737          }
 738  
 739          $info['wp-database']['fields']['extension'] = array(
 740              'label' => __( 'Extension' ),
 741              'value' => $extension,
 742          );
 743  
 744          $info['wp-database']['fields']['server_version'] = array(
 745              'label' => __( 'Server version' ),
 746              'value' => $server,
 747          );
 748  
 749          $info['wp-database']['fields']['client_version'] = array(
 750              'label' => __( 'Client version' ),
 751              'value' => $client_version,
 752          );
 753  
 754          $info['wp-database']['fields']['database_user'] = array(
 755              'label'   => __( 'Database user' ),
 756              'value'   => $wpdb->dbuser,
 757              'private' => true,
 758          );
 759  
 760          $info['wp-database']['fields']['database_host'] = array(
 761              'label'   => __( 'Database host' ),
 762              'value'   => $wpdb->dbhost,
 763              'private' => true,
 764          );
 765  
 766          $info['wp-database']['fields']['database_name'] = array(
 767              'label'   => __( 'Database name' ),
 768              'value'   => $wpdb->dbname,
 769              'private' => true,
 770          );
 771  
 772          $info['wp-database']['fields']['database_prefix'] = array(
 773              'label'   => __( 'Database prefix' ),
 774              'value'   => $wpdb->prefix,
 775              'private' => true,
 776          );
 777  
 778          $info['wp-database']['fields']['database_charset'] = array(
 779              'label'   => __( 'Database charset' ),
 780              'value'   => $wpdb->charset,
 781              'private' => true,
 782          );
 783  
 784          $info['wp-database']['fields']['database_collate'] = array(
 785              'label'   => __( 'Database collation' ),
 786              'value'   => $wpdb->collate,
 787              'private' => true,
 788          );
 789  
 790          // List must use plugins if there are any.
 791          $mu_plugins = get_mu_plugins();
 792  
 793          foreach ( $mu_plugins as $plugin_path => $plugin ) {
 794              $plugin_version = $plugin['Version'];
 795              $plugin_author  = $plugin['Author'];
 796  
 797              $plugin_version_string       = __( 'No version or author information is available.' );
 798              $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
 799  
 800              if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
 801                  /* translators: 1: Plugin version number. 2: Plugin author name. */
 802                  $plugin_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
 803                  $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
 804              } else {
 805                  if ( ! empty( $plugin_author ) ) {
 806                      /* translators: %s: Plugin author name. */
 807                      $plugin_version_string       = sprintf( __( 'By %s' ), $plugin_author );
 808                      $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
 809                  }
 810  
 811                  if ( ! empty( $plugin_version ) ) {
 812                      /* translators: %s: Plugin version number. */
 813                      $plugin_version_string       = sprintf( __( 'Version %s' ), $plugin_version );
 814                      $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
 815                  }
 816              }
 817  
 818              $info['wp-mu-plugins']['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
 819                  'label' => $plugin['Name'],
 820                  'value' => $plugin_version_string,
 821                  'debug' => $plugin_version_string_debug,
 822              );
 823          }
 824  
 825          // List all available plugins.
 826          $plugins        = get_plugins();
 827          $plugin_updates = get_plugin_updates();
 828  
 829          foreach ( $plugins as $plugin_path => $plugin ) {
 830              $plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive';
 831  
 832              $plugin_version = $plugin['Version'];
 833              $plugin_author  = $plugin['Author'];
 834  
 835              $plugin_version_string       = __( 'No version or author information is available.' );
 836              $plugin_version_string_debug = 'author: (undefined), version: (undefined)';
 837  
 838              if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) {
 839                  /* translators: 1: Plugin version number. 2: Plugin author name. */
 840                  $plugin_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $plugin_version, $plugin_author );
 841                  $plugin_version_string_debug = sprintf( 'version: %s, author: %s', $plugin_version, $plugin_author );
 842              } else {
 843                  if ( ! empty( $plugin_author ) ) {
 844                      /* translators: %s: Plugin author name. */
 845                      $plugin_version_string       = sprintf( __( 'By %s' ), $plugin_author );
 846                      $plugin_version_string_debug = sprintf( 'author: %s, version: (undefined)', $plugin_author );
 847                  }
 848  
 849                  if ( ! empty( $plugin_version ) ) {
 850                      /* translators: %s: Plugin version number. */
 851                      $plugin_version_string       = sprintf( __( 'Version %s' ), $plugin_version );
 852                      $plugin_version_string_debug = sprintf( 'author: (undefined), version: %s', $plugin_version );
 853                  }
 854              }
 855  
 856              if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
 857                  /* translators: %s: Latest plugin version number. */
 858                  $plugin_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $plugin_updates[ $plugin_path ]->update->new_version );
 859                  $plugin_version_string_debug .= sprintf( ' (latest version: %s)', $plugin_updates[ $plugin_path ]->update->new_version );
 860              }
 861  
 862              $info[ $plugin_part ]['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
 863                  'label' => $plugin['Name'],
 864                  'value' => $plugin_version_string,
 865                  'debug' => $plugin_version_string_debug,
 866              );
 867          }
 868  
 869          // Populate the section for the currently active theme.
 870          global $_wp_theme_features;
 871          $theme_features = array();
 872  
 873          if ( ! empty( $_wp_theme_features ) ) {
 874              foreach ( $_wp_theme_features as $feature => $options ) {
 875                  $theme_features[] = $feature;
 876              }
 877          }
 878  
 879          $active_theme  = wp_get_theme();
 880          $theme_updates = get_theme_updates();
 881  
 882          // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
 883          $active_theme_version       = $active_theme->Version;
 884          $active_theme_version_debug = $active_theme_version;
 885  
 886          if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
 887              $theme_update_new_version = $theme_updates[ $active_theme->stylesheet ]->update['new_version'];
 888  
 889              /* translators: %s: Latest theme version number. */
 890              $active_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_update_new_version );
 891              $active_theme_version_debug .= sprintf( ' (latest version: %s)', $theme_update_new_version );
 892          }
 893  
 894          $active_theme_author_uri = $active_theme->offsetGet( 'Author URI' );
 895  
 896          if ( $active_theme->parent_theme ) {
 897              $active_theme_parent_theme = sprintf(
 898                  /* translators: 1: Theme name. 2: Theme slug. */
 899                  __( '%1$s (%2$s)' ),
 900                  $active_theme->parent_theme,
 901                  $active_theme->template
 902              );
 903              $active_theme_parent_theme_debug = sprintf(
 904                  '%s (%s)',
 905                  $active_theme->parent_theme,
 906                  $active_theme->template
 907              );
 908          } else {
 909              $active_theme_parent_theme       = __( 'None' );
 910              $active_theme_parent_theme_debug = 'none';
 911          }
 912  
 913          $info['wp-active-theme']['fields'] = array(
 914              'name'           => array(
 915                  'label' => __( 'Name' ),
 916                  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
 917                  'value' => sprintf(
 918                      /* translators: 1: Theme name. 2: Theme slug. */
 919                      __( '%1$s (%2$s)' ),
 920                      // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
 921                      $active_theme->Name,
 922                      $active_theme->stylesheet
 923                  ),
 924              ),
 925              'version'        => array(
 926                  'label' => __( 'Version' ),
 927                  'value' => $active_theme_version,
 928                  'debug' => $active_theme_version_debug,
 929              ),
 930              'author'         => array(
 931                  'label' => __( 'Author' ),
 932                  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
 933                  'value' => wp_kses( $active_theme->Author, array() ),
 934              ),
 935              'author_website' => array(
 936                  'label' => __( 'Author website' ),
 937                  'value' => ( $active_theme_author_uri ? $active_theme_author_uri : __( 'Undefined' ) ),
 938                  'debug' => ( $active_theme_author_uri ? $active_theme_author_uri : '(undefined)' ),
 939              ),
 940              'parent_theme'   => array(
 941                  'label' => __( 'Parent theme' ),
 942                  'value' => $active_theme_parent_theme,
 943                  'debug' => $active_theme_parent_theme_debug,
 944              ),
 945              'theme_features' => array(
 946                  'label' => __( 'Theme features' ),
 947                  'value' => implode( ', ', $theme_features ),
 948              ),
 949              'theme_path'     => array(
 950                  'label' => __( 'Theme directory location' ),
 951                  'value' => get_stylesheet_directory(),
 952              ),
 953          );
 954  
 955          $parent_theme = $active_theme->parent();
 956  
 957          if ( $parent_theme ) {
 958              // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
 959              $parent_theme_version       = $parent_theme->Version;
 960              $parent_theme_version_debug = $parent_theme_version;
 961  
 962              if ( array_key_exists( $parent_theme->stylesheet, $theme_updates ) ) {
 963                  $parent_theme_update_new_version = $theme_updates[ $parent_theme->stylesheet ]->update['new_version'];
 964  
 965                  /* translators: %s: Latest theme version number. */
 966                  $parent_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $parent_theme_update_new_version );
 967                  $parent_theme_version_debug .= sprintf( ' (latest version: %s)', $parent_theme_update_new_version );
 968              }
 969  
 970              $parent_theme_author_uri = $parent_theme->offsetGet( 'Author URI' );
 971  
 972              $info['wp-parent-theme']['fields'] = array(
 973                  'name'           => array(
 974                      'label' => __( 'Name' ),
 975                      // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
 976                      'value' => sprintf(
 977                          /* translators: 1: Theme name. 2: Theme slug. */
 978                          __( '%1$s (%2$s)' ),
 979                          // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
 980                          $parent_theme->Name,
 981                          $parent_theme->stylesheet
 982                      ),
 983                  ),
 984                  'version'        => array(
 985                      'label' => __( 'Version' ),
 986                      'value' => $parent_theme_version,
 987                      'debug' => $parent_theme_version_debug,
 988                  ),
 989                  'author'         => array(
 990                      'label' => __( 'Author' ),
 991                      // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
 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              // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1021              $theme_version = $theme->Version;
1022              // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1023              $theme_author = $theme->Author;
1024  
1025              // Sanitize
1026              $theme_author = wp_kses( $theme_author, array() );
1027  
1028              $theme_version_string       = __( 'No version or author information is available.' );
1029              $theme_version_string_debug = 'undefined';
1030  
1031              if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) {
1032                  /* translators: 1: Theme version number. 2: Theme author name. */
1033                  $theme_version_string       = sprintf( __( 'Version %1$s by %2$s' ), $theme_version, $theme_author );
1034                  $theme_version_string_debug = sprintf( 'version: %s, author: %s', $theme_version, $theme_author );
1035              } else {
1036                  if ( ! empty( $theme_author ) ) {
1037                      /* translators: %s: Theme author name. */
1038                      $theme_version_string       = sprintf( __( 'By %s' ), $theme_author );
1039                      $theme_version_string_debug = sprintf( 'author: %s, version: (undefined)', $theme_author );
1040                  }
1041  
1042                  if ( ! empty( $theme_version ) ) {
1043                      /* translators: %s: Theme version number. */
1044                      $theme_version_string       = sprintf( __( 'Version %s' ), $theme_version );
1045                      $theme_version_string_debug = sprintf( 'author: (undefined), version: %s', $theme_version );
1046                  }
1047              }
1048  
1049              if ( array_key_exists( $theme_slug, $theme_updates ) ) {
1050                  /* translators: %s: Latest theme version number. */
1051                  $theme_version_string       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_updates[ $theme_slug ]->update['new_version'] );
1052                  $theme_version_string_debug .= sprintf( ' (latest version: %s)', $theme_updates[ $theme_slug ]->update['new_version'] );
1053              }
1054  
1055              // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1056              $info['wp-themes-inactive']['fields'][ sanitize_text_field( $theme->Name ) ] = array(
1057                  'label' => sprintf(
1058                      /* translators: 1: Theme name. 2: Theme slug. */
1059                      __( '%1$s (%2$s)' ),
1060                      // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1061                      $theme->Name,
1062                      $theme_slug
1063                  ),
1064                  'value' => $theme_version_string,
1065                  'debug' => $theme_version_string_debug,
1066              );
1067          }
1068  
1069          // Add more filesystem checks
1070          if ( defined( 'WPMU_PLUGIN_DIR' ) && is_dir( WPMU_PLUGIN_DIR ) ) {
1071              $is_writable_wpmu_plugin_dir = wp_is_writable( WPMU_PLUGIN_DIR );
1072  
1073              $info['wp-filesystem']['fields']['mu-plugins'] = array(
1074                  'label' => __( 'The must use plugins directory' ),
1075                  'value' => ( $is_writable_wpmu_plugin_dir ? __( 'Writable' ) : __( 'Not writable' ) ),
1076                  'debug' => ( $is_writable_wpmu_plugin_dir ? 'writable' : 'not writable' ),
1077              );
1078          }
1079  
1080          /**
1081           * Add or modify the debug information.
1082           *
1083           * Plugin or themes may wish to introduce their own debug information without creating additional admin pages
1084           * they can utilize this filter to introduce their own sections or add more data to existing sections.
1085           *
1086           * Array keys for sections added by core are all prefixed with `wp-`, plugins and themes should use their own slug as
1087           * a prefix, both for consistency as well as avoiding key collisions. Note that the array keys are used as labels
1088           * for the copied data.
1089           *
1090           * All strings are expected to be plain text except $description that can contain inline HTML tags (see below).
1091           *
1092           * @since 5.2.0
1093           *
1094           * @param array $args {
1095           *     The debug information to be added to the core information page.
1096           *
1097           *     This is an associative multi-dimensional array, up to three levels deep. The topmost array holds the sections.
1098           *     Each section has a `$fields` associative array (see below), and each `$value` in `$fields` can be
1099           *     another associative array of name/value pairs when there is more structured data to display.
1100           *
1101           *     @type string  $label        The title for this section of the debug output.
1102           *     @type string  $description  Optional. A description for your information section which may contain basic HTML
1103           *                                 markup, inline tags only as it is outputted in a paragraph.
1104           *     @type boolean $show_count   Optional. If set to `true` the amount of fields will be included in the title for
1105           *                                 this section.
1106           *     @type boolean $private      Optional. If set to `true` the section and all associated fields will be excluded
1107           *                                 from the copied data.
1108           *     @type array   $fields {
1109           *         An associative array containing the data to be displayed.
1110           *
1111           *         @type string  $label    The label for this piece of information.
1112           *         @type string  $value    The output that is displayed for this field. Text should be translated. Can be
1113           *                                 an associative array that is displayed as name/value pairs.
1114           *         @type string  $debug    Optional. The output that is used for this field when the user copies the data.
1115           *                                 It should be more concise and not translated. If not set, the content of `$value` is used.
1116           *                                 Note that the array keys are used as labels for the copied data.
1117           *         @type boolean $private  Optional. If set to `true` the field will not be included in the copied data
1118           *                                 allowing you to show, for example, API keys here.
1119           *     }
1120           * }
1121           */
1122          $info = apply_filters( 'debug_information', $info );
1123  
1124          return $info;
1125      }
1126  
1127      /**
1128       * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
1129       *
1130       * @since 5.2.0
1131       *
1132       * @param array $info_array Information gathered from the `WP_Debug_Data::debug_data` function.
1133       * @param string $type      The data type to return, either 'info' or 'debug'.
1134       * @return string The formatted data.
1135       */
1136  	public static function format( $info_array, $type ) {
1137          $return = "`\n";
1138  
1139          foreach ( $info_array as $section => $details ) {
1140              // Skip this section if there are no fields, or the section has been declared as private.
1141              if ( empty( $details['fields'] ) || ( isset( $details['private'] ) && $details['private'] ) ) {
1142                  continue;
1143              }
1144  
1145              $section_label = 'debug' === $type ? $section : $details['label'];
1146  
1147              $return .= sprintf(
1148                  "### %s%s ###\n\n",
1149                  $section_label,
1150                  ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' )
1151              );
1152  
1153              foreach ( $details['fields'] as $field_name => $field ) {
1154                  if ( isset( $field['private'] ) && true === $field['private'] ) {
1155                      continue;
1156                  }
1157  
1158                  if ( 'debug' === $type && isset( $field['debug'] ) ) {
1159                      $debug_data = $field['debug'];
1160                  } else {
1161                      $debug_data = $field['value'];
1162                  }
1163  
1164                  // Can be array, one level deep only.
1165                  if ( is_array( $debug_data ) ) {
1166                      $value = '';
1167  
1168                      foreach ( $debug_data as $sub_field_name => $sub_field_value ) {
1169                          $value .= sprintf( "\n\t%s: %s", $sub_field_name, $sub_field_value );
1170                      }
1171                  } elseif ( is_bool( $debug_data ) ) {
1172                      $value = $debug_data ? 'true' : 'false';
1173                  } elseif ( empty( $debug_data ) && '0' !== $debug_data ) {
1174                      $value = 'undefined';
1175                  } else {
1176                      $value = $debug_data;
1177                  }
1178  
1179                  if ( 'debug' === $type ) {
1180                      $label = $field_name;
1181                  } else {
1182                      $label = $field['label'];
1183                  }
1184  
1185                  $return .= sprintf( "%s: %s\n", $label, $value );
1186              }
1187  
1188              $return .= "\n";
1189          }
1190  
1191          $return .= '`';
1192  
1193          return $return;
1194      }
1195  
1196      /**
1197       * Fetch the total size of all the database tables for the active database user.
1198       *
1199       * @since 5.2.0
1200       *
1201       * @return int The size of the database, in bytes.
1202       */
1203  	public static function get_database_size() {
1204          global $wpdb;
1205          $size = 0;
1206          $rows = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A );
1207  
1208          if ( $wpdb->num_rows > 0 ) {
1209              foreach ( $rows as $row ) {
1210                  $size += $row['Data_length'] + $row['Index_length'];
1211              }
1212          }
1213  
1214          return (int) $size;
1215      }
1216  
1217      /**
1218       * Fetch the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`.
1219       * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`.
1220       *
1221       * @since 5.2.0
1222       *
1223       * @return array The sizes of the directories, also the database size and total installation size.
1224       */
1225  	public static function get_sizes() {
1226          $size_db    = self::get_database_size();
1227          $upload_dir = wp_get_upload_dir();
1228  
1229          /*
1230           * We will be using the PHP max execution time to prevent the size calculations
1231           * from causing a timeout. The default value is 30 seconds, and some
1232           * hosts do not allow you to read configuration values.
1233           */
1234          if ( function_exists( 'ini_get' ) ) {
1235              $max_execution_time = ini_get( 'max_execution_time' );
1236          }
1237  
1238          // The max_execution_time defaults to 0 when PHP runs from cli.
1239          // We still want to limit it below.
1240          if ( empty( $max_execution_time ) ) {
1241              $max_execution_time = 30;
1242          }
1243  
1244          if ( $max_execution_time > 20 ) {
1245              // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
1246              // edge-case timeouts that may happen after the size loop has finished running.
1247              $max_execution_time -= 2;
1248          }
1249  
1250          // Go through the various installation directories and calculate their sizes.
1251          // No trailing slashes.
1252          $paths = array(
1253              'wordpress_size' => untrailingslashit( ABSPATH ),
1254              'themes_size'    => get_theme_root(),
1255              'plugins_size'   => WP_PLUGIN_DIR,
1256              'uploads_size'   => $upload_dir['basedir'],
1257          );
1258  
1259          $exclude = $paths;
1260          unset( $exclude['wordpress_size'] );
1261          $exclude = array_values( $exclude );
1262  
1263          $size_total = 0;
1264          $all_sizes  = array();
1265  
1266          // Loop over all the directories we want to gather the sizes for.
1267          foreach ( $paths as $name => $path ) {
1268              $dir_size = null; // Default to timeout.
1269              $results  = array(
1270                  'path' => $path,
1271                  'raw'  => 0,
1272              );
1273  
1274              if ( microtime( true ) - WP_START_TIMESTAMP < $max_execution_time ) {
1275                  if ( 'wordpress_size' === $name ) {
1276                      $dir_size = recurse_dirsize( $path, $exclude, $max_execution_time );
1277                  } else {
1278                      $dir_size = recurse_dirsize( $path, null, $max_execution_time );
1279                  }
1280              }
1281  
1282              if ( false === $dir_size ) {
1283                  // Error reading.
1284                  $results['size']  = __( 'The size cannot be calculated. The directory is not accessible. Usually caused by invalid permissions.' );
1285                  $results['debug'] = 'not accessible';
1286  
1287                  // Stop total size calculation.
1288                  $size_total = null;
1289              } elseif ( null === $dir_size ) {
1290                  // Timeout.
1291                  $results['size']  = __( 'The directory size calculation has timed out. Usually caused by a very large number of sub-directories and files.' );
1292                  $results['debug'] = 'timeout while calculating size';
1293  
1294                  // Stop total size calculation.
1295                  $size_total = null;
1296              } else {
1297                  if ( null !== $size_total ) {
1298                      $size_total += $dir_size;
1299                  }
1300  
1301                  $results['raw']   = $dir_size;
1302                  $results['size']  = size_format( $dir_size, 2 );
1303                  $results['debug'] = $results['size'] . " ({$dir_size} bytes)";
1304              }
1305  
1306              $all_sizes[ $name ] = $results;
1307          }
1308  
1309          if ( $size_db > 0 ) {
1310              $database_size = size_format( $size_db, 2 );
1311  
1312              $all_sizes['database_size'] = array(
1313                  'raw'   => $size_db,
1314                  'size'  => $database_size,
1315                  'debug' => $database_size . " ({$size_db} bytes)",
1316              );
1317          } else {
1318              $all_sizes['database_size'] = array(
1319                  'size'  => __( 'Not available' ),
1320                  'debug' => 'not available',
1321              );
1322          }
1323  
1324          if ( null !== $size_total && $size_db > 0 ) {
1325              $total_size    = $size_total + $size_db;
1326              $total_size_mb = size_format( $total_size, 2 );
1327  
1328              $all_sizes['total_size'] = array(
1329                  'raw'   => $total_size,
1330                  'size'  => $total_size_mb,
1331                  'debug' => $total_size_mb . " ({$total_size} bytes)",
1332              );
1333          } else {
1334              $all_sizes['total_size'] = array(
1335                  'size'  => __( 'Total size is not available. Some errors were encountered when determining the size of your installation.' ),
1336                  'debug' => 'not available',
1337              );
1338          }
1339  
1340          return $all_sizes;
1341      }
1342  }


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7