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