PageRenderTime 35ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/plugin.php

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