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