[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> plugin.php (source)

   1  <?php
   2  /**
   3   * WordPress Plugin Administration API
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /**
  10   * Parses the plugin contents to retrieve plugin's metadata.
  11   *
  12   * All plugin headers must be on their own line. Plugin description must not have
  13   * any newlines, otherwise only parts of the description will be displayed.
  14   * The below is formatted for printing.
  15   *
  16   *     /*
  17   *     Plugin Name: Name of the plugin.
  18   *     Plugin URI: The home page of the plugin.
  19   *     Description: Plugin description.
  20   *     Author: Plugin author's name.
  21   *     Author URI: Link to the author's website.
  22   *     Version: Plugin version.
  23   *     Text Domain: Optional. Unique identifier, should be same as the one used in
  24   *          load_plugin_textdomain().
  25   *     Domain Path: Optional. Only useful if the translations are located in a
  26   *          folder above the plugin's base path. For example, if .mo files are
  27   *          located in the locale folder then Domain Path will be "/locale/" and
  28   *          must have the first slash. Defaults to the base folder the plugin is
  29   *          located in.
  30   *     Network: Optional. Specify "Network: true" to require that a plugin is activated
  31   *          across all sites in an installation. This will prevent a plugin from being
  32   *          activated on a single site when Multisite is enabled.
  33   *     Requires at least: Optional. Specify the minimum required WordPress version.
  34   *     Requires PHP: Optional. Specify the minimum required PHP version.
  35   *     * / # Remove the space to close comment.
  36   *
  37   * The first 8 KB of the file will be pulled in and if the plugin data is not
  38   * within that first 8 KB, then the plugin author should correct their plugin
  39   * and move the plugin data headers to the top.
  40   *
  41   * The plugin file is assumed to have permissions to allow for scripts to read
  42   * the file. This is not checked however and the file is only opened for
  43   * reading.
  44   *
  45   * @since 1.5.0
  46   * @since 5.3.0 Added support for `Requires at least` and `Requires PHP` headers.
  47   *
  48   * @param string $plugin_file Absolute path to the main plugin file.
  49   * @param bool   $markup      Optional. If the returned data should have HTML markup applied.
  50   *                            Default true.
  51   * @param bool   $translate   Optional. If the returned data should be translated. Default true.
  52   * @return array {
  53   *     Plugin data. Values will be empty if not supplied by the plugin.
  54   *
  55   *     @type string $Name        Name of the plugin. Should be unique.
  56   *     @type string $Title       Title of the plugin and link to the plugin's site (if set).
  57   *     @type string $Description Plugin description.
  58   *     @type string $Author      Author's name.
  59   *     @type string $AuthorURI   Author's website address (if set).
  60   *     @type string $Version     Plugin version.
  61   *     @type string $TextDomain  Plugin textdomain.
  62   *     @type string $DomainPath  Plugins relative directory path to .mo files.
  63   *     @type bool   $Network     Whether the plugin can only be activated network-wide.
  64   *     @type string $RequiresWP  Minimum required version of WordPress.
  65   *     @type string $RequiresPHP Minimum required version of PHP.
  66   * }
  67   */
  68  function get_plugin_data( $plugin_file, $markup = true, $translate = true ) {
  69  
  70      $default_headers = array(
  71          'Name'        => 'Plugin Name',
  72          'PluginURI'   => 'Plugin URI',
  73          'Version'     => 'Version',
  74          'Description' => 'Description',
  75          'Author'      => 'Author',
  76          'AuthorURI'   => 'Author URI',
  77          'TextDomain'  => 'Text Domain',
  78          'DomainPath'  => 'Domain Path',
  79          'Network'     => 'Network',
  80          'RequiresWP'  => 'Requires at least',
  81          'RequiresPHP' => 'Requires PHP',
  82          // Site Wide Only is deprecated in favor of Network.
  83          '_sitewide'   => 'Site Wide Only',
  84      );
  85  
  86      $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );
  87  
  88      // Site Wide Only is the old header for Network.
  89      if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) {
  90          /* translators: 1: Site Wide Only: true, 2: Network: true */
  91          _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The %1$s plugin header is deprecated. Use %2$s instead.' ), '<code>Site Wide Only: true</code>', '<code>Network: true</code>' ) );
  92          $plugin_data['Network'] = $plugin_data['_sitewide'];
  93      }
  94      $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) );
  95      unset( $plugin_data['_sitewide'] );
  96  
  97      // If no text domain is defined fall back to the plugin slug.
  98      if ( ! $plugin_data['TextDomain'] ) {
  99          $plugin_slug = dirname( plugin_basename( $plugin_file ) );
 100          if ( '.' !== $plugin_slug && false === strpos( $plugin_slug, '/' ) ) {
 101              $plugin_data['TextDomain'] = $plugin_slug;
 102          }
 103      }
 104  
 105      if ( $markup || $translate ) {
 106          $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate );
 107      } else {
 108          $plugin_data['Title']      = $plugin_data['Name'];
 109          $plugin_data['AuthorName'] = $plugin_data['Author'];
 110      }
 111  
 112      return $plugin_data;
 113  }
 114  
 115  /**
 116   * Sanitizes plugin data, optionally adds markup, optionally translates.
 117   *
 118   * @since 2.7.0
 119   *
 120   * @see get_plugin_data()
 121   *
 122   * @access private
 123   *
 124   * @param string $plugin_file Path to the main plugin file.
 125   * @param array  $plugin_data An array of plugin data. See `get_plugin_data()`.
 126   * @param bool   $markup      Optional. If the returned data should have HTML markup applied.
 127   *                            Default true.
 128   * @param bool   $translate   Optional. If the returned data should be translated. Default true.
 129   * @return array {
 130   *     Plugin data. Values will be empty if not supplied by the plugin.
 131   *
 132   *     @type string $Name        Name of the plugin. Should be unique.
 133   *     @type string $Title       Title of the plugin and link to the plugin's site (if set).
 134   *     @type string $Description Plugin description.
 135   *     @type string $Author      Author's name.
 136   *     @type string $AuthorURI   Author's website address (if set).
 137   *     @type string $Version     Plugin version.
 138   *     @type string $TextDomain  Plugin textdomain.
 139   *     @type string $DomainPath  Plugins relative directory path to .mo files.
 140   *     @type bool   $Network     Whether the plugin can only be activated network-wide.
 141   * }
 142   */
 143  function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup = true, $translate = true ) {
 144  
 145      // Sanitize the plugin filename to a WP_PLUGIN_DIR relative path.
 146      $plugin_file = plugin_basename( $plugin_file );
 147  
 148      // Translate fields.
 149      if ( $translate ) {
 150          $textdomain = $plugin_data['TextDomain'];
 151          if ( $textdomain ) {
 152              if ( ! is_textdomain_loaded( $textdomain ) ) {
 153                  if ( $plugin_data['DomainPath'] ) {
 154                      load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] );
 155                  } else {
 156                      load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) );
 157                  }
 158              }
 159          } elseif ( 'hello.php' == basename( $plugin_file ) ) {
 160              $textdomain = 'default';
 161          }
 162          if ( $textdomain ) {
 163              foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) {
 164                  // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
 165                  $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain );
 166              }
 167          }
 168      }
 169  
 170      // Sanitize fields.
 171      $allowed_tags_in_links = array(
 172          'abbr'    => array( 'title' => true ),
 173          'acronym' => array( 'title' => true ),
 174          'code'    => true,
 175          'em'      => true,
 176          'strong'  => true,
 177      );
 178  
 179      $allowed_tags      = $allowed_tags_in_links;
 180      $allowed_tags['a'] = array(
 181          'href'  => true,
 182          'title' => true,
 183      );
 184  
 185      // Name is marked up inside <a> tags. Don't allow these.
 186      // Author is too, but some plugins have used <a> here (omitting Author URI).
 187      $plugin_data['Name']   = wp_kses( $plugin_data['Name'], $allowed_tags_in_links );
 188      $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags );
 189  
 190      $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags );
 191      $plugin_data['Version']     = wp_kses( $plugin_data['Version'], $allowed_tags );
 192  
 193      $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] );
 194      $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] );
 195  
 196      $plugin_data['Title']      = $plugin_data['Name'];
 197      $plugin_data['AuthorName'] = $plugin_data['Author'];
 198  
 199      // Apply markup.
 200      if ( $markup ) {
 201          if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) {
 202              $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>';
 203          }
 204  
 205          if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) {
 206              $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
 207          }
 208  
 209          $plugin_data['Description'] = wptexturize( $plugin_data['Description'] );
 210  
 211          if ( $plugin_data['Author'] ) {
 212              $plugin_data['Description'] .= sprintf(
 213                  /* translators: %s: Plugin author. */
 214                  ' <cite>' . __( 'By %s.' ) . '</cite>',
 215                  $plugin_data['Author']
 216              );
 217          }
 218      }
 219  
 220      return $plugin_data;
 221  }
 222  
 223  /**
 224   * Get a list of a plugin's files.
 225   *
 226   * @since 2.8.0
 227   *
 228   * @param string $plugin Path to the plugin file relative to the plugins directory.
 229   * @return string[] Array of file names relative to the plugin root.
 230   */
 231  function get_plugin_files( $plugin ) {
 232      $plugin_file = WP_PLUGIN_DIR . '/' . $plugin;
 233      $dir         = dirname( $plugin_file );
 234  
 235      $plugin_files = array( plugin_basename( $plugin_file ) );
 236  
 237      if ( is_dir( $dir ) && WP_PLUGIN_DIR !== $dir ) {
 238  
 239          /**
 240           * Filters the array of excluded directories and files while scanning the folder.
 241           *
 242           * @since 4.9.0
 243           *
 244           * @param string[] $exclusions Array of excluded directories and files.
 245           */
 246          $exclusions = (array) apply_filters( 'plugin_files_exclusions', array( 'CVS', 'node_modules', 'vendor', 'bower_components' ) );
 247  
 248          $list_files = list_files( $dir, 100, $exclusions );
 249          $list_files = array_map( 'plugin_basename', $list_files );
 250  
 251          $plugin_files = array_merge( $plugin_files, $list_files );
 252          $plugin_files = array_values( array_unique( $plugin_files ) );
 253      }
 254  
 255      return $plugin_files;
 256  }
 257  
 258  /**
 259   * Check the plugins directory and retrieve all plugin files with plugin data.
 260   *
 261   * WordPress only supports plugin files in the base plugins directory
 262   * (wp-content/plugins) and in one directory above the plugins directory
 263   * (wp-content/plugins/my-plugin). The file it looks for has the plugin data
 264   * and must be found in those two locations. It is recommended to keep your
 265   * plugin files in their own directories.
 266   *
 267   * The file with the plugin data is the file that will be included and therefore
 268   * needs to have the main execution for the plugin. This does not mean
 269   * everything must be contained in the file and it is recommended that the file
 270   * be split for maintainability. Keep everything in one file for extreme
 271   * optimization purposes.
 272   *
 273   * @since 1.5.0
 274   *
 275   * @param string $plugin_folder Optional. Relative path to single plugin folder.
 276   * @return array[] Array of arrays of plugin data, keyed by plugin file name. See `get_plugin_data()`.
 277   */
 278  function get_plugins( $plugin_folder = '' ) {
 279  
 280      $cache_plugins = wp_cache_get( 'plugins', 'plugins' );
 281      if ( ! $cache_plugins ) {
 282          $cache_plugins = array();
 283      }
 284  
 285      if ( isset( $cache_plugins[ $plugin_folder ] ) ) {
 286          return $cache_plugins[ $plugin_folder ];
 287      }
 288  
 289      $wp_plugins  = array();
 290      $plugin_root = WP_PLUGIN_DIR;
 291      if ( ! empty( $plugin_folder ) ) {
 292          $plugin_root .= $plugin_folder;
 293      }
 294  
 295      // Files in wp-content/plugins directory.
 296      $plugins_dir  = @ opendir( $plugin_root );
 297      $plugin_files = array();
 298      if ( $plugins_dir ) {
 299          while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
 300              if ( substr( $file, 0, 1 ) == '.' ) {
 301                  continue;
 302              }
 303              if ( is_dir( $plugin_root . '/' . $file ) ) {
 304                  $plugins_subdir = @ opendir( $plugin_root . '/' . $file );
 305                  if ( $plugins_subdir ) {
 306                      while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) {
 307                          if ( substr( $subfile, 0, 1 ) == '.' ) {
 308                              continue;
 309                          }
 310                          if ( substr( $subfile, -4 ) == '.php' ) {
 311                              $plugin_files[] = "$file/$subfile";
 312                          }
 313                      }
 314                      closedir( $plugins_subdir );
 315                  }
 316              } else {
 317                  if ( substr( $file, -4 ) == '.php' ) {
 318                      $plugin_files[] = $file;
 319                  }
 320              }
 321          }
 322          closedir( $plugins_dir );
 323      }
 324  
 325      if ( empty( $plugin_files ) ) {
 326          return $wp_plugins;
 327      }
 328  
 329      foreach ( $plugin_files as $plugin_file ) {
 330          if ( ! is_readable( "$plugin_root/$plugin_file" ) ) {
 331              continue;
 332          }
 333  
 334          // Do not apply markup/translate as it will be cached.
 335          $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false );
 336  
 337          if ( empty( $plugin_data['Name'] ) ) {
 338              continue;
 339          }
 340  
 341          $wp_plugins[ plugin_basename( $plugin_file ) ] = $plugin_data;
 342      }
 343  
 344      uasort( $wp_plugins, '_sort_uname_callback' );
 345  
 346      $cache_plugins[ $plugin_folder ] = $wp_plugins;
 347      wp_cache_set( 'plugins', $cache_plugins, 'plugins' );
 348  
 349      return $wp_plugins;
 350  }
 351  
 352  /**
 353   * Check the mu-plugins directory and retrieve all mu-plugin files with any plugin data.
 354   *
 355   * WordPress only includes mu-plugin files in the base mu-plugins directory (wp-content/mu-plugins).
 356   *
 357   * @since 3.0.0
 358   * @return array[] Array of arrays of mu-plugin data, keyed by plugin file name. See `get_plugin_data()`.
 359   */
 360  function get_mu_plugins() {
 361      $wp_plugins   = array();
 362      $plugin_files = array();
 363  
 364      if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
 365          return $wp_plugins;
 366      }
 367  
 368      // Files in wp-content/mu-plugins directory.
 369      $plugins_dir = @opendir( WPMU_PLUGIN_DIR );
 370      if ( $plugins_dir ) {
 371          while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
 372              if ( substr( $file, -4 ) == '.php' ) {
 373                  $plugin_files[] = $file;
 374              }
 375          }
 376      } else {
 377          return $wp_plugins;
 378      }
 379  
 380      closedir( $plugins_dir );
 381  
 382      if ( empty( $plugin_files ) ) {
 383          return $wp_plugins;
 384      }
 385  
 386      foreach ( $plugin_files as $plugin_file ) {
 387          if ( ! is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) {
 388              continue;
 389          }
 390  
 391          // Do not apply markup/translate as it will be cached.
 392          $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false );
 393  
 394          if ( empty( $plugin_data['Name'] ) ) {
 395              $plugin_data['Name'] = $plugin_file;
 396          }
 397  
 398          $wp_plugins[ $plugin_file ] = $plugin_data;
 399      }
 400  
 401      if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php' ) <= 30 ) {
 402          // Silence is golden.
 403          unset( $wp_plugins['index.php'] );
 404      }
 405  
 406      uasort( $wp_plugins, '_sort_uname_callback' );
 407  
 408      return $wp_plugins;
 409  }
 410  
 411  /**
 412   * Callback to sort array by a 'Name' key.
 413   *
 414   * @since 3.1.0
 415   *
 416   * @access private
 417   *
 418   * @param array $a array with 'Name' key.
 419   * @param array $b array with 'Name' key.
 420   * @return int Return 0 or 1 based on two string comparison.
 421   */
 422  function _sort_uname_callback( $a, $b ) {
 423      return strnatcasecmp( $a['Name'], $b['Name'] );
 424  }
 425  
 426  /**
 427   * Check the wp-content directory and retrieve all drop-ins with any plugin data.
 428   *
 429   * @since 3.0.0
 430   * @return array[] Array of arrays of dropin plugin data, keyed by plugin file name. See `get_plugin_data()`.
 431   */
 432  function get_dropins() {
 433      $dropins      = array();
 434      $plugin_files = array();
 435  
 436      $_dropins = _get_dropins();
 437  
 438      // Files in wp-content directory.
 439      $plugins_dir = @opendir( WP_CONTENT_DIR );
 440      if ( $plugins_dir ) {
 441          while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
 442              if ( isset( $_dropins[ $file ] ) ) {
 443                  $plugin_files[] = $file;
 444              }
 445          }
 446      } else {
 447          return $dropins;
 448      }
 449  
 450      closedir( $plugins_dir );
 451  
 452      if ( empty( $plugin_files ) ) {
 453          return $dropins;
 454      }
 455  
 456      foreach ( $plugin_files as $plugin_file ) {
 457          if ( ! is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) {
 458              continue;
 459          }
 460  
 461          // Do not apply markup/translate as it will be cached.
 462          $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false );
 463  
 464          if ( empty( $plugin_data['Name'] ) ) {
 465              $plugin_data['Name'] = $plugin_file;
 466          }
 467  
 468          $dropins[ $plugin_file ] = $plugin_data;
 469      }
 470  
 471      uksort( $dropins, 'strnatcasecmp' );
 472  
 473      return $dropins;
 474  }
 475  
 476  /**
 477   * Returns drop-ins that WordPress uses.
 478   *
 479   * Includes Multisite drop-ins only when is_multisite()
 480   *
 481   * @since 3.0.0
 482   * @return array[] Key is file name. The value is an array, with the first value the
 483   *  purpose of the drop-in and the second value the name of the constant that must be
 484   *  true for the drop-in to be used, or true if no constant is required.
 485   */
 486  function _get_dropins() {
 487      $dropins = array(
 488          'advanced-cache.php'      => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ),  // WP_CACHE
 489          'db.php'                  => array( __( 'Custom database class.' ), true ),          // Auto on load.
 490          'db-error.php'            => array( __( 'Custom database error message.' ), true ),  // Auto on error.
 491          'install.php'             => array( __( 'Custom installation script.' ), true ),     // Auto on installation.
 492          'maintenance.php'         => array( __( 'Custom maintenance message.' ), true ),     // Auto on maintenance.
 493          'object-cache.php'        => array( __( 'External object cache.' ), true ),          // Auto on load.
 494          'php-error.php'           => array( __( 'Custom PHP error message.' ), true ),       // Auto on error.
 495          'fatal-error-handler.php' => array( __( 'Custom PHP fatal error handler.' ), true ), // Auto on error.
 496      );
 497  
 498      if ( is_multisite() ) {
 499          $dropins['sunrise.php']        = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE
 500          $dropins['blog-deleted.php']   = array( __( 'Custom site deleted message.' ), true );   // Auto on deleted blog.
 501          $dropins['blog-inactive.php']  = array( __( 'Custom site inactive message.' ), true );  // Auto on inactive blog.
 502          $dropins['blog-suspended.php'] = array( __( 'Custom site suspended message.' ), true ); // Auto on archived or spammed blog.
 503      }
 504  
 505      return $dropins;
 506  }
 507  
 508  /**
 509   * Determines whether a plugin is active.
 510   *
 511   * Only plugins installed in the plugins/ folder can be active.
 512   *
 513   * Plugins in the mu-plugins/ folder can't be "activated," so this function will
 514   * return false for those plugins.
 515   *
 516   * For more information on this and similar theme functions, check out
 517   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 518   * Conditional Tags} article in the Theme Developer Handbook.
 519   *
 520   * @since 2.5.0
 521   *
 522   * @param string $plugin Path to the plugin file relative to the plugins directory.
 523   * @return bool True, if in the active plugins list. False, not in the list.
 524   */
 525  function is_plugin_active( $plugin ) {
 526      return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( $plugin );
 527  }
 528  
 529  /**
 530   * Determines whether the plugin is inactive.
 531   *
 532   * Reverse of is_plugin_active(). Used as a callback.
 533   *
 534   * For more information on this and similar theme functions, check out
 535   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 536   * Conditional Tags} article in the Theme Developer Handbook.
 537   *
 538   * @since 3.1.0
 539   * @see is_plugin_active()
 540   *
 541   * @param string $plugin Path to the plugin file relative to the plugins directory.
 542   * @return bool True if inactive. False if active.
 543   */
 544  function is_plugin_inactive( $plugin ) {
 545      return ! is_plugin_active( $plugin );
 546  }
 547  
 548  /**
 549   * Determines whether the plugin is active for the entire network.
 550   *
 551   * Only plugins installed in the plugins/ folder can be active.
 552   *
 553   * Plugins in the mu-plugins/ folder can't be "activated," so this function will
 554   * return false for those plugins.
 555   *
 556   * For more information on this and similar theme functions, check out
 557   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 558   * Conditional Tags} article in the Theme Developer Handbook.
 559   *
 560   * @since 3.0.0
 561   *
 562   * @param string $plugin Path to the plugin file relative to the plugins directory.
 563   * @return bool True if active for the network, otherwise false.
 564   */
 565  function is_plugin_active_for_network( $plugin ) {
 566      if ( ! is_multisite() ) {
 567          return false;
 568      }
 569  
 570      $plugins = get_site_option( 'active_sitewide_plugins' );
 571      if ( isset( $plugins[ $plugin ] ) ) {
 572          return true;
 573      }
 574  
 575      return false;
 576  }
 577  
 578  /**
 579   * Checks for "Network: true" in the plugin header to see if this should
 580   * be activated only as a network wide plugin. The plugin would also work
 581   * when Multisite is not enabled.
 582   *
 583   * Checks for "Site Wide Only: true" for backward compatibility.
 584   *
 585   * @since 3.0.0
 586   *
 587   * @param string $plugin Path to the plugin file relative to the plugins directory.
 588   * @return bool True if plugin is network only, false otherwise.
 589   */
 590  function is_network_only_plugin( $plugin ) {
 591      $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
 592      if ( $plugin_data ) {
 593          return $plugin_data['Network'];
 594      }
 595      return false;
 596  }
 597  
 598  /**
 599   * Attempts activation of plugin in a "sandbox" and redirects on success.
 600   *
 601   * A plugin that is already activated will not attempt to be activated again.
 602   *
 603   * The way it works is by setting the redirection to the error before trying to
 604   * include the plugin file. If the plugin fails, then the redirection will not
 605   * be overwritten with the success message. Also, the options will not be
 606   * updated and the activation hook will not be called on plugin error.
 607   *
 608   * It should be noted that in no way the below code will actually prevent errors
 609   * within the file. The code should not be used elsewhere to replicate the
 610   * "sandbox", which uses redirection to work.
 611   * {@source 13 1}
 612   *
 613   * If any errors are found or text is outputted, then it will be captured to
 614   * ensure that the success redirection will update the error redirection.
 615   *
 616   * @since 2.5.0
 617   * @since 5.2.0 Test for WordPress version and PHP version compatibility.
 618   *
 619   * @param string $plugin       Path to the plugin file relative to the plugins directory.
 620   * @param string $redirect     Optional. URL to redirect to.
 621   * @param bool   $network_wide Optional. Whether to enable the plugin for all sites in the network
 622   *                             or just the current site. Multisite only. Default false.
 623   * @param bool   $silent       Optional. Whether to prevent calling activation hooks. Default false.
 624   * @return null|WP_Error Null on success, WP_Error on invalid file.
 625   */
 626  function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
 627      $plugin = plugin_basename( trim( $plugin ) );
 628  
 629      if ( is_multisite() && ( $network_wide || is_network_only_plugin( $plugin ) ) ) {
 630          $network_wide        = true;
 631          $current             = get_site_option( 'active_sitewide_plugins', array() );
 632          $_GET['networkwide'] = 1; // Back compat for plugins looking for this value.
 633      } else {
 634          $current = get_option( 'active_plugins', array() );
 635      }
 636  
 637      $valid = validate_plugin( $plugin );
 638      if ( is_wp_error( $valid ) ) {
 639          return $valid;
 640      }
 641  
 642      $requirements = validate_plugin_requirements( $plugin );
 643      if ( is_wp_error( $requirements ) ) {
 644          return $requirements;
 645      }
 646  
 647      if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current, true ) ) ) {
 648          if ( ! empty( $redirect ) ) {
 649              // We'll override this later if the plugin can be included without fatal error.
 650              wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) );
 651          }
 652  
 653          ob_start();
 654          wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
 655          $_wp_plugin_file = $plugin;
 656          if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
 657              define( 'WP_SANDBOX_SCRAPING', true );
 658          }
 659          include_once WP_PLUGIN_DIR . '/' . $plugin;
 660          $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin.
 661  
 662          if ( ! $silent ) {
 663              /**
 664               * Fires before a plugin is activated.
 665               *
 666               * If a plugin is silently activated (such as during an update),
 667               * this hook does not fire.
 668               *
 669               * @since 2.9.0
 670               *
 671               * @param string $plugin       Path to the plugin file relative to the plugins directory.
 672               * @param bool   $network_wide Whether to enable the plugin for all sites in the network
 673               *                             or just the current site. Multisite only. Default is false.
 674               */
 675              do_action( 'activate_plugin', $plugin, $network_wide );
 676  
 677              /**
 678               * Fires as a specific plugin is being activated.
 679               *
 680               * This hook is the "activation" hook used internally by register_activation_hook().
 681               * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename.
 682               *
 683               * If a plugin is silently activated (such as during an update), this hook does not fire.
 684               *
 685               * @since 2.0.0
 686               *
 687               * @param bool $network_wide Whether to enable the plugin for all sites in the network
 688               *                           or just the current site. Multisite only. Default is false.
 689               */
 690              do_action( "activate_{$plugin}", $network_wide );
 691          }
 692  
 693          if ( $network_wide ) {
 694              $current            = get_site_option( 'active_sitewide_plugins', array() );
 695              $current[ $plugin ] = time();
 696              update_site_option( 'active_sitewide_plugins', $current );
 697          } else {
 698              $current   = get_option( 'active_plugins', array() );
 699              $current[] = $plugin;
 700              sort( $current );
 701              update_option( 'active_plugins', $current );
 702          }
 703  
 704          if ( ! $silent ) {
 705              /**
 706               * Fires after a plugin has been activated.
 707               *
 708               * If a plugin is silently activated (such as during an update),
 709               * this hook does not fire.
 710               *
 711               * @since 2.9.0
 712               *
 713               * @param string $plugin       Path to the plugin file relative to the plugins directory.
 714               * @param bool   $network_wide Whether to enable the plugin for all sites in the network
 715               *                             or just the current site. Multisite only. Default is false.
 716               */
 717              do_action( 'activated_plugin', $plugin, $network_wide );
 718          }
 719  
 720          if ( ob_get_length() > 0 ) {
 721              $output = ob_get_clean();
 722              return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output );
 723          }
 724          ob_end_clean();
 725      }
 726  
 727      return null;
 728  }
 729  
 730  /**
 731   * Deactivate a single plugin or multiple plugins.
 732   *
 733   * The deactivation hook is disabled by the plugin upgrader by using the $silent
 734   * parameter.
 735   *
 736   * @since 2.5.0
 737   *
 738   * @param string|string[] $plugins      Single plugin or list of plugins to deactivate.
 739   * @param bool            $silent       Prevent calling deactivation hooks. Default false.
 740   * @param bool|null       $network_wide Whether to deactivate the plugin for all sites in the network.
 741   *                                      A value of null will deactivate plugins for both the network
 742   *                                      and the current site. Multisite only. Default null.
 743   */
 744  function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) {
 745      if ( is_multisite() ) {
 746          $network_current = get_site_option( 'active_sitewide_plugins', array() );
 747      }
 748      $current    = get_option( 'active_plugins', array() );
 749      $do_blog    = false;
 750      $do_network = false;
 751  
 752      foreach ( (array) $plugins as $plugin ) {
 753          $plugin = plugin_basename( trim( $plugin ) );
 754          if ( ! is_plugin_active( $plugin ) ) {
 755              continue;
 756          }
 757  
 758          $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin );
 759  
 760          if ( ! $silent ) {
 761              /**
 762               * Fires before a plugin is deactivated.
 763               *
 764               * If a plugin is silently deactivated (such as during an update),
 765               * this hook does not fire.
 766               *
 767               * @since 2.9.0
 768               *
 769               * @param string $plugin               Path to the plugin file relative to the plugins directory.
 770               * @param bool   $network_deactivating Whether the plugin is deactivated for all sites in the network
 771               *                                     or just the current site. Multisite only. Default false.
 772               */
 773              do_action( 'deactivate_plugin', $plugin, $network_deactivating );
 774          }
 775  
 776          if ( false !== $network_wide ) {
 777              if ( is_plugin_active_for_network( $plugin ) ) {
 778                  $do_network = true;
 779                  unset( $network_current[ $plugin ] );
 780              } elseif ( $network_wide ) {
 781                  continue;
 782              }
 783          }
 784  
 785          if ( true !== $network_wide ) {
 786              $key = array_search( $plugin, $current, true );
 787              if ( false !== $key ) {
 788                  $do_blog = true;
 789                  unset( $current[ $key ] );
 790              }
 791          }
 792  
 793          if ( $do_blog && wp_is_recovery_mode() ) {
 794              list( $extension ) = explode( '/', $plugin );
 795              wp_paused_plugins()->delete( $extension );
 796          }
 797  
 798          if ( ! $silent ) {
 799              /**
 800               * Fires as a specific plugin is being deactivated.
 801               *
 802               * This hook is the "deactivation" hook used internally by register_deactivation_hook().
 803               * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename.
 804               *
 805               * If a plugin is silently deactivated (such as during an update), this hook does not fire.
 806               *
 807               * @since 2.0.0
 808               *
 809               * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network
 810               *                                   or just the current site. Multisite only. Default false.
 811               */
 812              do_action( "deactivate_{$plugin}", $network_deactivating );
 813  
 814              /**
 815               * Fires after a plugin is deactivated.
 816               *
 817               * If a plugin is silently deactivated (such as during an update),
 818               * this hook does not fire.
 819               *
 820               * @since 2.9.0
 821               *
 822               * @param string $plugin               Path to the plugin file relative to the plugins directory.
 823               * @param bool   $network_deactivating Whether the plugin is deactivated for all sites in the network
 824               *                                     or just the current site. Multisite only. Default false.
 825               */
 826              do_action( 'deactivated_plugin', $plugin, $network_deactivating );
 827          }
 828      }
 829  
 830      if ( $do_blog ) {
 831          update_option( 'active_plugins', $current );
 832      }
 833      if ( $do_network ) {
 834          update_site_option( 'active_sitewide_plugins', $network_current );
 835      }
 836  }
 837  
 838  /**
 839   * Activate multiple plugins.
 840   *
 841   * When WP_Error is returned, it does not mean that one of the plugins had
 842   * errors. It means that one or more of the plugin file paths were invalid.
 843   *
 844   * The execution will be halted as soon as one of the plugins has an error.
 845   *
 846   * @since 2.6.0
 847   *
 848   * @param string|string[] $plugins      Single plugin or list of plugins to activate.
 849   * @param string          $redirect     Redirect to page after successful activation.
 850   * @param bool            $network_wide Whether to enable the plugin for all sites in the network.
 851   *                                      Default false.
 852   * @param bool $silent                  Prevent calling activation hooks. Default false.
 853   * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
 854   */
 855  function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) {
 856      if ( ! is_array( $plugins ) ) {
 857          $plugins = array( $plugins );
 858      }
 859  
 860      $errors = array();
 861      foreach ( $plugins as $plugin ) {
 862          if ( ! empty( $redirect ) ) {
 863              $redirect = add_query_arg( 'plugin', $plugin, $redirect );
 864          }
 865          $result = activate_plugin( $plugin, $redirect, $network_wide, $silent );
 866          if ( is_wp_error( $result ) ) {
 867              $errors[ $plugin ] = $result;
 868          }
 869      }
 870  
 871      if ( ! empty( $errors ) ) {
 872          return new WP_Error( 'plugins_invalid', __( 'One of the plugins is invalid.' ), $errors );
 873      }
 874  
 875      return true;
 876  }
 877  
 878  /**
 879   * Remove directory and files of a plugin for a list of plugins.
 880   *
 881   * @since 2.6.0
 882   *
 883   * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 884   *
 885   * @param string[] $plugins    List of plugin paths to delete, relative to the plugins directory.
 886   * @param string   $deprecated Not used.
 887   * @return bool|null|WP_Error True on success, false if `$plugins` is empty, `WP_Error` on failure.
 888   *                            `null` if filesystem credentials are required to proceed.
 889   */
 890  function delete_plugins( $plugins, $deprecated = '' ) {
 891      global $wp_filesystem;
 892  
 893      if ( empty( $plugins ) ) {
 894          return false;
 895      }
 896  
 897      $checked = array();
 898      foreach ( $plugins as $plugin ) {
 899          $checked[] = 'checked[]=' . $plugin;
 900      }
 901  
 902      $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&' . implode( '&', $checked ), 'bulk-plugins' );
 903  
 904      ob_start();
 905      $credentials = request_filesystem_credentials( $url );
 906      $data        = ob_get_clean();
 907  
 908      if ( false === $credentials ) {
 909          if ( ! empty( $data ) ) {
 910              require_once  ABSPATH . 'wp-admin/admin-header.php';
 911              echo $data;
 912              require_once  ABSPATH . 'wp-admin/admin-footer.php';
 913              exit;
 914          }
 915          return;
 916      }
 917  
 918      if ( ! WP_Filesystem( $credentials ) ) {
 919          ob_start();
 920          // Failed to connect. Error and request again.
 921          request_filesystem_credentials( $url, '', true );
 922          $data = ob_get_clean();
 923  
 924          if ( ! empty( $data ) ) {
 925              require_once  ABSPATH . 'wp-admin/admin-header.php';
 926              echo $data;
 927              require_once  ABSPATH . 'wp-admin/admin-footer.php';
 928              exit;
 929          }
 930          return;
 931      }
 932  
 933      if ( ! is_object( $wp_filesystem ) ) {
 934          return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
 935      }
 936  
 937      if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
 938          return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors );
 939      }
 940  
 941      // Get the base plugin folder.
 942      $plugins_dir = $wp_filesystem->wp_plugins_dir();
 943      if ( empty( $plugins_dir ) ) {
 944          return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress plugin directory.' ) );
 945      }
 946  
 947      $plugins_dir = trailingslashit( $plugins_dir );
 948  
 949      $plugin_translations = wp_get_installed_translations( 'plugins' );
 950  
 951      $errors = array();
 952  
 953      foreach ( $plugins as $plugin_file ) {
 954          // Run Uninstall hook.
 955          if ( is_uninstallable_plugin( $plugin_file ) ) {
 956              uninstall_plugin( $plugin_file );
 957          }
 958  
 959          /**
 960           * Fires immediately before a plugin deletion attempt.
 961           *
 962           * @since 4.4.0
 963           *
 964           * @param string $plugin_file Path to the plugin file relative to the plugins directory.
 965           */
 966          do_action( 'delete_plugin', $plugin_file );
 967  
 968          $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) );
 969  
 970          // If plugin is in its own directory, recursively delete the directory.
 971          // Base check on if plugin includes directory separator AND that it's not the root plugin folder.
 972          if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) {
 973              $deleted = $wp_filesystem->delete( $this_plugin_dir, true );
 974          } else {
 975              $deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file );
 976          }
 977  
 978          /**
 979           * Fires immediately after a plugin deletion attempt.
 980           *
 981           * @since 4.4.0
 982           *
 983           * @param string $plugin_file Path to the plugin file relative to the plugins directory.
 984           * @param bool   $deleted     Whether the plugin deletion was successful.
 985           */
 986          do_action( 'deleted_plugin', $plugin_file, $deleted );
 987  
 988          if ( ! $deleted ) {
 989              $errors[] = $plugin_file;
 990              continue;
 991          }
 992  
 993          // Remove language files, silently.
 994          $plugin_slug = dirname( $plugin_file );
 995          if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) {
 996              $translations = $plugin_translations[ $plugin_slug ];
 997  
 998              foreach ( $translations as $translation => $data ) {
 999                  $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' );
1000                  $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );
1001  
1002                  $json_translation_files = glob( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '-*.json' );
1003                  if ( $json_translation_files ) {
1004                      array_map( array( $wp_filesystem, 'delete' ), $json_translation_files );
1005                  }
1006              }
1007          }
1008      }
1009  
1010      // Remove deleted plugins from the plugin updates list.
1011      $current = get_site_transient( 'update_plugins' );
1012      if ( $current ) {
1013          // Don't remove the plugins that weren't deleted.
1014          $deleted = array_diff( $plugins, $errors );
1015  
1016          foreach ( $deleted as $plugin_file ) {
1017              unset( $current->response[ $plugin_file ] );
1018          }
1019  
1020          set_site_transient( 'update_plugins', $current );
1021      }
1022  
1023      if ( ! empty( $errors ) ) {
1024          if ( 1 === count( $errors ) ) {
1025              /* translators: %s: Plugin filename. */
1026              $message = __( 'Could not fully remove the plugin %s.' );
1027          } else {
1028              /* translators: %s: Comma-separated list of plugin filenames. */
1029              $message = __( 'Could not fully remove the plugins %s.' );
1030          }
1031  
1032          return new WP_Error( 'could_not_remove_plugin', sprintf( $message, implode( ', ', $errors ) ) );
1033      }
1034  
1035      return true;
1036  }
1037  
1038  /**
1039   * Validate active plugins
1040   *
1041   * Validate all active plugins, deactivates invalid and
1042   * returns an array of deactivated ones.
1043   *
1044   * @since 2.5.0
1045   * @return WP_Error[] Array of plugin errors keyed by plugin file name.
1046   */
1047  function validate_active_plugins() {
1048      $plugins = get_option( 'active_plugins', array() );
1049      // Validate vartype: array.
1050      if ( ! is_array( $plugins ) ) {
1051          update_option( 'active_plugins', array() );
1052          $plugins = array();
1053      }
1054  
1055      if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
1056          $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
1057          $plugins         = array_merge( $plugins, array_keys( $network_plugins ) );
1058      }
1059  
1060      if ( empty( $plugins ) ) {
1061          return array();
1062      }
1063  
1064      $invalid = array();
1065  
1066      // Invalid plugins get deactivated.
1067      foreach ( $plugins as $plugin ) {
1068          $result = validate_plugin( $plugin );
1069          if ( is_wp_error( $result ) ) {
1070              $invalid[ $plugin ] = $result;
1071              deactivate_plugins( $plugin, true );
1072          }
1073      }
1074      return $invalid;
1075  }
1076  
1077  /**
1078   * Validate the plugin path.
1079   *
1080   * Checks that the main plugin file exists and is a valid plugin. See validate_file().
1081   *
1082   * @since 2.5.0
1083   *
1084   * @param string $plugin Path to the plugin file relative to the plugins directory.
1085   * @return int|WP_Error 0 on success, WP_Error on failure.
1086   */
1087  function validate_plugin( $plugin ) {
1088      if ( validate_file( $plugin ) ) {
1089          return new WP_Error( 'plugin_invalid', __( 'Invalid plugin path.' ) );
1090      }
1091      if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
1092          return new WP_Error( 'plugin_not_found', __( 'Plugin file does not exist.' ) );
1093      }
1094  
1095      $installed_plugins = get_plugins();
1096      if ( ! isset( $installed_plugins[ $plugin ] ) ) {
1097          return new WP_Error( 'no_plugin_header', __( 'The plugin does not have a valid header.' ) );
1098      }
1099      return 0;
1100  }
1101  
1102  /**
1103   * Validate the plugin requirements for WP version and PHP version.
1104   *
1105   * @since 5.2.0
1106   *
1107   * @param string $plugin Path to the plugin file relative to the plugins directory.
1108   * @return true|WP_Error True if requirements are met, WP_Error on failure.
1109   */
1110  function validate_plugin_requirements( $plugin ) {
1111      $readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt';
1112      $plugin_data = array(
1113          'requires'     => '',
1114          'requires_php' => '',
1115      );
1116  
1117      if ( file_exists( $readme_file ) ) {
1118          $plugin_data = get_file_data(
1119              $readme_file,
1120              array(
1121                  'requires'     => 'Requires at least',
1122                  'requires_php' => 'Requires PHP',
1123              ),
1124              'plugin'
1125          );
1126      }
1127  
1128      $plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );
1129  
1130      // Check for headers in the plugin's PHP file, give precedence to the plugin headers.
1131      $plugin_data['requires']     = ! empty( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : $plugin_data['requires'];
1132      $plugin_data['requires_php'] = ! empty( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : $plugin_data['requires_php'];
1133  
1134      $plugin_data['wp_compatible']  = is_wp_version_compatible( $plugin_data['requires'] );
1135      $plugin_data['php_compatible'] = is_php_version_compatible( $plugin_data['requires_php'] );
1136  
1137      if ( ! $plugin_data['wp_compatible'] && ! $plugin_data['php_compatible'] ) {
1138          return new WP_Error(
1139              'plugin_wp_php_incompatible',
1140              sprintf(
1141                  /* translators: %s: Plugin name. */
1142                  __( '<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.' ),
1143                  $plugin_data['Name']
1144              )
1145          );
1146      } elseif ( ! $plugin_data['php_compatible'] ) {
1147          return new WP_Error(
1148              'plugin_php_incompatible',
1149              sprintf(
1150                  /* translators: %s: Plugin name. */
1151                  __( '<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.' ),
1152                  $plugin_data['Name']
1153              )
1154          );
1155      } elseif ( ! $plugin_data['wp_compatible'] ) {
1156          return new WP_Error(
1157              'plugin_wp_incompatible',
1158              sprintf(
1159                  /* translators: %s: Plugin name. */
1160                  __( '<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.' ),
1161                  $plugin_data['Name']
1162              )
1163          );
1164      }
1165  
1166      return true;
1167  }
1168  
1169  /**
1170   * Whether the plugin can be uninstalled.
1171   *
1172   * @since 2.7.0
1173   *
1174   * @param string $plugin Path to the plugin file relative to the plugins directory.
1175   * @return bool Whether plugin can be uninstalled.
1176   */
1177  function is_uninstallable_plugin( $plugin ) {
1178      $file = plugin_basename( $plugin );
1179  
1180      $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
1181      if ( isset( $uninstallable_plugins[ $file ] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) {
1182          return true;
1183      }
1184  
1185      return false;
1186  }
1187  
1188  /**
1189   * Uninstall a single plugin.
1190   *
1191   * Calls the uninstall hook, if it is available.
1192   *
1193   * @since 2.7.0
1194   *
1195   * @param string $plugin Path to the plugin file relative to the plugins directory.
1196   * @return true True if a plugin's uninstall.php file has been found and included.
1197   */
1198  function uninstall_plugin( $plugin ) {
1199      $file = plugin_basename( $plugin );
1200  
1201      $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
1202  
1203      /**
1204       * Fires in uninstall_plugin() immediately before the plugin is uninstalled.
1205       *
1206       * @since 4.5.0
1207       *
1208       * @param string $plugin                Path to the plugin file relative to the plugins directory.
1209       * @param array  $uninstallable_plugins Uninstallable plugins.
1210       */
1211      do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins );
1212  
1213      if ( file_exists( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) {
1214          if ( isset( $uninstallable_plugins[ $file ] ) ) {
1215              unset( $uninstallable_plugins[ $file ] );
1216              update_option( 'uninstall_plugins', $uninstallable_plugins );
1217          }
1218          unset( $uninstallable_plugins );
1219  
1220          define( 'WP_UNINSTALL_PLUGIN', $file );
1221          wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
1222          include WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php';
1223  
1224          return true;
1225      }
1226  
1227      if ( isset( $uninstallable_plugins[ $file ] ) ) {
1228          $callable = $uninstallable_plugins[ $file ];
1229          unset( $uninstallable_plugins[ $file ] );
1230          update_option( 'uninstall_plugins', $uninstallable_plugins );
1231          unset( $uninstallable_plugins );
1232  
1233          wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file );
1234          include WP_PLUGIN_DIR . '/' . $file;
1235  
1236          add_action( "uninstall_{$file}", $callable );
1237  
1238          /**
1239           * Fires in uninstall_plugin() once the plugin has been uninstalled.
1240           *
1241           * The action concatenates the 'uninstall_' prefix with the basename of the
1242           * plugin passed to uninstall_plugin() to create a dynamically-named action.
1243           *
1244           * @since 2.7.0
1245           */
1246          do_action( "uninstall_{$file}" );
1247      }
1248  }
1249  
1250  //
1251  // Menu.
1252  //
1253  
1254  /**
1255   * Add a top-level menu page.
1256   *
1257   * This function takes a capability which will be used to determine whether
1258   * or not a page is included in the menu.
1259   *
1260   * The function which is hooked in to handle the output of the page must check
1261   * that the user has the required capability as well.
1262   *
1263   * @since 1.5.0
1264   *
1265   * @global array $menu
1266   * @global array $admin_page_hooks
1267   * @global array $_registered_pages
1268   * @global array $_parent_pages
1269   *
1270   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1271   * @param string   $menu_title The text to be used for the menu.
1272   * @param string   $capability The capability required for this menu to be displayed to the user.
1273   * @param string   $menu_slug  The slug name to refer to this menu by. Should be unique for this menu page and only
1274   *                             include lowercase alphanumeric, dashes, and underscores characters to be compatible
1275   *                             with sanitize_key().
1276   * @param callable $function   The function to be called to output the content for this page.
1277   * @param string   $icon_url   The URL to the icon to be used for this menu.
1278   *                             * Pass a base64-encoded SVG using a data URI, which will be colored to match
1279   *                               the color scheme. This should begin with 'data:image/svg+xml;base64,'.
1280   *                             * Pass the name of a Dashicons helper class to use a font icon,
1281   *                               e.g. 'dashicons-chart-pie'.
1282   *                             * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS.
1283   * @param int      $position   The position in the menu order this item should appear.
1284   * @return string The resulting page's hook_suffix.
1285   */
1286  function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) {
1287      global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages;
1288  
1289      $menu_slug = plugin_basename( $menu_slug );
1290  
1291      $admin_page_hooks[ $menu_slug ] = sanitize_title( $menu_title );
1292  
1293      $hookname = get_plugin_page_hookname( $menu_slug, '' );
1294  
1295      if ( ! empty( $function ) && ! empty( $hookname ) && current_user_can( $capability ) ) {
1296          add_action( $hookname, $function );
1297      }
1298  
1299      if ( empty( $icon_url ) ) {
1300          $icon_url   = 'dashicons-admin-generic';
1301          $icon_class = 'menu-icon-generic ';
1302      } else {
1303          $icon_url   = set_url_scheme( $icon_url );
1304          $icon_class = '';
1305      }
1306  
1307      $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $icon_class . $hookname, $hookname, $icon_url );
1308  
1309      if ( null === $position ) {
1310          $menu[] = $new_menu;
1311      } elseif ( isset( $menu[ "$position" ] ) ) {
1312          $position            = $position + substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ), -5 ) * 0.00001;
1313          $menu[ "$position" ] = $new_menu;
1314      } else {
1315          $menu[ $position ] = $new_menu;
1316      }
1317  
1318      $_registered_pages[ $hookname ] = true;
1319  
1320      // No parent as top level.
1321      $_parent_pages[ $menu_slug ] = false;
1322  
1323      return $hookname;
1324  }
1325  
1326  /**
1327   * Add a submenu page.
1328   *
1329   * This function takes a capability which will be used to determine whether
1330   * or not a page is included in the menu.
1331   *
1332   * The function which is hooked in to handle the output of the page must check
1333   * that the user has the required capability as well.
1334   *
1335   * @since 1.5.0
1336   * @since 5.3.0 Added the `$position` parameter.
1337   *
1338   * @global array $submenu
1339   * @global array $menu
1340   * @global array $_wp_real_parent_file
1341   * @global bool  $_wp_submenu_nopriv
1342   * @global array $_registered_pages
1343   * @global array $_parent_pages
1344   *
1345   * @param string   $parent_slug The slug name for the parent menu (or the file name of a standard
1346   *                              WordPress admin page).
1347   * @param string   $page_title  The text to be displayed in the title tags of the page when the menu
1348   *                              is selected.
1349   * @param string   $menu_title  The text to be used for the menu.
1350   * @param string   $capability  The capability required for this menu to be displayed to the user.
1351   * @param string   $menu_slug   The slug name to refer to this menu by. Should be unique for this menu
1352   *                              and only include lowercase alphanumeric, dashes, and underscores characters
1353   *                              to be compatible with sanitize_key().
1354   * @param callable $function    The function to be called to output the content for this page.
1355   * @param int      $position    The position in the menu order this item should appear.
1356   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1357   */
1358  function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1359      global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv,
1360          $_registered_pages, $_parent_pages;
1361  
1362      $menu_slug   = plugin_basename( $menu_slug );
1363      $parent_slug = plugin_basename( $parent_slug );
1364  
1365      if ( isset( $_wp_real_parent_file[ $parent_slug ] ) ) {
1366          $parent_slug = $_wp_real_parent_file[ $parent_slug ];
1367      }
1368  
1369      if ( ! current_user_can( $capability ) ) {
1370          $_wp_submenu_nopriv[ $parent_slug ][ $menu_slug ] = true;
1371          return false;
1372      }
1373  
1374      /*
1375       * If the parent doesn't already have a submenu, add a link to the parent
1376       * as the first item in the submenu. If the submenu file is the same as the
1377       * parent file someone is trying to link back to the parent manually. In
1378       * this case, don't automatically add a link back to avoid duplication.
1379       */
1380      if ( ! isset( $submenu[ $parent_slug ] ) && $menu_slug != $parent_slug ) {
1381          foreach ( (array) $menu as $parent_menu ) {
1382              if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) {
1383                  $submenu[ $parent_slug ][] = array_slice( $parent_menu, 0, 4 );
1384              }
1385          }
1386      }
1387  
1388      $new_sub_menu = array( $menu_title, $capability, $menu_slug, $page_title );
1389      if ( ! is_int( $position ) ) {
1390          if ( null !== $position ) {
1391              _doing_it_wrong(
1392                  __FUNCTION__,
1393                  sprintf(
1394                      /* translators: %s: add_submenu_page() */
1395                      __( 'The seventh parameter passed to %s should be an integer representing menu position.' ),
1396                      '<code>add_submenu_page()</code>'
1397                  ),
1398                  '5.3.0'
1399              );
1400          }
1401  
1402          $submenu[ $parent_slug ][] = $new_sub_menu;
1403      } else {
1404          // Append the submenu if the parent item is not present in the submenu,
1405          // or if position is equal or higher than the number of items in the array.
1406          if ( ! isset( $submenu[ $parent_slug ] ) || $position >= count( $submenu[ $parent_slug ] ) ) {
1407              $submenu[ $parent_slug ][] = $new_sub_menu;
1408          } else {
1409              // Test for a negative position.
1410              $position = max( $position, 0 );
1411              if ( 0 === $position ) {
1412                  // For negative or `0` positions, prepend the submenu.
1413                  array_unshift( $submenu[ $parent_slug ], $new_sub_menu );
1414              } else {
1415                  // Grab all of the items before the insertion point.
1416                  $before_items = array_slice( $submenu[ $parent_slug ], 0, $position, true );
1417                  // Grab all of the items after the insertion point.
1418                  $after_items = array_slice( $submenu[ $parent_slug ], $position, null, true );
1419                  // Add the new item.
1420                  $before_items[] = $new_sub_menu;
1421                  // Merge the items.
1422                  $submenu[ $parent_slug ] = array_merge( $before_items, $after_items );
1423              }
1424          }
1425      }
1426      // Sort the parent array.
1427      ksort( $submenu[ $parent_slug ] );
1428  
1429      $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
1430      if ( ! empty( $function ) && ! empty( $hookname ) ) {
1431          add_action( $hookname, $function );
1432      }
1433  
1434      $_registered_pages[ $hookname ] = true;
1435  
1436      /*
1437       * Backward-compatibility for plugins using add_management_page().
1438       * See wp-admin/admin.php for redirect from edit.php to tools.php.
1439       */
1440      if ( 'tools.php' == $parent_slug ) {
1441          $_registered_pages[ get_plugin_page_hookname( $menu_slug, 'edit.php' ) ] = true;
1442      }
1443  
1444      // No parent as top level.
1445      $_parent_pages[ $menu_slug ] = $parent_slug;
1446  
1447      return $hookname;
1448  }
1449  
1450  /**
1451   * Add submenu page to the Tools main menu.
1452   *
1453   * This function takes a capability which will be used to determine whether
1454   * or not a page is included in the menu.
1455   *
1456   * The function which is hooked in to handle the output of the page must check
1457   * that the user has the required capability as well.
1458   *
1459   * @since 1.5.0
1460   * @since 5.3.0 Added the `$position` parameter.
1461   *
1462   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1463   * @param string   $menu_title The text to be used for the menu.
1464   * @param string   $capability The capability required for this menu to be displayed to the user.
1465   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1466   * @param callable $function   The function to be called to output the content for this page.
1467   * @param int      $position   The position in the menu order this item should appear.
1468   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1469   */
1470  function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1471      return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1472  }
1473  
1474  /**
1475   * Add submenu page to the Settings main menu.
1476   *
1477   * This function takes a capability which will be used to determine whether
1478   * or not a page is included in the menu.
1479   *
1480   * The function which is hooked in to handle the output of the page must check
1481   * that the user has the required capability as well.
1482   *
1483   * @since 1.5.0
1484   * @since 5.3.0 Added the `$position` parameter.
1485   *
1486   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1487   * @param string   $menu_title The text to be used for the menu.
1488   * @param string   $capability The capability required for this menu to be displayed to the user.
1489   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1490   * @param callable $function   The function to be called to output the content for this page.
1491   * @param int      $position   The position in the menu order this item should appear.
1492   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1493   */
1494  function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1495      return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1496  }
1497  
1498  /**
1499   * Add submenu page to the Appearance main menu.
1500   *
1501   * This function takes a capability which will be used to determine whether
1502   * or not a page is included in the menu.
1503   *
1504   * The function which is hooked in to handle the output of the page must check
1505   * that the user has the required capability as well.
1506   *
1507   * @since 2.0.0
1508   * @since 5.3.0 Added the `$position` parameter.
1509   *
1510   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1511   * @param string   $menu_title The text to be used for the menu.
1512   * @param string   $capability The capability required for this menu to be displayed to the user.
1513   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1514   * @param callable $function   The function to be called to output the content for this page.
1515   * @param int      $position   The position in the menu order this item should appear.
1516   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1517   */
1518  function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1519      return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1520  }
1521  
1522  /**
1523   * Add submenu page to the Plugins main menu.
1524   *
1525   * This function takes a capability which will be used to determine whether
1526   * or not a page is included in the menu.
1527   *
1528   * The function which is hooked in to handle the output of the page must check
1529   * that the user has the required capability as well.
1530   *
1531   * @since 3.0.0
1532   * @since 5.3.0 Added the `$position` parameter.
1533   *
1534   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1535   * @param string   $menu_title The text to be used for the menu.
1536   * @param string   $capability The capability required for this menu to be displayed to the user.
1537   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1538   * @param callable $function   The function to be called to output the content for this page.
1539   * @param int      $position   The position in the menu order this item should appear.
1540   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1541   */
1542  function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1543      return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1544  }
1545  
1546  /**
1547   * Add submenu page to the Users/Profile main menu.
1548   *
1549   * This function takes a capability which will be used to determine whether
1550   * or not a page is included in the menu.
1551   *
1552   * The function which is hooked in to handle the output of the page must check
1553   * that the user has the required capability as well.
1554   *
1555   * @since 2.1.3
1556   * @since 5.3.0 Added the `$position` parameter.
1557   *
1558   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1559   * @param string   $menu_title The text to be used for the menu.
1560   * @param string   $capability The capability required for this menu to be displayed to the user.
1561   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1562   * @param callable $function   The function to be called to output the content for this page.
1563   * @param int      $position   The position in the menu order this item should appear.
1564   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1565   */
1566  function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1567      if ( current_user_can( 'edit_users' ) ) {
1568          $parent = 'users.php';
1569      } else {
1570          $parent = 'profile.php';
1571      }
1572      return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1573  }
1574  
1575  /**
1576   * Add submenu page to the Dashboard main menu.
1577   *
1578   * This function takes a capability which will be used to determine whether
1579   * or not a page is included in the menu.
1580   *
1581   * The function which is hooked in to handle the output of the page must check
1582   * that the user has the required capability as well.
1583   *
1584   * @since 2.7.0
1585   * @since 5.3.0 Added the `$position` parameter.
1586   *
1587   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1588   * @param string   $menu_title The text to be used for the menu.
1589   * @param string   $capability The capability required for this menu to be displayed to the user.
1590   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1591   * @param callable $function   The function to be called to output the content for this page.
1592   * @param int      $position   The position in the menu order this item should appear.
1593   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1594   */
1595  function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1596      return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1597  }
1598  
1599  /**
1600   * Add submenu page to the Posts main menu.
1601   *
1602   * This function takes a capability which will be used to determine whether
1603   * or not a page is included in the menu.
1604   *
1605   * The function which is hooked in to handle the output of the page must check
1606   * that the user has the required capability as well.
1607   *
1608   * @since 2.7.0
1609   * @since 5.3.0 Added the `$position` parameter.
1610   *
1611   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1612   * @param string   $menu_title The text to be used for the menu.
1613   * @param string   $capability The capability required for this menu to be displayed to the user.
1614   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1615   * @param callable $function   The function to be called to output the content for this page.
1616   * @param int      $position   The position in the menu order this item should appear.
1617   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1618   */
1619  function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1620      return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1621  }
1622  
1623  /**
1624   * Add submenu page to the Media main menu.
1625   *
1626   * This function takes a capability which will be used to determine whether
1627   * or not a page is included in the menu.
1628   *
1629   * The function which is hooked in to handle the output of the page must check
1630   * that the user has the required capability as well.
1631   *
1632   * @since 2.7.0
1633   * @since 5.3.0 Added the `$position` parameter.
1634   *
1635   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1636   * @param string   $menu_title The text to be used for the menu.
1637   * @param string   $capability The capability required for this menu to be displayed to the user.
1638   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1639   * @param callable $function   The function to be called to output the content for this page.
1640   * @param int      $position   The position in the menu order this item should appear.
1641   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1642   */
1643  function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1644      return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1645  }
1646  
1647  /**
1648   * Add submenu page to the Links main menu.
1649   *
1650   * This function takes a capability which will be used to determine whether
1651   * or not a page is included in the menu.
1652   *
1653   * The function which is hooked in to handle the output of the page must check
1654   * that the user has the required capability as well.
1655   *
1656   * @since 2.7.0
1657   * @since 5.3.0 Added the `$position` parameter.
1658   *
1659   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1660   * @param string   $menu_title The text to be used for the menu.
1661   * @param string   $capability The capability required for this menu to be displayed to the user.
1662   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1663   * @param callable $function   The function to be called to output the content for this page.
1664   * @param int      $position   The position in the menu order this item should appear.
1665   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1666   */
1667  function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1668      return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1669  }
1670  
1671  /**
1672   * Add submenu page to the Pages main menu.
1673   *
1674   * This function takes a capability which will be used to determine whether
1675   * or not a page is included in the menu.
1676   *
1677   * The function which is hooked in to handle the output of the page must check
1678   * that the user has the required capability as well.
1679   *
1680   * @since 2.7.0
1681   * @since 5.3.0 Added the `$position` parameter.
1682   *
1683   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1684   * @param string   $menu_title The text to be used for the menu.
1685   * @param string   $capability The capability required for this menu to be displayed to the user.
1686   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1687   * @param callable $function   The function to be called to output the content for this page.
1688   * @param int      $position   The position in the menu order this item should appear.
1689   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1690   */
1691  function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1692      return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1693  }
1694  
1695  /**
1696   * Add submenu page to the Comments main menu.
1697   *
1698   * This function takes a capability which will be used to determine whether
1699   * or not a page is included in the menu.
1700   *
1701   * The function which is hooked in to handle the output of the page must check
1702   * that the user has the required capability as well.
1703   *
1704   * @since 2.7.0
1705   * @since 5.3.0 Added the `$position` parameter.
1706   *
1707   * @param string   $page_title The text to be displayed in the title tags of the page when the menu is selected.
1708   * @param string   $menu_title The text to be used for the menu.
1709   * @param string   $capability The capability required for this menu to be displayed to the user.
1710   * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
1711   * @param callable $function   The function to be called to output the content for this page.
1712   * @param int      $position   The position in the menu order this item should appear.
1713   * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
1714   */
1715  function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
1716      return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
1717  }
1718  
1719  /**
1720   * Remove a top-level admin menu.
1721   *
1722   * @since 3.1.0
1723   *
1724   * @global array $menu
1725   *
1726   * @param string $menu_slug The slug of the menu.
1727   * @return array|bool The removed menu on success, false if not found.
1728   */
1729  function remove_menu_page( $menu_slug ) {
1730      global $menu;
1731  
1732      foreach ( $menu as $i => $item ) {
1733          if ( $menu_slug == $item[2] ) {
1734              unset( $menu[ $i ] );
1735              return $item;
1736          }
1737      }
1738  
1739      return false;
1740  }
1741  
1742  /**
1743   * Remove an admin submenu.
1744   *
1745   * @since 3.1.0
1746   *
1747   * @global array $submenu
1748   *
1749   * @param string $menu_slug    The slug for the parent menu.
1750   * @param string $submenu_slug The slug of the submenu.
1751   * @return array|bool The removed submenu on success, false if not found.
1752   */
1753  function remove_submenu_page( $menu_slug, $submenu_slug ) {
1754      global $submenu;
1755  
1756      if ( ! isset( $submenu[ $menu_slug ] ) ) {
1757          return false;
1758      }
1759  
1760      foreach ( $submenu[ $menu_slug ] as $i => $item ) {
1761          if ( $submenu_slug == $item[2] ) {
1762              unset( $submenu[ $menu_slug ][ $i ] );
1763              return $item;
1764          }
1765      }
1766  
1767      return false;
1768  }
1769  
1770  /**
1771   * Get the URL to access a particular menu page based on the slug it was registered with.
1772   *
1773   * If the slug hasn't been registered properly, no URL will be returned.
1774   *
1775   * @since 3.0.0
1776   *
1777   * @global array $_parent_pages
1778   *
1779   * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu).
1780   * @param bool   $echo      Whether or not to echo the URL. Default true.
1781   * @return string The menu page URL.
1782   */
1783  function menu_page_url( $menu_slug, $echo = true ) {
1784      global $_parent_pages;
1785  
1786      if ( isset( $_parent_pages[ $menu_slug ] ) ) {
1787          $parent_slug = $_parent_pages[ $menu_slug ];
1788          if ( $parent_slug && ! isset( $_parent_pages[ $parent_slug ] ) ) {
1789              $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) );
1790          } else {
1791              $url = admin_url( 'admin.php?page=' . $menu_slug );
1792          }
1793      } else {
1794          $url = '';
1795      }
1796  
1797      $url = esc_url( $url );
1798  
1799      if ( $echo ) {
1800          echo $url;
1801      }
1802  
1803      return $url;
1804  }
1805  
1806  //
1807  // Pluggable Menu Support -- Private.
1808  //
1809  /**
1810   * Gets the parent file of the current admin page.
1811   *
1812   * @since 1.5.0
1813   *
1814   * @global string $parent_file
1815   * @global array  $menu
1816   * @global array  $submenu
1817   * @global string $pagenow
1818   * @global string $typenow
1819   * @global string $plugin_page
1820   * @global array  $_wp_real_parent_file
1821   * @global array  $_wp_menu_nopriv
1822   * @global array  $_wp_submenu_nopriv
1823   *
1824   * @param string $parent The slug name for the parent menu (or the file name of a standard
1825   *                       WordPress admin page). Default empty string.
1826   * @return string The parent file of the current admin page.
1827   */
1828  function get_admin_page_parent( $parent = '' ) {
1829      global $parent_file, $menu, $submenu, $pagenow, $typenow,
1830          $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv;
1831  
1832      if ( ! empty( $parent ) && 'admin.php' != $parent ) {
1833          if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
1834              $parent = $_wp_real_parent_file[ $parent ];
1835          }
1836          return $parent;
1837      }
1838  
1839      if ( 'admin.php' === $pagenow && isset( $plugin_page ) ) {
1840          foreach ( (array) $menu as $parent_menu ) {
1841              if ( $parent_menu[2] == $plugin_page ) {
1842                  $parent_file = $plugin_page;
1843                  if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
1844                      $parent_file = $_wp_real_parent_file[ $parent_file ];
1845                  }
1846                  return $parent_file;
1847              }
1848          }
1849          if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
1850              $parent_file = $plugin_page;
1851              if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
1852                      $parent_file = $_wp_real_parent_file[ $parent_file ];
1853              }
1854              return $parent_file;
1855          }
1856      }
1857  
1858      if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) {
1859          $parent_file = $pagenow;
1860          if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) {
1861              $parent_file = $_wp_real_parent_file[ $parent_file ];
1862          }
1863          return $parent_file;
1864      }
1865  
1866      foreach ( array_keys( (array) $submenu ) as $parent ) {
1867          foreach ( $submenu[ $parent ] as $submenu_array ) {
1868              if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
1869                  $parent = $_wp_real_parent_file[ $parent ];
1870              }
1871              if ( ! empty( $typenow ) && ( "$pagenow?post_type=$typenow" === $submenu_array[2] ) ) {
1872                  $parent_file = $parent;
1873                  return $parent;
1874              } elseif ( $submenu_array[2] == $pagenow && empty( $typenow ) && ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) ) ) {
1875                  $parent_file = $parent;
1876                  return $parent;
1877              } elseif ( isset( $plugin_page ) && ( $plugin_page == $submenu_array[2] ) ) {
1878                  $parent_file = $parent;
1879                  return $parent;
1880              }
1881          }
1882      }
1883  
1884      if ( empty( $parent_file ) ) {
1885          $parent_file = '';
1886      }
1887      return '';
1888  }
1889  
1890  /**
1891   * Gets the title of the current admin page.
1892   *
1893   * @since 1.5.0
1894   *
1895   * @global string $title
1896   * @global array $menu
1897   * @global array $submenu
1898   * @global string $pagenow
1899   * @global string $plugin_page
1900   * @global string $typenow
1901   *
1902   * @return string The title of the current admin page.
1903   */
1904  function get_admin_page_title() {
1905      global $title, $menu, $submenu, $pagenow, $plugin_page, $typenow;
1906  
1907      if ( ! empty( $title ) ) {
1908          return $title;
1909      }
1910  
1911      $hook = get_plugin_page_hook( $plugin_page, $pagenow );
1912  
1913      $parent  = get_admin_page_parent();
1914      $parent1 = $parent;
1915  
1916      if ( empty( $parent ) ) {
1917          foreach ( (array) $menu as $menu_array ) {
1918              if ( isset( $menu_array[3] ) ) {
1919                  if ( $menu_array[2] == $pagenow ) {
1920                      $title = $menu_array[3];
1921                      return $menu_array[3];
1922                  } elseif ( isset( $plugin_page ) && ( $plugin_page == $menu_array[2] ) && ( $hook == $menu_array[3] ) ) {
1923                      $title = $menu_array[3];
1924                      return $menu_array[3];
1925                  }
1926              } else {
1927                  $title = $menu_array[0];
1928                  return $title;
1929              }
1930          }
1931      } else {
1932          foreach ( array_keys( $submenu ) as $parent ) {
1933              foreach ( $submenu[ $parent ] as $submenu_array ) {
1934                  if ( isset( $plugin_page ) &&
1935                      ( $plugin_page == $submenu_array[2] ) &&
1936                      (
1937                          ( $parent == $pagenow ) ||
1938                          ( $parent == $plugin_page ) ||
1939                          ( $plugin_page == $hook ) ||
1940                          ( 'admin.php' === $pagenow && $parent1 != $submenu_array[2] ) ||
1941                          ( ! empty( $typenow ) && $parent == $pagenow . '?post_type=' . $typenow )
1942                      )
1943                      ) {
1944                          $title = $submenu_array[3];
1945                          return $submenu_array[3];
1946                  }
1947  
1948                  if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) { // Not the current page.
1949                      continue;
1950                  }
1951  
1952                  if ( isset( $submenu_array[3] ) ) {
1953                      $title = $submenu_array[3];
1954                      return $submenu_array[3];
1955                  } else {
1956                      $title = $submenu_array[0];
1957                      return $title;
1958                  }
1959              }
1960          }
1961          if ( empty( $title ) ) {
1962              foreach ( $menu as $menu_array ) {
1963                  if ( isset( $plugin_page ) &&
1964                      ( $plugin_page == $menu_array[2] ) &&
1965                      ( 'admin.php' === $pagenow ) &&
1966                      ( $parent1 == $menu_array[2] ) ) {
1967                          $title = $menu_array[3];
1968                          return $menu_array[3];
1969                  }
1970              }
1971          }
1972      }
1973  
1974      return $title;
1975  }
1976  
1977  /**
1978   * Gets the hook attached to the administrative page of a plugin.
1979   *
1980   * @since 1.5.0
1981   *
1982   * @param string $plugin_page The slug name of the plugin page.
1983   * @param string $parent_page The slug name for the parent menu (or the file name of a standard
1984   *                            WordPress admin page).
1985   * @return string|null Hook attached to the plugin page, null otherwise.
1986   */
1987  function get_plugin_page_hook( $plugin_page, $parent_page ) {
1988      $hook = get_plugin_page_hookname( $plugin_page, $parent_page );
1989      if ( has_action( $hook ) ) {
1990          return $hook;
1991      } else {
1992          return null;
1993      }
1994  }
1995  
1996  /**
1997   * Gets the hook name for the administrative page of a plugin.
1998   *
1999   * @since 1.5.0
2000   *
2001   * @global array $admin_page_hooks
2002   *
2003   * @param string $plugin_page The slug name of the plugin page.
2004   * @param string $parent_page The slug name for the parent menu (or the file name of a standard
2005   *                            WordPress admin page).
2006   * @return string Hook name for the plugin page.
2007   */
2008  function get_plugin_page_hookname( $plugin_page, $parent_page ) {
2009      global $admin_page_hooks;
2010  
2011      $parent = get_admin_page_parent( $parent_page );
2012  
2013      $page_type = 'admin';
2014      if ( empty( $parent_page ) || 'admin.php' == $parent_page || isset( $admin_page_hooks[ $plugin_page ] ) ) {
2015          if ( isset( $admin_page_hooks[ $plugin_page ] ) ) {
2016              $page_type = 'toplevel';
2017          } elseif ( isset( $admin_page_hooks[ $parent ] ) ) {
2018              $page_type = $admin_page_hooks[ $parent ];
2019          }
2020      } elseif ( isset( $admin_page_hooks[ $parent ] ) ) {
2021          $page_type = $admin_page_hooks[ $parent ];
2022      }
2023  
2024      $plugin_name = preg_replace( '!\.php!', '', $plugin_page );
2025  
2026      return $page_type . '_page_' . $plugin_name;
2027  }
2028  
2029  /**
2030   * Determines whether the current user can access the current admin page.
2031   *
2032   * @since 1.5.0
2033   *
2034   * @global string $pagenow
2035   * @global array  $menu
2036   * @global array  $submenu
2037   * @global array  $_wp_menu_nopriv
2038   * @global array  $_wp_submenu_nopriv
2039   * @global string $plugin_page
2040   * @global array  $_registered_pages
2041   *
2042   * @return bool True if the current user can access the admin page, false otherwise.
2043   */
2044  function user_can_access_admin_page() {
2045      global $pagenow, $menu, $submenu, $_wp_menu_nopriv, $_wp_submenu_nopriv,
2046          $plugin_page, $_registered_pages;
2047  
2048      $parent = get_admin_page_parent();
2049  
2050      if ( ! isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $parent ][ $pagenow ] ) ) {
2051          return false;
2052      }
2053  
2054      if ( isset( $plugin_page ) ) {
2055          if ( isset( $_wp_submenu_nopriv[ $parent ][ $plugin_page ] ) ) {
2056              return false;
2057          }
2058  
2059          $hookname = get_plugin_page_hookname( $plugin_page, $parent );
2060  
2061          if ( ! isset( $_registered_pages[ $hookname ] ) ) {
2062              return false;
2063          }
2064      }
2065  
2066      if ( empty( $parent ) ) {
2067          if ( isset( $_wp_menu_nopriv[ $pagenow ] ) ) {
2068              return false;
2069          }
2070          if ( isset( $_wp_submenu_nopriv[ $pagenow ][ $pagenow ] ) ) {
2071              return false;
2072          }
2073          if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) {
2074              return false;
2075          }
2076          if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
2077              return false;
2078          }
2079          foreach ( array_keys( $_wp_submenu_nopriv ) as $key ) {
2080              if ( isset( $_wp_submenu_nopriv[ $key ][ $pagenow ] ) ) {
2081                  return false;
2082              }
2083              if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $key ][ $plugin_page ] ) ) {
2084                  return false;
2085              }
2086          }
2087          return true;
2088      }
2089  
2090      if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) {
2091          return false;
2092      }
2093  
2094      if ( isset( $submenu[ $parent ] ) ) {
2095          foreach ( $submenu[ $parent ] as $submenu_array ) {
2096              if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) {
2097                  if ( current_user_can( $submenu_array[1] ) ) {
2098                      return true;
2099                  } else {
2100                      return false;
2101                  }
2102              } elseif ( $submenu_array[2] == $pagenow ) {
2103                  if ( current_user_can( $submenu_array[1] ) ) {
2104                      return true;
2105                  } else {
2106                      return false;
2107                  }
2108              }
2109          }
2110      }
2111  
2112      foreach ( $menu as $menu_array ) {
2113          if ( $menu_array[2] == $parent ) {
2114              if ( current_user_can( $menu_array[1] ) ) {
2115                  return true;
2116              } else {
2117                  return false;
2118              }
2119          }
2120      }
2121  
2122      return true;
2123  }
2124  
2125  /* Whitelist functions */
2126  
2127  /**
2128   * Refreshes the value of the options whitelist available via the 'whitelist_options' hook.
2129   *
2130   * See the {@see 'whitelist_options'} filter.
2131   *
2132   * @since 2.7.0
2133   *
2134   * @global array $new_whitelist_options
2135   *
2136   * @param array $options
2137   * @return array
2138   */
2139  function option_update_filter( $options ) {
2140      global $new_whitelist_options;
2141  
2142      if ( is_array( $new_whitelist_options ) ) {
2143          $options = add_option_whitelist( $new_whitelist_options, $options );
2144      }
2145  
2146      return $options;
2147  }
2148  
2149  /**
2150   * Adds an array of options to the options whitelist.
2151   *
2152   * @since 2.7.0
2153   *
2154   * @global array $whitelist_options
2155   *
2156   * @param array        $new_options
2157   * @param string|array $options
2158   * @return array
2159   */
2160  function add_option_whitelist( $new_options, $options = '' ) {
2161      if ( '' == $options ) {
2162          global $whitelist_options;
2163      } else {
2164          $whitelist_options = $options;
2165      }
2166  
2167      foreach ( $new_options as $page => $keys ) {
2168          foreach ( $keys as $key ) {
2169              if ( ! isset( $whitelist_options[ $page ] ) || ! is_array( $whitelist_options[ $page ] ) ) {
2170                  $whitelist_options[ $page ]   = array();
2171                  $whitelist_options[ $page ][] = $key;
2172              } else {
2173                  $pos = array_search( $key, $whitelist_options[ $page ] );
2174                  if ( false === $pos ) {
2175                      $whitelist_options[ $page ][] = $key;
2176                  }
2177              }
2178          }
2179      }
2180  
2181      return $whitelist_options;
2182  }
2183  
2184  /**
2185   * Removes a list of options from the options whitelist.
2186   *
2187   * @since 2.7.0
2188   *
2189   * @global array $whitelist_options
2190   *
2191   * @param array        $del_options
2192   * @param string|array $options
2193   * @return array
2194   */
2195  function remove_option_whitelist( $del_options, $options = '' ) {
2196      if ( '' == $options ) {
2197          global $whitelist_options;
2198      } else {
2199          $whitelist_options = $options;
2200      }
2201  
2202      foreach ( $del_options as $page => $keys ) {
2203          foreach ( $keys as $key ) {
2204              if ( isset( $whitelist_options[ $page ] ) && is_array( $whitelist_options[ $page ] ) ) {
2205                  $pos = array_search( $key, $whitelist_options[ $page ] );
2206                  if ( false !== $pos ) {
2207                      unset( $whitelist_options[ $page ][ $pos ] );
2208                  }
2209              }
2210          }
2211      }
2212  
2213      return $whitelist_options;
2214  }
2215  
2216  /**
2217   * Output nonce, action, and option_page fields for a settings page.
2218   *
2219   * @since 2.7.0
2220   *
2221   * @param string $option_group A settings group name. This should match the group name
2222   *                             used in register_setting().
2223   */
2224  function settings_fields( $option_group ) {
2225      echo "<input type='hidden' name='option_page' value='" . esc_attr( $option_group ) . "' />";
2226      echo '<input type="hidden" name="action" value="update" />';
2227      wp_nonce_field( "$option_group-options" );
2228  }
2229  
2230  /**
2231   * Clears the plugins cache used by get_plugins() and by default, the plugin updates cache.
2232   *
2233   * @since 3.7.0
2234   *
2235   * @param bool $clear_update_cache Whether to clear the plugin updates cache. Default true.
2236   */
2237  function wp_clean_plugins_cache( $clear_update_cache = true ) {
2238      if ( $clear_update_cache ) {
2239          delete_site_transient( 'update_plugins' );
2240      }
2241      wp_cache_delete( 'plugins', 'plugins' );
2242  }
2243  
2244  /**
2245   * Load a given plugin attempt to generate errors.
2246   *
2247   * @since 3.0.0
2248   * @since 4.4.0 Function was moved into the `wp-admin/includes/plugin.php` file.
2249   *
2250   * @param string $plugin Path to the plugin file relative to the plugins directory.
2251   */
2252  function plugin_sandbox_scrape( $plugin ) {
2253      if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
2254          define( 'WP_SANDBOX_SCRAPING', true );
2255      }
2256      wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
2257      include WP_PLUGIN_DIR . '/' . $plugin;
2258  }
2259  
2260  /**
2261   * Helper function for adding content to the Privacy Policy Guide.
2262   *
2263   * Plugins and themes should suggest text for inclusion in the site's privacy policy.
2264   * The suggested text should contain information about any functionality that affects user privacy,
2265   * and will be shown on the Privacy Policy Guide screen.
2266   *
2267   * A plugin or theme can use this function multiple times as long as it will help to better present
2268   * the suggested policy content. For example modular plugins such as WooCommerse or Jetpack
2269   * can add or remove suggested content depending on the modules/extensions that are enabled.
2270   * For more information see the Plugin Handbook:
2271   * https://developer.wordpress.org/plugins/privacy/suggesting-text-for-the-site-privacy-policy/.
2272   *
2273   * The HTML contents of the `$policy_text` supports use of a specialized `.privacy-policy-tutorial`
2274   * CSS class which can be used to provide supplemental information. Any content contained within
2275   * HTML elements that have the `.privacy-policy-tutorial` CSS class applied will be omitted
2276   * from the clipboard when the section content is copied.
2277   *
2278   * Intended for use with the `'admin_init'` action.
2279   *
2280   * @since 4.9.6
2281   *
2282   * @param string $plugin_name The name of the plugin or theme that is suggesting content
2283   *                            for the site's privacy policy.
2284   * @param string $policy_text The suggested content for inclusion in the policy.
2285   */
2286  function wp_add_privacy_policy_content( $plugin_name, $policy_text ) {
2287      if ( ! is_admin() ) {
2288          _doing_it_wrong(
2289              __FUNCTION__,
2290              sprintf(
2291                  /* translators: %s: admin_init */
2292                  __( 'The suggested privacy policy content should be added only in wp-admin by using the %s (or later) action.' ),
2293                  '<code>admin_init</code>'
2294              ),
2295              '4.9.7'
2296          );
2297          return;
2298      } elseif ( ! doing_action( 'admin_init' ) && ! did_action( 'admin_init' ) ) {
2299          _doing_it_wrong(
2300              __FUNCTION__,
2301              sprintf(
2302                  /* translators: %s: admin_init */
2303                  __( 'The suggested privacy policy content should be added by using the %s (or later) action. Please see the inline documentation.' ),
2304                  '<code>admin_init</code>'
2305              ),
2306              '4.9.7'
2307          );
2308          return;
2309      }
2310  
2311      if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
2312          require_once  ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
2313      }
2314  
2315      WP_Privacy_Policy_Content::add( $plugin_name, $policy_text );
2316  }
2317  
2318  /**
2319   * Determines whether a plugin is technically active but was paused while
2320   * loading.
2321   *
2322   * For more information on this and similar theme functions, check out
2323   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
2324   * Conditional Tags} article in the Theme Developer Handbook.
2325   *
2326   * @since 5.2.0
2327   *
2328   * @param string $plugin Path to the plugin file relative to the plugins directory.
2329   * @return bool True, if in the list of paused plugins. False, if not in the list.
2330   */
2331  function is_plugin_paused( $plugin ) {
2332      if ( ! isset( $GLOBALS['_paused_plugins'] ) ) {
2333          return false;
2334      }
2335  
2336      if ( ! is_plugin_active( $plugin ) ) {
2337          return false;
2338      }
2339  
2340      list( $plugin ) = explode( '/', $plugin );
2341  
2342      return array_key_exists( $plugin, $GLOBALS['_paused_plugins'] );
2343  }
2344  
2345  /**
2346   * Gets the error that was recorded for a paused plugin.
2347   *
2348   * @since 5.2.0
2349   *
2350   * @param string $plugin Path to the plugin file relative to the plugins directory.
2351   * @return array|false Array of error information as returned by `error_get_last()`,
2352   *                     or false if none was recorded.
2353   */
2354  function wp_get_plugin_error( $plugin ) {
2355      if ( ! isset( $GLOBALS['_paused_plugins'] ) ) {
2356          return false;
2357      }
2358  
2359      list( $plugin ) = explode( '/', $plugin );
2360  
2361      if ( ! array_key_exists( $plugin, $GLOBALS['_paused_plugins'] ) ) {
2362          return false;
2363      }
2364  
2365      return $GLOBALS['_paused_plugins'][ $plugin ];
2366  }
2367  
2368  /**
2369   * Tries to resume a single plugin.
2370   *
2371   * If a redirect was provided, we first ensure the plugin does not throw fatal
2372   * errors anymore.
2373   *
2374   * The way it works is by setting the redirection to the error before trying to
2375   * include the plugin file. If the plugin fails, then the redirection will not
2376   * be overwritten with the success message and the plugin will not be resumed.
2377   *
2378   * @since 5.2.0
2379   *
2380   * @param string $plugin   Single plugin to resume.
2381   * @param string $redirect Optional. URL to redirect to. Default empty string.
2382   * @return bool|WP_Error True on success, false if `$plugin` was not paused,
2383   *                       `WP_Error` on failure.
2384   */
2385  function resume_plugin( $plugin, $redirect = '' ) {
2386      /*
2387       * We'll override this later if the plugin could be resumed without
2388       * creating a fatal error.
2389       */
2390      if ( ! empty( $redirect ) ) {
2391          wp_redirect(
2392              add_query_arg(
2393                  '_error_nonce',
2394                  wp_create_nonce( 'plugin-resume-error_' . $plugin ),
2395                  $redirect
2396              )
2397          );
2398  
2399          // Load the plugin to test whether it throws a fatal error.
2400          ob_start();
2401          plugin_sandbox_scrape( $plugin );
2402          ob_clean();
2403      }
2404  
2405      list( $extension ) = explode( '/', $plugin );
2406  
2407      $result = wp_paused_plugins()->delete( $extension );
2408  
2409      if ( ! $result ) {
2410          return new WP_Error(
2411              'could_not_resume_plugin',
2412              __( 'Could not resume the plugin.' )
2413          );
2414      }
2415  
2416      return true;
2417  }
2418  
2419  /**
2420   * Renders an admin notice in case some plugins have been paused due to errors.
2421   *
2422   * @since 5.2.0
2423   */
2424  function paused_plugins_notice() {
2425      if ( 'plugins.php' === $GLOBALS['pagenow'] ) {
2426          return;
2427      }
2428  
2429      if ( ! current_user_can( 'resume_plugins' ) ) {
2430          return;
2431      }
2432  
2433      if ( ! isset( $GLOBALS['_paused_plugins'] ) || empty( $GLOBALS['_paused_plugins'] ) ) {
2434          return;
2435      }
2436  
2437      printf(
2438          '<div class="notice notice-error"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>',
2439          __( 'One or more plugins failed to load properly.' ),
2440          __( 'You can find more details and make changes on the Plugins screen.' ),
2441          esc_url( admin_url( 'plugins.php?plugin_status=paused' ) ),
2442          __( 'Go to the Plugins screen' )
2443      );
2444  }


Generated : Wed Apr 8 08:20:02 2020 Cross-referenced by PHPXref