[ Index ]

PHP Cross Reference of WordPress

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


Generated: Sun May 31 01:00:03 2020 Cross-referenced by PHPXref 0.7.1