| 70 | | $default_headers = array( |
| 71 | | 'Name' => 'Plugin Name', |
| 72 | | 'PluginURI' => 'Plugin URI', |
| 73 | | 'Version' => 'Version', |
| 74 | | 'Description' => 'Description', |
| 75 | | 'Author' => 'Author', |
| 76 | | 'AuthorURI' => 'Author URI', |
| 77 | | 'TextDomain' => 'Text Domain', |
| 78 | | 'DomainPath' => 'Domain Path', |
| 79 | | 'Network' => 'Network', |
| 80 | | 'RequiresWP' => 'Requires at least', |
| 81 | | 'RequiresPHP' => 'Requires PHP', |
| 82 | | // Site Wide Only is deprecated in favor of Network. |
| 83 | | '_sitewide' => 'Site Wide Only', |
| 84 | | ); |
| 85 | | |
| 86 | | $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); |
| 87 | | |
| 88 | | // Site Wide Only is the old header for Network. |
| 89 | | if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) { |
| 90 | | /* translators: 1: Site Wide Only: true, 2: Network: true */ |
| 91 | | _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The %1$s plugin header is deprecated. Use %2$s instead.' ), '<code>Site Wide Only: true</code>', '<code>Network: true</code>' ) ); |
| 92 | | $plugin_data['Network'] = $plugin_data['_sitewide']; |
| 93 | | } |
| 94 | | $plugin_data['Network'] = ( 'true' === strtolower( $plugin_data['Network'] ) ); |
| 95 | | unset( $plugin_data['_sitewide'] ); |
| 96 | | |
| 97 | | // If no text domain is defined fall back to the plugin slug. |
| 98 | | if ( ! $plugin_data['TextDomain'] ) { |
| 99 | | $plugin_slug = dirname( plugin_basename( $plugin_file ) ); |
| 100 | | if ( '.' !== $plugin_slug && false === strpos( $plugin_slug, '/' ) ) { |
| 101 | | $plugin_data['TextDomain'] = $plugin_slug; |
| 102 | | } |
| 103 | | } |
| 104 | | |
| 105 | | if ( $markup || $translate ) { |
| 106 | | $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); |
| 107 | | } else { |
| 108 | | $plugin_data['Title'] = $plugin_data['Name']; |
| 109 | | $plugin_data['AuthorName'] = $plugin_data['Author']; |
| 110 | | } |
| 111 | | |
| 112 | | return $plugin_data; |
| | 70 | $default_headers = array( |
| | 71 | 'Name' => 'Plugin Name', |
| | 72 | 'PluginURI' => 'Plugin URI', |
| | 73 | 'Version' => 'Version', |
| | 74 | 'Description' => 'Description', |
| | 75 | 'Author' => 'Author', |
| | 76 | 'AuthorURI' => 'Author URI', |
| | 77 | 'TextDomain' => 'Text Domain', |
| | 78 | 'DomainPath' => 'Domain Path', |
| | 79 | 'Network' => 'Network', |
| | 80 | 'RequiresWP' => 'Requires at least', |
| | 81 | 'RequiresPHP' => 'Requires PHP', |
| | 82 | // Site Wide Only is deprecated in favor of Network. |
| | 83 | '_sitewide' => 'Site Wide Only', |
| | 84 | ); |
| | 85 | |
| | 86 | $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); |
| | 87 | |
| | 88 | // Site Wide Only is the old header for Network. |
| | 89 | if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) { |
| | 90 | /* translators: 1: Site Wide Only: true, 2: Network: true */ |
| | 91 | _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The %1$s plugin header is deprecated. Use %2$s instead.' ), '<code>Site Wide Only: true</code>', '<code>Network: true</code>' ) ); |
| | 92 | $plugin_data['Network'] = $plugin_data['_sitewide']; |
| | 93 | } |
| | 94 | $plugin_data['Network'] = ( 'true' === strtolower( $plugin_data['Network'] ) ); |
| | 95 | unset( $plugin_data['_sitewide'] ); |
| | 96 | |
| | 97 | // If no text domain is defined fall back to the plugin slug. |
| | 98 | if ( ! $plugin_data['TextDomain'] ) { |
| | 99 | $plugin_slug = dirname( plugin_basename( $plugin_file ) ); |
| | 100 | if ( '.' !== $plugin_slug && false === strpos( $plugin_slug, '/' ) ) { |
| | 101 | $plugin_data['TextDomain'] = $plugin_slug; |
| | 102 | } |
| | 103 | } |
| | 104 | |
| | 105 | if ( $markup || $translate ) { |
| | 106 | $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); |
| | 107 | } else { |
| | 108 | $plugin_data['Title'] = $plugin_data['Name']; |
| | 109 | $plugin_data['AuthorName'] = $plugin_data['Author']; |
| | 110 | } |
| | 111 | |
| | 112 | return $plugin_data; |
| 145 | | // Sanitize the plugin filename to a WP_PLUGIN_DIR relative path. |
| 146 | | $plugin_file = plugin_basename( $plugin_file ); |
| 147 | | |
| 148 | | // Translate fields. |
| 149 | | if ( $translate ) { |
| 150 | | $textdomain = $plugin_data['TextDomain']; |
| 151 | | if ( $textdomain ) { |
| 152 | | if ( ! is_textdomain_loaded( $textdomain ) ) { |
| 153 | | if ( $plugin_data['DomainPath'] ) { |
| 154 | | load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] ); |
| 155 | | } else { |
| 156 | | load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); |
| 157 | | } |
| 158 | | } |
| 159 | | } elseif ( 'hello.php' === basename( $plugin_file ) ) { |
| 160 | | $textdomain = 'default'; |
| 161 | | } |
| 162 | | if ( $textdomain ) { |
| 163 | | foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) { |
| 164 | | // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain |
| 165 | | $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); |
| 166 | | } |
| 167 | | } |
| 168 | | } |
| 169 | | |
| 170 | | // Sanitize fields. |
| 171 | | $allowed_tags_in_links = array( |
| 172 | | 'abbr' => array( 'title' => true ), |
| 173 | | 'acronym' => array( 'title' => true ), |
| 174 | | 'code' => true, |
| 175 | | 'em' => true, |
| 176 | | 'strong' => true, |
| 177 | | ); |
| 178 | | |
| 179 | | $allowed_tags = $allowed_tags_in_links; |
| 180 | | $allowed_tags['a'] = array( |
| 181 | | 'href' => true, |
| 182 | | 'title' => true, |
| 183 | | ); |
| 184 | | |
| 185 | | // Name is marked up inside <a> tags. Don't allow these. |
| 186 | | // Author is too, but some plugins have used <a> here (omitting Author URI). |
| 187 | | $plugin_data['Name'] = wp_kses( $plugin_data['Name'], $allowed_tags_in_links ); |
| 188 | | $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags ); |
| 189 | | |
| 190 | | $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags ); |
| 191 | | $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $allowed_tags ); |
| 192 | | |
| 193 | | $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] ); |
| 194 | | $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] ); |
| 195 | | |
| 196 | | $plugin_data['Title'] = $plugin_data['Name']; |
| 197 | | $plugin_data['AuthorName'] = $plugin_data['Author']; |
| 198 | | |
| 199 | | // Apply markup. |
| 200 | | if ( $markup ) { |
| 201 | | if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) { |
| 202 | | $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>'; |
| 203 | | } |
| 204 | | |
| 205 | | if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) { |
| 206 | | $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; |
| 207 | | } |
| 208 | | |
| 209 | | $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); |
| 210 | | |
| 211 | | if ( $plugin_data['Author'] ) { |
| 212 | | $plugin_data['Description'] .= sprintf( |
| 213 | | /* translators: %s: Plugin author. */ |
| 214 | | ' <cite>' . __( 'By %s.' ) . '</cite>', |
| 215 | | $plugin_data['Author'] |
| 216 | | ); |
| 217 | | } |
| 218 | | } |
| 219 | | |
| 220 | | return $plugin_data; |
| | 145 | // Sanitize the plugin filename to a WP_PLUGIN_DIR relative path. |
| | 146 | $plugin_file = plugin_basename( $plugin_file ); |
| | 147 | |
| | 148 | // Translate fields. |
| | 149 | if ( $translate ) { |
| | 150 | $textdomain = $plugin_data['TextDomain']; |
| | 151 | if ( $textdomain ) { |
| | 152 | if ( ! is_textdomain_loaded( $textdomain ) ) { |
| | 153 | if ( $plugin_data['DomainPath'] ) { |
| | 154 | load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] ); |
| | 155 | } else { |
| | 156 | load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); |
| | 157 | } |
| | 158 | } |
| | 159 | } elseif ( 'hello.php' === basename( $plugin_file ) ) { |
| | 160 | $textdomain = 'default'; |
| | 161 | } |
| | 162 | if ( $textdomain ) { |
| | 163 | foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) { |
| | 164 | // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain |
| | 165 | $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); |
| | 166 | } |
| | 167 | } |
| | 168 | } |
| | 169 | |
| | 170 | // Sanitize fields. |
| | 171 | $allowed_tags_in_links = array( |
| | 172 | 'abbr' => array( 'title' => true ), |
| | 173 | 'acronym' => array( 'title' => true ), |
| | 174 | 'code' => true, |
| | 175 | 'em' => true, |
| | 176 | 'strong' => true, |
| | 177 | ); |
| | 178 | |
| | 179 | $allowed_tags = $allowed_tags_in_links; |
| | 180 | $allowed_tags['a'] = array( |
| | 181 | 'href' => true, |
| | 182 | 'title' => true, |
| | 183 | ); |
| | 184 | |
| | 185 | // Name is marked up inside <a> tags. Don't allow these. |
| | 186 | // Author is too, but some plugins have used <a> here (omitting Author URI). |
| | 187 | $plugin_data['Name'] = wp_kses( $plugin_data['Name'], $allowed_tags_in_links ); |
| | 188 | $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags ); |
| | 189 | |
| | 190 | $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags ); |
| | 191 | $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $allowed_tags ); |
| | 192 | |
| | 193 | $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] ); |
| | 194 | $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] ); |
| | 195 | |
| | 196 | $plugin_data['Title'] = $plugin_data['Name']; |
| | 197 | $plugin_data['AuthorName'] = $plugin_data['Author']; |
| | 198 | |
| | 199 | // Apply markup. |
| | 200 | if ( $markup ) { |
| | 201 | if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) { |
| | 202 | $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>'; |
| | 203 | } |
| | 204 | |
| | 205 | if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) { |
| | 206 | $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; |
| | 207 | } |
| | 208 | |
| | 209 | $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); |
| | 210 | |
| | 211 | if ( $plugin_data['Author'] ) { |
| | 212 | $plugin_data['Description'] .= sprintf( |
| | 213 | /* translators: %s: Plugin author. */ |
| | 214 | ' <cite>' . __( 'By %s.' ) . '</cite>', |
| | 215 | $plugin_data['Author'] |
| | 216 | ); |
| | 217 | } |
| | 218 | } |
| | 219 | |
| | 220 | return $plugin_data; |
| 280 | | $cache_plugins = wp_cache_get( 'plugins', 'plugins' ); |
| 281 | | if ( ! $cache_plugins ) { |
| 282 | | $cache_plugins = array(); |
| 283 | | } |
| 284 | | |
| 285 | | if ( isset( $cache_plugins[ $plugin_folder ] ) ) { |
| 286 | | return $cache_plugins[ $plugin_folder ]; |
| 287 | | } |
| 288 | | |
| 289 | | $wp_plugins = array(); |
| 290 | | $plugin_root = WP_PLUGIN_DIR; |
| 291 | | if ( ! empty( $plugin_folder ) ) { |
| 292 | | $plugin_root .= $plugin_folder; |
| 293 | | } |
| 294 | | |
| 295 | | // Files in wp-content/plugins directory. |
| 296 | | $plugins_dir = @ opendir( $plugin_root ); |
| 297 | | $plugin_files = array(); |
| 298 | | |
| 299 | | if ( $plugins_dir ) { |
| 300 | | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
| 301 | | if ( '.' === substr( $file, 0, 1 ) ) { |
| 302 | | continue; |
| 303 | | } |
| 304 | | |
| 305 | | if ( is_dir( $plugin_root . '/' . $file ) ) { |
| 306 | | $plugins_subdir = @ opendir( $plugin_root . '/' . $file ); |
| 307 | | |
| 308 | | if ( $plugins_subdir ) { |
| 309 | | while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) { |
| 310 | | if ( '.' === substr( $subfile, 0, 1 ) ) { |
| 311 | | continue; |
| 312 | | } |
| 313 | | |
| 314 | | if ( '.php' === substr( $subfile, -4 ) ) { |
| 315 | | $plugin_files[] = "$file/$subfile"; |
| 316 | | } |
| 317 | | } |
| 318 | | |
| 319 | | closedir( $plugins_subdir ); |
| 320 | | } |
| 321 | | } else { |
| 322 | | if ( '.php' === substr( $file, -4 ) ) { |
| 323 | | $plugin_files[] = $file; |
| 324 | | } |
| 325 | | } |
| 326 | | } |
| 327 | | |
| 328 | | closedir( $plugins_dir ); |
| 329 | | } |
| 330 | | |
| 331 | | if ( empty( $plugin_files ) ) { |
| 332 | | return $wp_plugins; |
| 333 | | } |
| 334 | | |
| 335 | | foreach ( $plugin_files as $plugin_file ) { |
| 336 | | if ( ! is_readable( "$plugin_root/$plugin_file" ) ) { |
| 337 | | continue; |
| 338 | | } |
| 339 | | |
| 340 | | // Do not apply markup/translate as it will be cached. |
| 341 | | $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); |
| 342 | | |
| 343 | | if ( empty( $plugin_data['Name'] ) ) { |
| 344 | | continue; |
| 345 | | } |
| 346 | | |
| 347 | | $wp_plugins[ plugin_basename( $plugin_file ) ] = $plugin_data; |
| 348 | | } |
| 349 | | |
| 350 | | uasort( $wp_plugins, '_sort_uname_callback' ); |
| 351 | | |
| 352 | | $cache_plugins[ $plugin_folder ] = $wp_plugins; |
| 353 | | wp_cache_set( 'plugins', $cache_plugins, 'plugins' ); |
| 354 | | |
| 355 | | return $wp_plugins; |
| | 280 | $cache_plugins = wp_cache_get( 'plugins', 'plugins' ); |
| | 281 | if ( ! $cache_plugins ) { |
| | 282 | $cache_plugins = array(); |
| | 283 | } |
| | 284 | |
| | 285 | if ( isset( $cache_plugins[ $plugin_folder ] ) ) { |
| | 286 | return $cache_plugins[ $plugin_folder ]; |
| | 287 | } |
| | 288 | |
| | 289 | $wp_plugins = array(); |
| | 290 | $plugin_root = WP_PLUGIN_DIR; |
| | 291 | if ( ! empty( $plugin_folder ) ) { |
| | 292 | $plugin_root .= $plugin_folder; |
| | 293 | } |
| | 294 | |
| | 295 | // Files in wp-content/plugins directory. |
| | 296 | $plugins_dir = @ opendir( $plugin_root ); |
| | 297 | $plugin_files = array(); |
| | 298 | |
| | 299 | if ( $plugins_dir ) { |
| | 300 | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
| | 301 | if ( '.' === substr( $file, 0, 1 ) ) { |
| | 302 | continue; |
| | 303 | } |
| | 304 | |
| | 305 | if ( is_dir( $plugin_root . '/' . $file ) ) { |
| | 306 | $plugins_subdir = @ opendir( $plugin_root . '/' . $file ); |
| | 307 | |
| | 308 | if ( $plugins_subdir ) { |
| | 309 | while ( ( $subfile = readdir( $plugins_subdir ) ) !== false ) { |
| | 310 | if ( '.' === substr( $subfile, 0, 1 ) ) { |
| | 311 | continue; |
| | 312 | } |
| | 313 | |
| | 314 | if ( '.php' === substr( $subfile, -4 ) ) { |
| | 315 | $plugin_files[] = "$file/$subfile"; |
| | 316 | } |
| | 317 | } |
| | 318 | |
| | 319 | closedir( $plugins_subdir ); |
| | 320 | } |
| | 321 | } else { |
| | 322 | if ( '.php' === substr( $file, -4 ) ) { |
| | 323 | $plugin_files[] = $file; |
| | 324 | } |
| | 325 | } |
| | 326 | } |
| | 327 | |
| | 328 | closedir( $plugins_dir ); |
| | 329 | } |
| | 330 | |
| | 331 | if ( empty( $plugin_files ) ) { |
| | 332 | return $wp_plugins; |
| | 333 | } |
| | 334 | |
| | 335 | foreach ( $plugin_files as $plugin_file ) { |
| | 336 | if ( ! is_readable( "$plugin_root/$plugin_file" ) ) { |
| | 337 | continue; |
| | 338 | } |
| | 339 | |
| | 340 | // Do not apply markup/translate as it will be cached. |
| | 341 | $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); |
| | 342 | |
| | 343 | if ( empty( $plugin_data['Name'] ) ) { |
| | 344 | continue; |
| | 345 | } |
| | 346 | |
| | 347 | $wp_plugins[ plugin_basename( $plugin_file ) ] = $plugin_data; |
| | 348 | } |
| | 349 | |
| | 350 | uasort( $wp_plugins, '_sort_uname_callback' ); |
| | 351 | |
| | 352 | $cache_plugins[ $plugin_folder ] = $wp_plugins; |
| | 353 | wp_cache_set( 'plugins', $cache_plugins, 'plugins' ); |
| | 354 | |
| | 355 | return $wp_plugins; |
| 367 | | $wp_plugins = array(); |
| 368 | | $plugin_files = array(); |
| 369 | | |
| 370 | | if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { |
| 371 | | return $wp_plugins; |
| 372 | | } |
| 373 | | |
| 374 | | // Files in wp-content/mu-plugins directory. |
| 375 | | $plugins_dir = @opendir( WPMU_PLUGIN_DIR ); |
| 376 | | if ( $plugins_dir ) { |
| 377 | | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
| 378 | | if ( '.php' === substr( $file, -4 ) ) { |
| 379 | | $plugin_files[] = $file; |
| 380 | | } |
| 381 | | } |
| 382 | | } else { |
| 383 | | return $wp_plugins; |
| 384 | | } |
| 385 | | |
| 386 | | closedir( $plugins_dir ); |
| 387 | | |
| 388 | | if ( empty( $plugin_files ) ) { |
| 389 | | return $wp_plugins; |
| 390 | | } |
| 391 | | |
| 392 | | foreach ( $plugin_files as $plugin_file ) { |
| 393 | | if ( ! is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) { |
| 394 | | continue; |
| 395 | | } |
| 396 | | |
| 397 | | // Do not apply markup/translate as it will be cached. |
| 398 | | $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); |
| 399 | | |
| 400 | | if ( empty( $plugin_data['Name'] ) ) { |
| 401 | | $plugin_data['Name'] = $plugin_file; |
| 402 | | } |
| 403 | | |
| 404 | | $wp_plugins[ $plugin_file ] = $plugin_data; |
| 405 | | } |
| 406 | | |
| 407 | | if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php' ) <= 30 ) { |
| 408 | | // Silence is golden. |
| 409 | | unset( $wp_plugins['index.php'] ); |
| 410 | | } |
| 411 | | |
| 412 | | uasort( $wp_plugins, '_sort_uname_callback' ); |
| 413 | | |
| 414 | | return $wp_plugins; |
| | 367 | $wp_plugins = array(); |
| | 368 | $plugin_files = array(); |
| | 369 | |
| | 370 | if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { |
| | 371 | return $wp_plugins; |
| | 372 | } |
| | 373 | |
| | 374 | // Files in wp-content/mu-plugins directory. |
| | 375 | $plugins_dir = @opendir( WPMU_PLUGIN_DIR ); |
| | 376 | if ( $plugins_dir ) { |
| | 377 | while ( ( $file = readdir( $plugins_dir ) ) !== false ) { |
| | 378 | if ( '.php' === substr( $file, -4 ) ) { |
| | 379 | $plugin_files[] = $file; |
| | 380 | } |
| | 381 | } |
| | 382 | } else { |
| | 383 | return $wp_plugins; |
| | 384 | } |
| | 385 | |
| | 386 | closedir( $plugins_dir ); |
| | 387 | |
| | 388 | if ( empty( $plugin_files ) ) { |
| | 389 | return $wp_plugins; |
| | 390 | } |
| | 391 | |
| | 392 | foreach ( $plugin_files as $plugin_file ) { |
| | 393 | if ( ! is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) { |
| | 394 | continue; |
| | 395 | } |
| | 396 | |
| | 397 | // Do not apply markup/translate as it will be cached. |
| | 398 | $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); |
| | 399 | |
| | 400 | if ( empty( $plugin_data['Name'] ) ) { |
| | 401 | $plugin_data['Name'] = $plugin_file; |
| | 402 | } |
| | 403 | |
| | 404 | $wp_plugins[ $plugin_file ] = $plugin_data; |
| | 405 | } |
| | 406 | |
| | 407 | if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php' ) <= 30 ) { |
| | 408 | // Silence is golden. |
| | 409 | unset( $wp_plugins['index.php'] ); |
| | 410 | } |
| | 411 | |
| | 412 | uasort( $wp_plugins, '_sort_uname_callback' ); |
| | 413 | |
| | 414 | return $wp_plugins; |
| 493 | | $dropins = array( |
| 494 | | 'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE |
| 495 | | 'db.php' => array( __( 'Custom database class.' ), true ), // Auto on load. |
| 496 | | 'db-error.php' => array( __( 'Custom database error message.' ), true ), // Auto on error. |
| 497 | | 'install.php' => array( __( 'Custom installation script.' ), true ), // Auto on installation. |
| 498 | | 'maintenance.php' => array( __( 'Custom maintenance message.' ), true ), // Auto on maintenance. |
| 499 | | 'object-cache.php' => array( __( 'External object cache.' ), true ), // Auto on load. |
| 500 | | 'php-error.php' => array( __( 'Custom PHP error message.' ), true ), // Auto on error. |
| 501 | | 'fatal-error-handler.php' => array( __( 'Custom PHP fatal error handler.' ), true ), // Auto on error. |
| 502 | | ); |
| 503 | | |
| 504 | | if ( is_multisite() ) { |
| 505 | | $dropins['sunrise.php'] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE |
| 506 | | $dropins['blog-deleted.php'] = array( __( 'Custom site deleted message.' ), true ); // Auto on deleted blog. |
| 507 | | $dropins['blog-inactive.php'] = array( __( 'Custom site inactive message.' ), true ); // Auto on inactive blog. |
| 508 | | $dropins['blog-suspended.php'] = array( __( 'Custom site suspended message.' ), true ); // Auto on archived or spammed blog. |
| 509 | | } |
| 510 | | |
| 511 | | return $dropins; |
| | 493 | $dropins = array( |
| | 494 | 'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE |
| | 495 | 'db.php' => array( __( 'Custom database class.' ), true ), // Auto on load. |
| | 496 | 'db-error.php' => array( __( 'Custom database error message.' ), true ), // Auto on error. |
| | 497 | 'install.php' => array( __( 'Custom installation script.' ), true ), // Auto on installation. |
| | 498 | 'maintenance.php' => array( __( 'Custom maintenance message.' ), true ), // Auto on maintenance. |
| | 499 | 'object-cache.php' => array( __( 'External object cache.' ), true ), // Auto on load. |
| | 500 | 'php-error.php' => array( __( 'Custom PHP error message.' ), true ), // Auto on error. |
| | 501 | 'fatal-error-handler.php' => array( __( 'Custom PHP fatal error handler.' ), true ), // Auto on error. |
| | 502 | ); |
| | 503 | |
| | 504 | if ( is_multisite() ) { |
| | 505 | $dropins['sunrise.php'] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE |
| | 506 | $dropins['blog-deleted.php'] = array( __( 'Custom site deleted message.' ), true ); // Auto on deleted blog. |
| | 507 | $dropins['blog-inactive.php'] = array( __( 'Custom site inactive message.' ), true ); // Auto on inactive blog. |
| | 508 | $dropins['blog-suspended.php'] = array( __( 'Custom site suspended message.' ), true ); // Auto on archived or spammed blog. |
| | 509 | } |
| | 510 | |
| | 511 | return $dropins; |
| 634 | | $plugin = plugin_basename( trim( $plugin ) ); |
| 635 | | |
| 636 | | if ( is_multisite() && ( $network_wide || is_network_only_plugin( $plugin ) ) ) { |
| 637 | | $network_wide = true; |
| 638 | | $current = get_site_option( 'active_sitewide_plugins', array() ); |
| 639 | | $_GET['networkwide'] = 1; // Back compat for plugins looking for this value. |
| 640 | | } else { |
| 641 | | $current = get_option( 'active_plugins', array() ); |
| 642 | | } |
| 643 | | |
| 644 | | $valid = validate_plugin( $plugin ); |
| 645 | | if ( is_wp_error( $valid ) ) { |
| 646 | | return $valid; |
| 647 | | } |
| 648 | | |
| 649 | | $requirements = validate_plugin_requirements( $plugin ); |
| 650 | | if ( is_wp_error( $requirements ) ) { |
| 651 | | return $requirements; |
| 652 | | } |
| 653 | | |
| 654 | | if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current, true ) ) ) { |
| 655 | | if ( ! empty( $redirect ) ) { |
| 656 | | // We'll override this later if the plugin can be included without fatal error. |
| 657 | | wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) ); |
| 658 | | } |
| 659 | | |
| 660 | | ob_start(); |
| 661 | | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); |
| 662 | | $_wp_plugin_file = $plugin; |
| 663 | | if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { |
| 664 | | define( 'WP_SANDBOX_SCRAPING', true ); |
| 665 | | } |
| 666 | | include_once WP_PLUGIN_DIR . '/' . $plugin; |
| 667 | | $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin. |
| 668 | | |
| 669 | | if ( ! $silent ) { |
| 670 | | /** |
| 671 | | * Fires before a plugin is activated. |
| 672 | | * |
| 673 | | * If a plugin is silently activated (such as during an update), |
| 674 | | * this hook does not fire. |
| 675 | | * |
| 676 | | * @since 2.9.0 |
| 677 | | * |
| 678 | | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| 679 | | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
| 680 | | * or just the current site. Multisite only. Default false. |
| 681 | | */ |
| 682 | | do_action( 'activate_plugin', $plugin, $network_wide ); |
| 683 | | |
| 684 | | /** |
| 685 | | * Fires as a specific plugin is being activated. |
| 686 | | * |
| 687 | | * This hook is the "activation" hook used internally by register_activation_hook(). |
| 688 | | * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename. |
| 689 | | * |
| 690 | | * If a plugin is silently activated (such as during an update), this hook does not fire. |
| 691 | | * |
| 692 | | * @since 2.0.0 |
| 693 | | * |
| 694 | | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
| 695 | | * or just the current site. Multisite only. Default false. |
| 696 | | */ |
| 697 | | do_action( "activate_{$plugin}", $network_wide ); |
| 698 | | } |
| 699 | | |
| 700 | | if ( $network_wide ) { |
| 701 | | $current = get_site_option( 'active_sitewide_plugins', array() ); |
| 702 | | $current[ $plugin ] = time(); |
| 703 | | update_site_option( 'active_sitewide_plugins', $current ); |
| 704 | | } else { |
| 705 | | $current = get_option( 'active_plugins', array() ); |
| 706 | | $current[] = $plugin; |
| 707 | | sort( $current ); |
| 708 | | update_option( 'active_plugins', $current ); |
| 709 | | } |
| 710 | | |
| 711 | | if ( ! $silent ) { |
| 712 | | /** |
| 713 | | * Fires after a plugin has been activated. |
| 714 | | * |
| 715 | | * If a plugin is silently activated (such as during an update), |
| 716 | | * this hook does not fire. |
| 717 | | * |
| 718 | | * @since 2.9.0 |
| 719 | | * |
| 720 | | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| 721 | | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
| 722 | | * or just the current site. Multisite only. Default false. |
| 723 | | */ |
| 724 | | do_action( 'activated_plugin', $plugin, $network_wide ); |
| 725 | | } |
| 726 | | |
| 727 | | if ( ob_get_length() > 0 ) { |
| 728 | | $output = ob_get_clean(); |
| 729 | | return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output ); |
| 730 | | } |
| 731 | | ob_end_clean(); |
| 732 | | } |
| 733 | | |
| 734 | | return null; |
| | 634 | $plugin = plugin_basename( trim( $plugin ) ); |
| | 635 | |
| | 636 | if ( is_multisite() && ( $network_wide || is_network_only_plugin( $plugin ) ) ) { |
| | 637 | $network_wide = true; |
| | 638 | $current = get_site_option( 'active_sitewide_plugins', array() ); |
| | 639 | $_GET['networkwide'] = 1; // Back compat for plugins looking for this value. |
| | 640 | } else { |
| | 641 | $current = get_option( 'active_plugins', array() ); |
| | 642 | } |
| | 643 | |
| | 644 | $valid = validate_plugin( $plugin ); |
| | 645 | if ( is_wp_error( $valid ) ) { |
| | 646 | return $valid; |
| | 647 | } |
| | 648 | |
| | 649 | $requirements = validate_plugin_requirements( $plugin ); |
| | 650 | if ( is_wp_error( $requirements ) ) { |
| | 651 | return $requirements; |
| | 652 | } |
| | 653 | |
| | 654 | if ( ( $network_wide && ! isset( $current[ $plugin ] ) ) || ( ! $network_wide && ! in_array( $plugin, $current, true ) ) ) { |
| | 655 | if ( ! empty( $redirect ) ) { |
| | 656 | // We'll override this later if the plugin can be included without fatal error. |
| | 657 | wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) ); |
| | 658 | } |
| | 659 | |
| | 660 | ob_start(); |
| | 661 | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); |
| | 662 | $_wp_plugin_file = $plugin; |
| | 663 | if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { |
| | 664 | define( 'WP_SANDBOX_SCRAPING', true ); |
| | 665 | } |
| | 666 | include_once WP_PLUGIN_DIR . '/' . $plugin; |
| | 667 | $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin. |
| | 668 | |
| | 669 | if ( ! $silent ) { |
| | 670 | /** |
| | 671 | * Fires before a plugin is activated. |
| | 672 | * |
| | 673 | * If a plugin is silently activated (such as during an update), |
| | 674 | * this hook does not fire. |
| | 675 | * |
| | 676 | * @since 2.9.0 |
| | 677 | * |
| | 678 | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| | 679 | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
| | 680 | * or just the current site. Multisite only. Default false. |
| | 681 | */ |
| | 682 | do_action( 'activate_plugin', $plugin, $network_wide ); |
| | 683 | |
| | 684 | /** |
| | 685 | * Fires as a specific plugin is being activated. |
| | 686 | * |
| | 687 | * This hook is the "activation" hook used internally by register_activation_hook(). |
| | 688 | * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename. |
| | 689 | * |
| | 690 | * If a plugin is silently activated (such as during an update), this hook does not fire. |
| | 691 | * |
| | 692 | * @since 2.0.0 |
| | 693 | * |
| | 694 | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
| | 695 | * or just the current site. Multisite only. Default false. |
| | 696 | */ |
| | 697 | do_action( "activate_{$plugin}", $network_wide ); |
| | 698 | } |
| | 699 | |
| | 700 | if ( $network_wide ) { |
| | 701 | $current = get_site_option( 'active_sitewide_plugins', array() ); |
| | 702 | $current[ $plugin ] = time(); |
| | 703 | update_site_option( 'active_sitewide_plugins', $current ); |
| | 704 | } else { |
| | 705 | $current = get_option( 'active_plugins', array() ); |
| | 706 | $current[] = $plugin; |
| | 707 | sort( $current ); |
| | 708 | update_option( 'active_plugins', $current ); |
| | 709 | } |
| | 710 | |
| | 711 | if ( ! $silent ) { |
| | 712 | /** |
| | 713 | * Fires after a plugin has been activated. |
| | 714 | * |
| | 715 | * If a plugin is silently activated (such as during an update), |
| | 716 | * this hook does not fire. |
| | 717 | * |
| | 718 | * @since 2.9.0 |
| | 719 | * |
| | 720 | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| | 721 | * @param bool $network_wide Whether to enable the plugin for all sites in the network |
| | 722 | * or just the current site. Multisite only. Default false. |
| | 723 | */ |
| | 724 | do_action( 'activated_plugin', $plugin, $network_wide ); |
| | 725 | } |
| | 726 | |
| | 727 | if ( ob_get_length() > 0 ) { |
| | 728 | $output = ob_get_clean(); |
| | 729 | return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output ); |
| | 730 | } |
| | 731 | ob_end_clean(); |
| | 732 | } |
| | 733 | |
| | 734 | return null; |
| 752 | | if ( is_multisite() ) { |
| 753 | | $network_current = get_site_option( 'active_sitewide_plugins', array() ); |
| 754 | | } |
| 755 | | $current = get_option( 'active_plugins', array() ); |
| 756 | | $do_blog = false; |
| 757 | | $do_network = false; |
| 758 | | |
| 759 | | foreach ( (array) $plugins as $plugin ) { |
| 760 | | $plugin = plugin_basename( trim( $plugin ) ); |
| 761 | | if ( ! is_plugin_active( $plugin ) ) { |
| 762 | | continue; |
| 763 | | } |
| 764 | | |
| 765 | | $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin ); |
| 766 | | |
| 767 | | if ( ! $silent ) { |
| 768 | | /** |
| 769 | | * Fires before a plugin is deactivated. |
| 770 | | * |
| 771 | | * If a plugin is silently deactivated (such as during an update), |
| 772 | | * this hook does not fire. |
| 773 | | * |
| 774 | | * @since 2.9.0 |
| 775 | | * |
| 776 | | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| 777 | | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
| 778 | | * or just the current site. Multisite only. Default false. |
| 779 | | */ |
| 780 | | do_action( 'deactivate_plugin', $plugin, $network_deactivating ); |
| 781 | | } |
| 782 | | |
| 783 | | if ( false !== $network_wide ) { |
| 784 | | if ( is_plugin_active_for_network( $plugin ) ) { |
| 785 | | $do_network = true; |
| 786 | | unset( $network_current[ $plugin ] ); |
| 787 | | } elseif ( $network_wide ) { |
| 788 | | continue; |
| 789 | | } |
| 790 | | } |
| 791 | | |
| 792 | | if ( true !== $network_wide ) { |
| 793 | | $key = array_search( $plugin, $current, true ); |
| 794 | | if ( false !== $key ) { |
| 795 | | $do_blog = true; |
| 796 | | unset( $current[ $key ] ); |
| 797 | | } |
| 798 | | } |
| 799 | | |
| 800 | | if ( $do_blog && wp_is_recovery_mode() ) { |
| 801 | | list( $extension ) = explode( '/', $plugin ); |
| 802 | | wp_paused_plugins()->delete( $extension ); |
| 803 | | } |
| 804 | | |
| 805 | | if ( ! $silent ) { |
| 806 | | /** |
| 807 | | * Fires as a specific plugin is being deactivated. |
| 808 | | * |
| 809 | | * This hook is the "deactivation" hook used internally by register_deactivation_hook(). |
| 810 | | * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename. |
| 811 | | * |
| 812 | | * If a plugin is silently deactivated (such as during an update), this hook does not fire. |
| 813 | | * |
| 814 | | * @since 2.0.0 |
| 815 | | * |
| 816 | | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
| 817 | | * or just the current site. Multisite only. Default false. |
| 818 | | */ |
| 819 | | do_action( "deactivate_{$plugin}", $network_deactivating ); |
| 820 | | |
| 821 | | /** |
| 822 | | * Fires after a plugin is deactivated. |
| 823 | | * |
| 824 | | * If a plugin is silently deactivated (such as during an update), |
| 825 | | * this hook does not fire. |
| 826 | | * |
| 827 | | * @since 2.9.0 |
| 828 | | * |
| 829 | | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| 830 | | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
| 831 | | * or just the current site. Multisite only. Default false. |
| 832 | | */ |
| 833 | | do_action( 'deactivated_plugin', $plugin, $network_deactivating ); |
| 834 | | } |
| 835 | | } |
| 836 | | |
| 837 | | if ( $do_blog ) { |
| 838 | | update_option( 'active_plugins', $current ); |
| 839 | | } |
| 840 | | if ( $do_network ) { |
| 841 | | update_site_option( 'active_sitewide_plugins', $network_current ); |
| 842 | | } |
| | 752 | if ( is_multisite() ) { |
| | 753 | $network_current = get_site_option( 'active_sitewide_plugins', array() ); |
| | 754 | } |
| | 755 | $current = get_option( 'active_plugins', array() ); |
| | 756 | $do_blog = false; |
| | 757 | $do_network = false; |
| | 758 | |
| | 759 | foreach ( (array) $plugins as $plugin ) { |
| | 760 | $plugin = plugin_basename( trim( $plugin ) ); |
| | 761 | if ( ! is_plugin_active( $plugin ) ) { |
| | 762 | continue; |
| | 763 | } |
| | 764 | |
| | 765 | $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin ); |
| | 766 | |
| | 767 | if ( ! $silent ) { |
| | 768 | /** |
| | 769 | * Fires before a plugin is deactivated. |
| | 770 | * |
| | 771 | * If a plugin is silently deactivated (such as during an update), |
| | 772 | * this hook does not fire. |
| | 773 | * |
| | 774 | * @since 2.9.0 |
| | 775 | * |
| | 776 | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| | 777 | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
| | 778 | * or just the current site. Multisite only. Default false. |
| | 779 | */ |
| | 780 | do_action( 'deactivate_plugin', $plugin, $network_deactivating ); |
| | 781 | } |
| | 782 | |
| | 783 | if ( false !== $network_wide ) { |
| | 784 | if ( is_plugin_active_for_network( $plugin ) ) { |
| | 785 | $do_network = true; |
| | 786 | unset( $network_current[ $plugin ] ); |
| | 787 | } elseif ( $network_wide ) { |
| | 788 | continue; |
| | 789 | } |
| | 790 | } |
| | 791 | |
| | 792 | if ( true !== $network_wide ) { |
| | 793 | $key = array_search( $plugin, $current, true ); |
| | 794 | if ( false !== $key ) { |
| | 795 | $do_blog = true; |
| | 796 | unset( $current[ $key ] ); |
| | 797 | } |
| | 798 | } |
| | 799 | |
| | 800 | if ( $do_blog && wp_is_recovery_mode() ) { |
| | 801 | list( $extension ) = explode( '/', $plugin ); |
| | 802 | wp_paused_plugins()->delete( $extension ); |
| | 803 | } |
| | 804 | |
| | 805 | if ( ! $silent ) { |
| | 806 | /** |
| | 807 | * Fires as a specific plugin is being deactivated. |
| | 808 | * |
| | 809 | * This hook is the "deactivation" hook used internally by register_deactivation_hook(). |
| | 810 | * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename. |
| | 811 | * |
| | 812 | * If a plugin is silently deactivated (such as during an update), this hook does not fire. |
| | 813 | * |
| | 814 | * @since 2.0.0 |
| | 815 | * |
| | 816 | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
| | 817 | * or just the current site. Multisite only. Default false. |
| | 818 | */ |
| | 819 | do_action( "deactivate_{$plugin}", $network_deactivating ); |
| | 820 | |
| | 821 | /** |
| | 822 | * Fires after a plugin is deactivated. |
| | 823 | * |
| | 824 | * If a plugin is silently deactivated (such as during an update), |
| | 825 | * this hook does not fire. |
| | 826 | * |
| | 827 | * @since 2.9.0 |
| | 828 | * |
| | 829 | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| | 830 | * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network |
| | 831 | * or just the current site. Multisite only. Default false. |
| | 832 | */ |
| | 833 | do_action( 'deactivated_plugin', $plugin, $network_deactivating ); |
| | 834 | } |
| | 835 | } |
| | 836 | |
| | 837 | if ( $do_blog ) { |
| | 838 | update_option( 'active_plugins', $current ); |
| | 839 | } |
| | 840 | if ( $do_network ) { |
| | 841 | update_site_option( 'active_sitewide_plugins', $network_current ); |
| | 842 | } |
| 898 | | global $wp_filesystem; |
| 899 | | |
| 900 | | if ( empty( $plugins ) ) { |
| 901 | | return false; |
| 902 | | } |
| 903 | | |
| 904 | | $checked = array(); |
| 905 | | foreach ( $plugins as $plugin ) { |
| 906 | | $checked[] = 'checked[]=' . $plugin; |
| 907 | | } |
| 908 | | |
| 909 | | $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&' . implode( '&', $checked ), 'bulk-plugins' ); |
| 910 | | |
| 911 | | ob_start(); |
| 912 | | $credentials = request_filesystem_credentials( $url ); |
| 913 | | $data = ob_get_clean(); |
| 914 | | |
| 915 | | if ( false === $credentials ) { |
| 916 | | if ( ! empty( $data ) ) { |
| 917 | | require_once ABSPATH . 'wp-admin/admin-header.php'; |
| 918 | | echo $data; |
| 919 | | require_once ABSPATH . 'wp-admin/admin-footer.php'; |
| 920 | | exit; |
| 921 | | } |
| 922 | | return; |
| 923 | | } |
| 924 | | |
| 925 | | if ( ! WP_Filesystem( $credentials ) ) { |
| 926 | | ob_start(); |
| 927 | | // Failed to connect. Error and request again. |
| 928 | | request_filesystem_credentials( $url, '', true ); |
| 929 | | $data = ob_get_clean(); |
| 930 | | |
| 931 | | if ( ! empty( $data ) ) { |
| 932 | | require_once ABSPATH . 'wp-admin/admin-header.php'; |
| 933 | | echo $data; |
| 934 | | require_once ABSPATH . 'wp-admin/admin-footer.php'; |
| 935 | | exit; |
| 936 | | } |
| 937 | | return; |
| 938 | | } |
| 939 | | |
| 940 | | if ( ! is_object( $wp_filesystem ) ) { |
| 941 | | return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); |
| 942 | | } |
| 943 | | |
| 944 | | if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
| 945 | | return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors ); |
| 946 | | } |
| 947 | | |
| 948 | | // Get the base plugin folder. |
| 949 | | $plugins_dir = $wp_filesystem->wp_plugins_dir(); |
| 950 | | if ( empty( $plugins_dir ) ) { |
| 951 | | return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress plugin directory.' ) ); |
| 952 | | } |
| 953 | | |
| 954 | | $plugins_dir = trailingslashit( $plugins_dir ); |
| 955 | | |
| 956 | | $plugin_translations = wp_get_installed_translations( 'plugins' ); |
| 957 | | |
| 958 | | $errors = array(); |
| 959 | | |
| 960 | | foreach ( $plugins as $plugin_file ) { |
| 961 | | // Run Uninstall hook. |
| 962 | | if ( is_uninstallable_plugin( $plugin_file ) ) { |
| 963 | | uninstall_plugin( $plugin_file ); |
| 964 | | } |
| 965 | | |
| 966 | | /** |
| 967 | | * Fires immediately before a plugin deletion attempt. |
| 968 | | * |
| 969 | | * @since 4.4.0 |
| 970 | | * |
| 971 | | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 972 | | */ |
| 973 | | do_action( 'delete_plugin', $plugin_file ); |
| 974 | | |
| 975 | | $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) ); |
| 976 | | |
| 977 | | // If plugin is in its own directory, recursively delete the directory. |
| 978 | | // Base check on if plugin includes directory separator AND that it's not the root plugin folder. |
| 979 | | if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) { |
| 980 | | $deleted = $wp_filesystem->delete( $this_plugin_dir, true ); |
| 981 | | } else { |
| 982 | | $deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file ); |
| 983 | | } |
| 984 | | |
| 985 | | /** |
| 986 | | * Fires immediately after a plugin deletion attempt. |
| 987 | | * |
| 988 | | * @since 4.4.0 |
| 989 | | * |
| 990 | | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 991 | | * @param bool $deleted Whether the plugin deletion was successful. |
| 992 | | */ |
| 993 | | do_action( 'deleted_plugin', $plugin_file, $deleted ); |
| 994 | | |
| 995 | | if ( ! $deleted ) { |
| 996 | | $errors[] = $plugin_file; |
| 997 | | continue; |
| 998 | | } |
| 999 | | |
| 1000 | | // Remove language files, silently. |
| 1001 | | $plugin_slug = dirname( $plugin_file ); |
| 1002 | | if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) { |
| 1003 | | $translations = $plugin_translations[ $plugin_slug ]; |
| 1004 | | |
| 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' ); |
| 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 | | } |
| 1013 | | } |
| 1014 | | } |
| 1015 | | } |
| 1016 | | |
| 1017 | | // Remove deleted plugins from the plugin updates list. |
| 1018 | | $current = get_site_transient( 'update_plugins' ); |
| 1019 | | if ( $current ) { |
| 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 ); |
| 1028 | | } |
| 1029 | | |
| 1030 | | if ( ! empty( $errors ) ) { |
| 1031 | | if ( 1 === count( $errors ) ) { |
| 1032 | | /* translators: %s: Plugin filename. */ |
| 1033 | | $message = __( 'Could not fully remove the plugin %s.' ); |
| 1034 | | } else { |
| 1035 | | /* translators: %s: Comma-separated list of plugin filenames. */ |
| 1036 | | $message = __( 'Could not fully remove the plugins %s.' ); |
| 1037 | | } |
| 1038 | | |
| 1039 | | return new WP_Error( 'could_not_remove_plugin', sprintf( $message, implode( ', ', $errors ) ) ); |
| 1040 | | } |
| 1041 | | |
| 1042 | | return true; |
| | 898 | global $wp_filesystem; |
| | 899 | |
| | 900 | if ( empty( $plugins ) ) { |
| | 901 | return false; |
| | 902 | } |
| | 903 | |
| | 904 | $checked = array(); |
| | 905 | foreach ( $plugins as $plugin ) { |
| | 906 | $checked[] = 'checked[]=' . $plugin; |
| | 907 | } |
| | 908 | |
| | 909 | $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&' . implode( '&', $checked ), 'bulk-plugins' ); |
| | 910 | |
| | 911 | ob_start(); |
| | 912 | $credentials = request_filesystem_credentials( $url ); |
| | 913 | $data = ob_get_clean(); |
| | 914 | |
| | 915 | if ( false === $credentials ) { |
| | 916 | if ( ! empty( $data ) ) { |
| | 917 | require_once ABSPATH . 'wp-admin/admin-header.php'; |
| | 918 | echo $data; |
| | 919 | require_once ABSPATH . 'wp-admin/admin-footer.php'; |
| | 920 | exit; |
| | 921 | } |
| | 922 | return; |
| | 923 | } |
| | 924 | |
| | 925 | if ( ! WP_Filesystem( $credentials ) ) { |
| | 926 | ob_start(); |
| | 927 | // Failed to connect. Error and request again. |
| | 928 | request_filesystem_credentials( $url, '', true ); |
| | 929 | $data = ob_get_clean(); |
| | 930 | |
| | 931 | if ( ! empty( $data ) ) { |
| | 932 | require_once ABSPATH . 'wp-admin/admin-header.php'; |
| | 933 | echo $data; |
| | 934 | require_once ABSPATH . 'wp-admin/admin-footer.php'; |
| | 935 | exit; |
| | 936 | } |
| | 937 | return; |
| | 938 | } |
| | 939 | |
| | 940 | if ( ! is_object( $wp_filesystem ) ) { |
| | 941 | return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); |
| | 942 | } |
| | 943 | |
| | 944 | if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
| | 945 | return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors ); |
| | 946 | } |
| | 947 | |
| | 948 | // Get the base plugin folder. |
| | 949 | $plugins_dir = $wp_filesystem->wp_plugins_dir(); |
| | 950 | if ( empty( $plugins_dir ) ) { |
| | 951 | return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress plugin directory.' ) ); |
| | 952 | } |
| | 953 | |
| | 954 | $plugins_dir = trailingslashit( $plugins_dir ); |
| | 955 | |
| | 956 | $plugin_translations = wp_get_installed_translations( 'plugins' ); |
| | 957 | |
| | 958 | $errors = array(); |
| | 959 | |
| | 960 | foreach ( $plugins as $plugin_file ) { |
| | 961 | // Run Uninstall hook. |
| | 962 | if ( is_uninstallable_plugin( $plugin_file ) ) { |
| | 963 | uninstall_plugin( $plugin_file ); |
| | 964 | } |
| | 965 | |
| | 966 | /** |
| | 967 | * Fires immediately before a plugin deletion attempt. |
| | 968 | * |
| | 969 | * @since 4.4.0 |
| | 970 | * |
| | 971 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| | 972 | */ |
| | 973 | do_action( 'delete_plugin', $plugin_file ); |
| | 974 | |
| | 975 | $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) ); |
| | 976 | |
| | 977 | // If plugin is in its own directory, recursively delete the directory. |
| | 978 | // Base check on if plugin includes directory separator AND that it's not the root plugin folder. |
| | 979 | if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) { |
| | 980 | $deleted = $wp_filesystem->delete( $this_plugin_dir, true ); |
| | 981 | } else { |
| | 982 | $deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file ); |
| | 983 | } |
| | 984 | |
| | 985 | /** |
| | 986 | * Fires immediately after a plugin deletion attempt. |
| | 987 | * |
| | 988 | * @since 4.4.0 |
| | 989 | * |
| | 990 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| | 991 | * @param bool $deleted Whether the plugin deletion was successful. |
| | 992 | */ |
| | 993 | do_action( 'deleted_plugin', $plugin_file, $deleted ); |
| | 994 | |
| | 995 | if ( ! $deleted ) { |
| | 996 | $errors[] = $plugin_file; |
| | 997 | continue; |
| | 998 | } |
| | 999 | |
| | 1000 | // Remove language files, silently. |
| | 1001 | $plugin_slug = dirname( $plugin_file ); |
| | 1002 | if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) { |
| | 1003 | $translations = $plugin_translations[ $plugin_slug ]; |
| | 1004 | |
| | 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' ); |
| | 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 | } |
| | 1013 | } |
| | 1014 | } |
| | 1015 | } |
| | 1016 | |
| | 1017 | // Remove deleted plugins from the plugin updates list. |
| | 1018 | $current = get_site_transient( 'update_plugins' ); |
| | 1019 | if ( $current ) { |
| | 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 ); |
| | 1028 | } |
| | 1029 | |
| | 1030 | if ( ! empty( $errors ) ) { |
| | 1031 | if ( 1 === count( $errors ) ) { |
| | 1032 | /* translators: %s: Plugin filename. */ |
| | 1033 | $message = __( 'Could not fully remove the plugin %s.' ); |
| | 1034 | } else { |
| | 1035 | /* translators: %s: Comma-separated list of plugin filenames. */ |
| | 1036 | $message = __( 'Could not fully remove the plugins %s.' ); |
| | 1037 | } |
| | 1038 | |
| | 1039 | return new WP_Error( 'could_not_remove_plugin', sprintf( $message, implode( ', ', $errors ) ) ); |
| | 1040 | } |
| | 1041 | |
| | 1042 | return true; |
| 1055 | | $plugins = get_option( 'active_plugins', array() ); |
| 1056 | | // Validate vartype: array. |
| 1057 | | if ( ! is_array( $plugins ) ) { |
| 1058 | | update_option( 'active_plugins', array() ); |
| 1059 | | $plugins = array(); |
| 1060 | | } |
| 1061 | | |
| 1062 | | if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { |
| 1063 | | $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
| 1064 | | $plugins = array_merge( $plugins, array_keys( $network_plugins ) ); |
| 1065 | | } |
| 1066 | | |
| 1067 | | if ( empty( $plugins ) ) { |
| 1068 | | return array(); |
| 1069 | | } |
| 1070 | | |
| 1071 | | $invalid = array(); |
| 1072 | | |
| 1073 | | // Invalid plugins get deactivated. |
| 1074 | | foreach ( $plugins as $plugin ) { |
| 1075 | | $result = validate_plugin( $plugin ); |
| 1076 | | if ( is_wp_error( $result ) ) { |
| 1077 | | $invalid[ $plugin ] = $result; |
| 1078 | | deactivate_plugins( $plugin, true ); |
| 1079 | | } |
| 1080 | | } |
| 1081 | | return $invalid; |
| | 1055 | $plugins = get_option( 'active_plugins', array() ); |
| | 1056 | // Validate vartype: array. |
| | 1057 | if ( ! is_array( $plugins ) ) { |
| | 1058 | update_option( 'active_plugins', array() ); |
| | 1059 | $plugins = array(); |
| | 1060 | } |
| | 1061 | |
| | 1062 | if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { |
| | 1063 | $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
| | 1064 | $plugins = array_merge( $plugins, array_keys( $network_plugins ) ); |
| | 1065 | } |
| | 1066 | |
| | 1067 | if ( empty( $plugins ) ) { |
| | 1068 | return array(); |
| | 1069 | } |
| | 1070 | |
| | 1071 | $invalid = array(); |
| | 1072 | |
| | 1073 | // Invalid plugins get deactivated. |
| | 1074 | foreach ( $plugins as $plugin ) { |
| | 1075 | $result = validate_plugin( $plugin ); |
| | 1076 | if ( is_wp_error( $result ) ) { |
| | 1077 | $invalid[ $plugin ] = $result; |
| | 1078 | deactivate_plugins( $plugin, true ); |
| | 1079 | } |
| | 1080 | } |
| | 1081 | return $invalid; |
| 1126 | | $plugin_headers = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
| 1127 | | |
| 1128 | | $requirements = array( |
| 1129 | | 'requires' => ! empty( $plugin_headers['RequiresWP'] ) ? $plugin_headers['RequiresWP'] : '', |
| 1130 | | 'requires_php' => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '', |
| 1131 | | ); |
| 1132 | | |
| 1133 | | $readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt'; |
| 1134 | | |
| 1135 | | if ( file_exists( $readme_file ) ) { |
| 1136 | | $readme_headers = get_file_data( |
| 1137 | | $readme_file, |
| 1138 | | array( |
| 1139 | | 'requires' => 'Requires at least', |
| 1140 | | 'requires_php' => 'Requires PHP', |
| 1141 | | ), |
| 1142 | | 'plugin' |
| 1143 | | ); |
| 1144 | | |
| 1145 | | $requirements = array_merge( $readme_headers, $requirements ); |
| 1146 | | } |
| 1147 | | |
| 1148 | | $compatible_wp = is_wp_version_compatible( $requirements['requires'] ); |
| 1149 | | $compatible_php = is_php_version_compatible( $requirements['requires_php'] ); |
| 1150 | | |
| 1151 | | if ( ! $compatible_wp && ! $compatible_php ) { |
| 1152 | | return new WP_Error( |
| 1153 | | 'plugin_wp_php_incompatible', |
| 1154 | | sprintf( |
| 1155 | | /* translators: %s: Plugin name. */ |
| 1156 | | _x( '<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.', 'plugin' ), |
| 1157 | | $plugin_headers['Name'] |
| 1158 | | ) |
| 1159 | | ); |
| 1160 | | } elseif ( ! $compatible_php ) { |
| 1161 | | return new WP_Error( |
| 1162 | | 'plugin_php_incompatible', |
| 1163 | | sprintf( |
| 1164 | | /* translators: %s: Plugin name. */ |
| 1165 | | _x( '<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.', 'plugin' ), |
| 1166 | | $plugin_headers['Name'] |
| 1167 | | ) |
| 1168 | | ); |
| 1169 | | } elseif ( ! $compatible_wp ) { |
| 1170 | | return new WP_Error( |
| 1171 | | 'plugin_wp_incompatible', |
| 1172 | | sprintf( |
| 1173 | | /* translators: %s: Plugin name. */ |
| 1174 | | _x( '<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.', 'plugin' ), |
| 1175 | | $plugin_headers['Name'] |
| 1176 | | ) |
| 1177 | | ); |
| 1178 | | } |
| 1179 | | |
| 1180 | | return true; |
| | 1126 | $plugin_headers = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
| | 1127 | |
| | 1128 | $requirements = array( |
| | 1129 | 'requires' => ! empty( $plugin_headers['RequiresWP'] ) ? $plugin_headers['RequiresWP'] : '', |
| | 1130 | 'requires_php' => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '', |
| | 1131 | ); |
| | 1132 | |
| | 1133 | $php_compat = version_compare( phpversion(), $plugin_headers['RequiresPHP'], '>=' ); |
| | 1134 | |
| | 1135 | $readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt'; |
| | 1136 | |
| | 1137 | if ( file_exists( $readme_file ) ) { |
| | 1138 | $readme_headers = get_file_data( |
| | 1139 | $readme_file, |
| | 1140 | array( |
| | 1141 | 'requires' => 'Requires at least', |
| | 1142 | 'requires_php' => 'Requires PHP', |
| | 1143 | ), |
| | 1144 | 'plugin' |
| | 1145 | ); |
| | 1146 | |
| | 1147 | $requirements = array_merge( $readme_headers, $requirements ); |
| | 1148 | } |
| | 1149 | |
| | 1150 | |
| | 1151 | /* translators: %s: URL to Update PHP page. */ |
| | 1152 | $php_update_message = ( !$php_compat ) ? '<p>' . sprintf( __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ) : ''; |
| | 1153 | |
| | 1154 | $annotation = ( !$php_compat ) ? wp_get_update_php_annotation() : false; |
| | 1155 | |
| | 1156 | if ( $annotation ) { |
| | 1157 | $php_update_message .= '</p><p><em>' . $annotation . '</em>'; |
| | 1158 | } |
| | 1159 | |
| | 1160 | |
| | 1161 | $compatible_wp = is_wp_version_compatible( $requirements['requires'] ); |
| | 1162 | $compatible_php = is_php_version_compatible( $requirements['requires_php'] ); |
| | 1163 | |
| | 1164 | if ( ! $compatible_wp && ! $compatible_php ) { |
| | 1165 | return new WP_Error( |
| | 1166 | 'plugin_wp_php_incompatible', |
| | 1167 | sprintf( |
| | 1168 | /* translators: 1: WordPress version, 2: PHP version, 3: Plugin name, 4: Current WordPress version 5: Current PHP version. */ |
| | 1169 | _x( 'Current WordPress and PHP versions do not meet minimum requirements of %1$s and %2$s for %3$s. |
| | 1170 | Your current versions of WordPress and PHP are %4$s and %5$s respectively.', 'plugin' ), |
| | 1171 | $requirements['requires'], |
| | 1172 | $requirements['requires_php'], |
| | 1173 | $plugin_headers['Name'], |
| | 1174 | get_bloginfo('version'), |
| | 1175 | phpversion() |
| | 1176 | ) . $php_update_message |
| | 1177 | ); |
| | 1178 | } elseif ( ! $compatible_php ) { |
| | 1179 | return new WP_Error( |
| | 1180 | 'plugin_php_incompatible', |
| | 1181 | sprintf( |
| | 1182 | /* translators: 1: PHP version, 2: Current PHP Version, 3: Plugin name. */ |
| | 1183 | _x( 'Your current PHP version is %2$s. The current PHP version does not meet minimum requirements of %1$s for 3$s.', 'plugin' ), |
| | 1184 | $requirements['requires_php'], |
| | 1185 | phpversion(), |
| | 1186 | $plugin_headers['Name'] |
| | 1187 | ) . $php_update_message |
| | 1188 | ); |
| | 1189 | } elseif ( ! $compatible_wp ) { |
| | 1190 | return new WP_Error( |
| | 1191 | 'plugin_wp_incompatible', |
| | 1192 | sprintf( |
| | 1193 | /* translators: 1: WordPress version, 2: Current WordPress version, 3: Plugin name. */ |
| | 1194 | _x( 'Your current WordPress version is: %2$s. The current WordPress version does not meet minimum requirements of %1$s for %3$s.', 'plugin' ), |
| | 1195 | $requirements['requires'], |
| | 1196 | get_bloginfo('version'), |
| | 1197 | $plugin_headers['Name'] |
| | 1198 | ) . $php_update_message |
| | 1199 | ); |
| | 1200 | } |
| | 1201 | |
| | 1202 | return true; |
| 1213 | | $file = plugin_basename( $plugin ); |
| 1214 | | |
| 1215 | | $uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); |
| 1216 | | |
| 1217 | | /** |
| 1218 | | * Fires in uninstall_plugin() immediately before the plugin is uninstalled. |
| 1219 | | * |
| 1220 | | * @since 4.5.0 |
| 1221 | | * |
| 1222 | | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| 1223 | | * @param array $uninstallable_plugins Uninstallable plugins. |
| 1224 | | */ |
| 1225 | | do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins ); |
| 1226 | | |
| 1227 | | if ( file_exists( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) { |
| 1228 | | if ( isset( $uninstallable_plugins[ $file ] ) ) { |
| 1229 | | unset( $uninstallable_plugins[ $file ] ); |
| 1230 | | update_option( 'uninstall_plugins', $uninstallable_plugins ); |
| 1231 | | } |
| 1232 | | unset( $uninstallable_plugins ); |
| 1233 | | |
| 1234 | | define( 'WP_UNINSTALL_PLUGIN', $file ); |
| 1235 | | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); |
| 1236 | | include WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php'; |
| 1237 | | |
| 1238 | | return true; |
| 1239 | | } |
| 1240 | | |
| 1241 | | if ( isset( $uninstallable_plugins[ $file ] ) ) { |
| 1242 | | $callable = $uninstallable_plugins[ $file ]; |
| 1243 | | unset( $uninstallable_plugins[ $file ] ); |
| 1244 | | update_option( 'uninstall_plugins', $uninstallable_plugins ); |
| 1245 | | unset( $uninstallable_plugins ); |
| 1246 | | |
| 1247 | | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); |
| 1248 | | include WP_PLUGIN_DIR . '/' . $file; |
| 1249 | | |
| 1250 | | add_action( "uninstall_{$file}", $callable ); |
| 1251 | | |
| 1252 | | /** |
| 1253 | | * Fires in uninstall_plugin() once the plugin has been uninstalled. |
| 1254 | | * |
| 1255 | | * The action concatenates the 'uninstall_' prefix with the basename of the |
| 1256 | | * plugin passed to uninstall_plugin() to create a dynamically-named action. |
| 1257 | | * |
| 1258 | | * @since 2.7.0 |
| 1259 | | */ |
| 1260 | | do_action( "uninstall_{$file}" ); |
| 1261 | | } |
| | 1235 | $file = plugin_basename( $plugin ); |
| | 1236 | |
| | 1237 | $uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); |
| | 1238 | |
| | 1239 | /** |
| | 1240 | * Fires in uninstall_plugin() immediately before the plugin is uninstalled. |
| | 1241 | * |
| | 1242 | * @since 4.5.0 |
| | 1243 | * |
| | 1244 | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| | 1245 | * @param array $uninstallable_plugins Uninstallable plugins. |
| | 1246 | */ |
| | 1247 | do_action( 'pre_uninstall_plugin', $plugin, $uninstallable_plugins ); |
| | 1248 | |
| | 1249 | if ( file_exists( WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php' ) ) { |
| | 1250 | if ( isset( $uninstallable_plugins[ $file ] ) ) { |
| | 1251 | unset( $uninstallable_plugins[ $file ] ); |
| | 1252 | update_option( 'uninstall_plugins', $uninstallable_plugins ); |
| | 1253 | } |
| | 1254 | unset( $uninstallable_plugins ); |
| | 1255 | |
| | 1256 | define( 'WP_UNINSTALL_PLUGIN', $file ); |
| | 1257 | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); |
| | 1258 | include WP_PLUGIN_DIR . '/' . dirname( $file ) . '/uninstall.php'; |
| | 1259 | |
| | 1260 | return true; |
| | 1261 | } |
| | 1262 | |
| | 1263 | if ( isset( $uninstallable_plugins[ $file ] ) ) { |
| | 1264 | $callable = $uninstallable_plugins[ $file ]; |
| | 1265 | unset( $uninstallable_plugins[ $file ] ); |
| | 1266 | update_option( 'uninstall_plugins', $uninstallable_plugins ); |
| | 1267 | unset( $uninstallable_plugins ); |
| | 1268 | |
| | 1269 | wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); |
| | 1270 | include WP_PLUGIN_DIR . '/' . $file; |
| | 1271 | |
| | 1272 | add_action( "uninstall_{$file}", $callable ); |
| | 1273 | |
| | 1274 | /** |
| | 1275 | * Fires in uninstall_plugin() once the plugin has been uninstalled. |
| | 1276 | * |
| | 1277 | * The action concatenates the 'uninstall_' prefix with the basename of the |
| | 1278 | * plugin passed to uninstall_plugin() to create a dynamically-named action. |
| | 1279 | * |
| | 1280 | * @since 2.7.0 |
| | 1281 | */ |
| | 1282 | do_action( "uninstall_{$file}" ); |
| | 1283 | } |
| 1373 | | global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv, |
| 1374 | | $_registered_pages, $_parent_pages; |
| 1375 | | |
| 1376 | | $menu_slug = plugin_basename( $menu_slug ); |
| 1377 | | $parent_slug = plugin_basename( $parent_slug ); |
| 1378 | | |
| 1379 | | if ( isset( $_wp_real_parent_file[ $parent_slug ] ) ) { |
| 1380 | | $parent_slug = $_wp_real_parent_file[ $parent_slug ]; |
| 1381 | | } |
| 1382 | | |
| 1383 | | if ( ! current_user_can( $capability ) ) { |
| 1384 | | $_wp_submenu_nopriv[ $parent_slug ][ $menu_slug ] = true; |
| 1385 | | return false; |
| 1386 | | } |
| 1387 | | |
| 1388 | | /* |
| 1389 | | * If the parent doesn't already have a submenu, add a link to the parent |
| 1390 | | * as the first item in the submenu. If the submenu file is the same as the |
| 1391 | | * parent file someone is trying to link back to the parent manually. In |
| 1392 | | * this case, don't automatically add a link back to avoid duplication. |
| 1393 | | */ |
| 1394 | | if ( ! isset( $submenu[ $parent_slug ] ) && $menu_slug != $parent_slug ) { |
| 1395 | | foreach ( (array) $menu as $parent_menu ) { |
| 1396 | | if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) { |
| 1397 | | $submenu[ $parent_slug ][] = array_slice( $parent_menu, 0, 4 ); |
| 1398 | | } |
| 1399 | | } |
| 1400 | | } |
| 1401 | | |
| 1402 | | $new_sub_menu = array( $menu_title, $capability, $menu_slug, $page_title ); |
| 1403 | | if ( ! is_int( $position ) ) { |
| 1404 | | if ( null !== $position ) { |
| 1405 | | _doing_it_wrong( |
| 1406 | | __FUNCTION__, |
| 1407 | | sprintf( |
| 1408 | | /* translators: %s: add_submenu_page() */ |
| 1409 | | __( 'The seventh parameter passed to %s should be an integer representing menu position.' ), |
| 1410 | | '<code>add_submenu_page()</code>' |
| 1411 | | ), |
| 1412 | | '5.3.0' |
| 1413 | | ); |
| 1414 | | } |
| 1415 | | |
| 1416 | | $submenu[ $parent_slug ][] = $new_sub_menu; |
| 1417 | | } else { |
| 1418 | | // Append the submenu if the parent item is not present in the submenu, |
| 1419 | | // or if position is equal or higher than the number of items in the array. |
| 1420 | | if ( ! isset( $submenu[ $parent_slug ] ) || $position >= count( $submenu[ $parent_slug ] ) ) { |
| 1421 | | $submenu[ $parent_slug ][] = $new_sub_menu; |
| 1422 | | } else { |
| 1423 | | // Test for a negative position. |
| 1424 | | $position = max( $position, 0 ); |
| 1425 | | if ( 0 === $position ) { |
| 1426 | | // For negative or `0` positions, prepend the submenu. |
| 1427 | | array_unshift( $submenu[ $parent_slug ], $new_sub_menu ); |
| 1428 | | } else { |
| 1429 | | // Grab all of the items before the insertion point. |
| 1430 | | $before_items = array_slice( $submenu[ $parent_slug ], 0, $position, true ); |
| 1431 | | // Grab all of the items after the insertion point. |
| 1432 | | $after_items = array_slice( $submenu[ $parent_slug ], $position, null, true ); |
| 1433 | | // Add the new item. |
| 1434 | | $before_items[] = $new_sub_menu; |
| 1435 | | // Merge the items. |
| 1436 | | $submenu[ $parent_slug ] = array_merge( $before_items, $after_items ); |
| 1437 | | } |
| 1438 | | } |
| 1439 | | } |
| 1440 | | // Sort the parent array. |
| 1441 | | ksort( $submenu[ $parent_slug ] ); |
| 1442 | | |
| 1443 | | $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug ); |
| 1444 | | if ( ! empty( $function ) && ! empty( $hookname ) ) { |
| 1445 | | add_action( $hookname, $function ); |
| 1446 | | } |
| 1447 | | |
| 1448 | | $_registered_pages[ $hookname ] = true; |
| 1449 | | |
| 1450 | | /* |
| 1451 | | * Backward-compatibility for plugins using add_management_page(). |
| 1452 | | * See wp-admin/admin.php for redirect from edit.php to tools.php. |
| 1453 | | */ |
| 1454 | | if ( 'tools.php' === $parent_slug ) { |
| 1455 | | $_registered_pages[ get_plugin_page_hookname( $menu_slug, 'edit.php' ) ] = true; |
| 1456 | | } |
| 1457 | | |
| 1458 | | // No parent as top level. |
| 1459 | | $_parent_pages[ $menu_slug ] = $parent_slug; |
| 1460 | | |
| 1461 | | return $hookname; |
| | 1395 | global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv, |
| | 1396 | $_registered_pages, $_parent_pages; |
| | 1397 | |
| | 1398 | $menu_slug = plugin_basename( $menu_slug ); |
| | 1399 | $parent_slug = plugin_basename( $parent_slug ); |
| | 1400 | |
| | 1401 | if ( isset( $_wp_real_parent_file[ $parent_slug ] ) ) { |
| | 1402 | $parent_slug = $_wp_real_parent_file[ $parent_slug ]; |
| | 1403 | } |
| | 1404 | |
| | 1405 | if ( ! current_user_can( $capability ) ) { |
| | 1406 | $_wp_submenu_nopriv[ $parent_slug ][ $menu_slug ] = true; |
| | 1407 | return false; |
| | 1408 | } |
| | 1409 | |
| | 1410 | /* |
| | 1411 | * If the parent doesn't already have a submenu, add a link to the parent |
| | 1412 | * as the first item in the submenu. If the submenu file is the same as the |
| | 1413 | * parent file someone is trying to link back to the parent manually. In |
| | 1414 | * this case, don't automatically add a link back to avoid duplication. |
| | 1415 | */ |
| | 1416 | if ( ! isset( $submenu[ $parent_slug ] ) && $menu_slug != $parent_slug ) { |
| | 1417 | foreach ( (array) $menu as $parent_menu ) { |
| | 1418 | if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) { |
| | 1419 | $submenu[ $parent_slug ][] = array_slice( $parent_menu, 0, 4 ); |
| | 1420 | } |
| | 1421 | } |
| | 1422 | } |
| | 1423 | |
| | 1424 | $new_sub_menu = array( $menu_title, $capability, $menu_slug, $page_title ); |
| | 1425 | if ( ! is_int( $position ) ) { |
| | 1426 | if ( null !== $position ) { |
| | 1427 | _doing_it_wrong( |
| | 1428 | __FUNCTION__, |
| | 1429 | sprintf( |
| | 1430 | /* translators: %s: add_submenu_page() */ |
| | 1431 | __( 'The seventh parameter passed to %s should be an integer representing menu position.' ), |
| | 1432 | '<code>add_submenu_page()</code>' |
| | 1433 | ), |
| | 1434 | '5.3.0' |
| | 1435 | ); |
| | 1436 | } |
| | 1437 | |
| | 1438 | $submenu[ $parent_slug ][] = $new_sub_menu; |
| | 1439 | } else { |
| | 1440 | // Append the submenu if the parent item is not present in the submenu, |
| | 1441 | // or if position is equal or higher than the number of items in the array. |
| | 1442 | if ( ! isset( $submenu[ $parent_slug ] ) || $position >= count( $submenu[ $parent_slug ] ) ) { |
| | 1443 | $submenu[ $parent_slug ][] = $new_sub_menu; |
| | 1444 | } else { |
| | 1445 | // Test for a negative position. |
| | 1446 | $position = max( $position, 0 ); |
| | 1447 | if ( 0 === $position ) { |
| | 1448 | // For negative or `0` positions, prepend the submenu. |
| | 1449 | array_unshift( $submenu[ $parent_slug ], $new_sub_menu ); |
| | 1450 | } else { |
| | 1451 | // Grab all of the items before the insertion point. |
| | 1452 | $before_items = array_slice( $submenu[ $parent_slug ], 0, $position, true ); |
| | 1453 | // Grab all of the items after the insertion point. |
| | 1454 | $after_items = array_slice( $submenu[ $parent_slug ], $position, null, true ); |
| | 1455 | // Add the new item. |
| | 1456 | $before_items[] = $new_sub_menu; |
| | 1457 | // Merge the items. |
| | 1458 | $submenu[ $parent_slug ] = array_merge( $before_items, $after_items ); |
| | 1459 | } |
| | 1460 | } |
| | 1461 | } |
| | 1462 | // Sort the parent array. |
| | 1463 | ksort( $submenu[ $parent_slug ] ); |
| | 1464 | |
| | 1465 | $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug ); |
| | 1466 | if ( ! empty( $function ) && ! empty( $hookname ) ) { |
| | 1467 | add_action( $hookname, $function ); |
| | 1468 | } |
| | 1469 | |
| | 1470 | $_registered_pages[ $hookname ] = true; |
| | 1471 | |
| | 1472 | /* |
| | 1473 | * Backward-compatibility for plugins using add_management_page(). |
| | 1474 | * See wp-admin/admin.php for redirect from edit.php to tools.php. |
| | 1475 | */ |
| | 1476 | if ( 'tools.php' === $parent_slug ) { |
| | 1477 | $_registered_pages[ get_plugin_page_hookname( $menu_slug, 'edit.php' ) ] = true; |
| | 1478 | } |
| | 1479 | |
| | 1480 | // No parent as top level. |
| | 1481 | $_parent_pages[ $menu_slug ] = $parent_slug; |
| | 1482 | |
| | 1483 | return $hookname; |
| 1843 | | global $parent_file, $menu, $submenu, $pagenow, $typenow, |
| 1844 | | $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv; |
| 1845 | | |
| 1846 | | if ( ! empty( $parent ) && 'admin.php' !== $parent ) { |
| 1847 | | if ( isset( $_wp_real_parent_file[ $parent ] ) ) { |
| 1848 | | $parent = $_wp_real_parent_file[ $parent ]; |
| 1849 | | } |
| 1850 | | return $parent; |
| 1851 | | } |
| 1852 | | |
| 1853 | | if ( 'admin.php' === $pagenow && isset( $plugin_page ) ) { |
| 1854 | | foreach ( (array) $menu as $parent_menu ) { |
| 1855 | | if ( $parent_menu[2] == $plugin_page ) { |
| 1856 | | $parent_file = $plugin_page; |
| 1857 | | if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { |
| 1858 | | $parent_file = $_wp_real_parent_file[ $parent_file ]; |
| 1859 | | } |
| 1860 | | return $parent_file; |
| 1861 | | } |
| 1862 | | } |
| 1863 | | if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { |
| 1864 | | $parent_file = $plugin_page; |
| 1865 | | if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { |
| 1866 | | $parent_file = $_wp_real_parent_file[ $parent_file ]; |
| 1867 | | } |
| 1868 | | return $parent_file; |
| 1869 | | } |
| 1870 | | } |
| 1871 | | |
| 1872 | | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) { |
| 1873 | | $parent_file = $pagenow; |
| 1874 | | if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { |
| 1875 | | $parent_file = $_wp_real_parent_file[ $parent_file ]; |
| 1876 | | } |
| 1877 | | return $parent_file; |
| 1878 | | } |
| 1879 | | |
| 1880 | | foreach ( array_keys( (array) $submenu ) as $parent ) { |
| 1881 | | foreach ( $submenu[ $parent ] as $submenu_array ) { |
| 1882 | | if ( isset( $_wp_real_parent_file[ $parent ] ) ) { |
| 1883 | | $parent = $_wp_real_parent_file[ $parent ]; |
| 1884 | | } |
| 1885 | | if ( ! empty( $typenow ) && ( "$pagenow?post_type=$typenow" === $submenu_array[2] ) ) { |
| 1886 | | $parent_file = $parent; |
| 1887 | | return $parent; |
| 1888 | | } elseif ( $submenu_array[2] == $pagenow && empty( $typenow ) && ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) ) ) { |
| 1889 | | $parent_file = $parent; |
| 1890 | | return $parent; |
| 1891 | | } elseif ( isset( $plugin_page ) && ( $plugin_page == $submenu_array[2] ) ) { |
| 1892 | | $parent_file = $parent; |
| 1893 | | return $parent; |
| 1894 | | } |
| 1895 | | } |
| 1896 | | } |
| 1897 | | |
| 1898 | | if ( empty( $parent_file ) ) { |
| 1899 | | $parent_file = ''; |
| 1900 | | } |
| 1901 | | return ''; |
| | 1865 | global $parent_file, $menu, $submenu, $pagenow, $typenow, |
| | 1866 | $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv; |
| | 1867 | |
| | 1868 | if ( ! empty( $parent ) && 'admin.php' !== $parent ) { |
| | 1869 | if ( isset( $_wp_real_parent_file[ $parent ] ) ) { |
| | 1870 | $parent = $_wp_real_parent_file[ $parent ]; |
| | 1871 | } |
| | 1872 | return $parent; |
| | 1873 | } |
| | 1874 | |
| | 1875 | if ( 'admin.php' === $pagenow && isset( $plugin_page ) ) { |
| | 1876 | foreach ( (array) $menu as $parent_menu ) { |
| | 1877 | if ( $parent_menu[2] == $plugin_page ) { |
| | 1878 | $parent_file = $plugin_page; |
| | 1879 | if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { |
| | 1880 | $parent_file = $_wp_real_parent_file[ $parent_file ]; |
| | 1881 | } |
| | 1882 | return $parent_file; |
| | 1883 | } |
| | 1884 | } |
| | 1885 | if ( isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { |
| | 1886 | $parent_file = $plugin_page; |
| | 1887 | if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { |
| | 1888 | $parent_file = $_wp_real_parent_file[ $parent_file ]; |
| | 1889 | } |
| | 1890 | return $parent_file; |
| | 1891 | } |
| | 1892 | } |
| | 1893 | |
| | 1894 | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) { |
| | 1895 | $parent_file = $pagenow; |
| | 1896 | if ( isset( $_wp_real_parent_file[ $parent_file ] ) ) { |
| | 1897 | $parent_file = $_wp_real_parent_file[ $parent_file ]; |
| | 1898 | } |
| | 1899 | return $parent_file; |
| | 1900 | } |
| | 1901 | |
| | 1902 | foreach ( array_keys( (array) $submenu ) as $parent ) { |
| | 1903 | foreach ( $submenu[ $parent ] as $submenu_array ) { |
| | 1904 | if ( isset( $_wp_real_parent_file[ $parent ] ) ) { |
| | 1905 | $parent = $_wp_real_parent_file[ $parent ]; |
| | 1906 | } |
| | 1907 | if ( ! empty( $typenow ) && ( "$pagenow?post_type=$typenow" === $submenu_array[2] ) ) { |
| | 1908 | $parent_file = $parent; |
| | 1909 | return $parent; |
| | 1910 | } elseif ( $submenu_array[2] == $pagenow && empty( $typenow ) && ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) ) ) { |
| | 1911 | $parent_file = $parent; |
| | 1912 | return $parent; |
| | 1913 | } elseif ( isset( $plugin_page ) && ( $plugin_page == $submenu_array[2] ) ) { |
| | 1914 | $parent_file = $parent; |
| | 1915 | return $parent; |
| | 1916 | } |
| | 1917 | } |
| | 1918 | } |
| | 1919 | |
| | 1920 | if ( empty( $parent_file ) ) { |
| | 1921 | $parent_file = ''; |
| | 1922 | } |
| | 1923 | return ''; |
| 1919 | | global $title, $menu, $submenu, $pagenow, $plugin_page, $typenow; |
| 1920 | | |
| 1921 | | if ( ! empty( $title ) ) { |
| 1922 | | return $title; |
| 1923 | | } |
| 1924 | | |
| 1925 | | $hook = get_plugin_page_hook( $plugin_page, $pagenow ); |
| 1926 | | |
| 1927 | | $parent = get_admin_page_parent(); |
| 1928 | | $parent1 = $parent; |
| 1929 | | |
| 1930 | | if ( empty( $parent ) ) { |
| 1931 | | foreach ( (array) $menu as $menu_array ) { |
| 1932 | | if ( isset( $menu_array[3] ) ) { |
| 1933 | | if ( $menu_array[2] == $pagenow ) { |
| 1934 | | $title = $menu_array[3]; |
| 1935 | | return $menu_array[3]; |
| 1936 | | } elseif ( isset( $plugin_page ) && ( $plugin_page == $menu_array[2] ) && ( $hook == $menu_array[3] ) ) { |
| 1937 | | $title = $menu_array[3]; |
| 1938 | | return $menu_array[3]; |
| 1939 | | } |
| 1940 | | } else { |
| 1941 | | $title = $menu_array[0]; |
| 1942 | | return $title; |
| 1943 | | } |
| 1944 | | } |
| 1945 | | } else { |
| 1946 | | foreach ( array_keys( $submenu ) as $parent ) { |
| 1947 | | foreach ( $submenu[ $parent ] as $submenu_array ) { |
| 1948 | | if ( isset( $plugin_page ) && |
| 1949 | | ( $plugin_page == $submenu_array[2] ) && |
| 1950 | | ( |
| 1951 | | ( $parent == $pagenow ) || |
| 1952 | | ( $parent == $plugin_page ) || |
| 1953 | | ( $plugin_page == $hook ) || |
| 1954 | | ( 'admin.php' === $pagenow && $parent1 != $submenu_array[2] ) || |
| 1955 | | ( ! empty( $typenow ) && $parent == $pagenow . '?post_type=' . $typenow ) |
| 1956 | | ) |
| 1957 | | ) { |
| 1958 | | $title = $submenu_array[3]; |
| 1959 | | return $submenu_array[3]; |
| 1960 | | } |
| 1961 | | |
| 1962 | | if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) { // Not the current page. |
| 1963 | | continue; |
| 1964 | | } |
| 1965 | | |
| 1966 | | if ( isset( $submenu_array[3] ) ) { |
| 1967 | | $title = $submenu_array[3]; |
| 1968 | | return $submenu_array[3]; |
| 1969 | | } else { |
| 1970 | | $title = $submenu_array[0]; |
| 1971 | | return $title; |
| 1972 | | } |
| 1973 | | } |
| 1974 | | } |
| 1975 | | if ( empty( $title ) ) { |
| 1976 | | foreach ( $menu as $menu_array ) { |
| 1977 | | if ( isset( $plugin_page ) && |
| 1978 | | ( $plugin_page == $menu_array[2] ) && |
| 1979 | | ( 'admin.php' === $pagenow ) && |
| 1980 | | ( $parent1 == $menu_array[2] ) ) { |
| 1981 | | $title = $menu_array[3]; |
| 1982 | | return $menu_array[3]; |
| 1983 | | } |
| 1984 | | } |
| 1985 | | } |
| 1986 | | } |
| 1987 | | |
| 1988 | | return $title; |
| | 1941 | global $title, $menu, $submenu, $pagenow, $plugin_page, $typenow; |
| | 1942 | |
| | 1943 | if ( ! empty( $title ) ) { |
| | 1944 | return $title; |
| | 1945 | } |
| | 1946 | |
| | 1947 | $hook = get_plugin_page_hook( $plugin_page, $pagenow ); |
| | 1948 | |
| | 1949 | $parent = get_admin_page_parent(); |
| | 1950 | $parent1 = $parent; |
| | 1951 | |
| | 1952 | if ( empty( $parent ) ) { |
| | 1953 | foreach ( (array) $menu as $menu_array ) { |
| | 1954 | if ( isset( $menu_array[3] ) ) { |
| | 1955 | if ( $menu_array[2] == $pagenow ) { |
| | 1956 | $title = $menu_array[3]; |
| | 1957 | return $menu_array[3]; |
| | 1958 | } elseif ( isset( $plugin_page ) && ( $plugin_page == $menu_array[2] ) && ( $hook == $menu_array[3] ) ) { |
| | 1959 | $title = $menu_array[3]; |
| | 1960 | return $menu_array[3]; |
| | 1961 | } |
| | 1962 | } else { |
| | 1963 | $title = $menu_array[0]; |
| | 1964 | return $title; |
| | 1965 | } |
| | 1966 | } |
| | 1967 | } else { |
| | 1968 | foreach ( array_keys( $submenu ) as $parent ) { |
| | 1969 | foreach ( $submenu[ $parent ] as $submenu_array ) { |
| | 1970 | if ( isset( $plugin_page ) && |
| | 1971 | ( $plugin_page == $submenu_array[2] ) && |
| | 1972 | ( |
| | 1973 | ( $parent == $pagenow ) || |
| | 1974 | ( $parent == $plugin_page ) || |
| | 1975 | ( $plugin_page == $hook ) || |
| | 1976 | ( 'admin.php' === $pagenow && $parent1 != $submenu_array[2] ) || |
| | 1977 | ( ! empty( $typenow ) && $parent == $pagenow . '?post_type=' . $typenow ) |
| | 1978 | ) |
| | 1979 | ) { |
| | 1980 | $title = $submenu_array[3]; |
| | 1981 | return $submenu_array[3]; |
| | 1982 | } |
| | 1983 | |
| | 1984 | if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) { // Not the current page. |
| | 1985 | continue; |
| | 1986 | } |
| | 1987 | |
| | 1988 | if ( isset( $submenu_array[3] ) ) { |
| | 1989 | $title = $submenu_array[3]; |
| | 1990 | return $submenu_array[3]; |
| | 1991 | } else { |
| | 1992 | $title = $submenu_array[0]; |
| | 1993 | return $title; |
| | 1994 | } |
| | 1995 | } |
| | 1996 | } |
| | 1997 | if ( empty( $title ) ) { |
| | 1998 | foreach ( $menu as $menu_array ) { |
| | 1999 | if ( isset( $plugin_page ) && |
| | 2000 | ( $plugin_page == $menu_array[2] ) && |
| | 2001 | ( 'admin.php' === $pagenow ) && |
| | 2002 | ( $parent1 == $menu_array[2] ) ) { |
| | 2003 | $title = $menu_array[3]; |
| | 2004 | return $menu_array[3]; |
| | 2005 | } |
| | 2006 | } |
| | 2007 | } |
| | 2008 | } |
| | 2009 | |
| | 2010 | return $title; |
| 2059 | | global $pagenow, $menu, $submenu, $_wp_menu_nopriv, $_wp_submenu_nopriv, |
| 2060 | | $plugin_page, $_registered_pages; |
| 2061 | | |
| 2062 | | $parent = get_admin_page_parent(); |
| 2063 | | |
| 2064 | | if ( ! isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $parent ][ $pagenow ] ) ) { |
| 2065 | | return false; |
| 2066 | | } |
| 2067 | | |
| 2068 | | if ( isset( $plugin_page ) ) { |
| 2069 | | if ( isset( $_wp_submenu_nopriv[ $parent ][ $plugin_page ] ) ) { |
| 2070 | | return false; |
| 2071 | | } |
| 2072 | | |
| 2073 | | $hookname = get_plugin_page_hookname( $plugin_page, $parent ); |
| 2074 | | |
| 2075 | | if ( ! isset( $_registered_pages[ $hookname ] ) ) { |
| 2076 | | return false; |
| 2077 | | } |
| 2078 | | } |
| 2079 | | |
| 2080 | | if ( empty( $parent ) ) { |
| 2081 | | if ( isset( $_wp_menu_nopriv[ $pagenow ] ) ) { |
| 2082 | | return false; |
| 2083 | | } |
| 2084 | | if ( isset( $_wp_submenu_nopriv[ $pagenow ][ $pagenow ] ) ) { |
| 2085 | | return false; |
| 2086 | | } |
| 2087 | | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) { |
| 2088 | | return false; |
| 2089 | | } |
| 2090 | | if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { |
| 2091 | | return false; |
| 2092 | | } |
| 2093 | | foreach ( array_keys( $_wp_submenu_nopriv ) as $key ) { |
| 2094 | | if ( isset( $_wp_submenu_nopriv[ $key ][ $pagenow ] ) ) { |
| 2095 | | return false; |
| 2096 | | } |
| 2097 | | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $key ][ $plugin_page ] ) ) { |
| 2098 | | return false; |
| 2099 | | } |
| 2100 | | } |
| 2101 | | return true; |
| 2102 | | } |
| 2103 | | |
| 2104 | | if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { |
| 2105 | | return false; |
| 2106 | | } |
| 2107 | | |
| 2108 | | if ( isset( $submenu[ $parent ] ) ) { |
| 2109 | | foreach ( $submenu[ $parent ] as $submenu_array ) { |
| 2110 | | if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { |
| 2111 | | if ( current_user_can( $submenu_array[1] ) ) { |
| 2112 | | return true; |
| 2113 | | } else { |
| 2114 | | return false; |
| 2115 | | } |
| 2116 | | } elseif ( $submenu_array[2] == $pagenow ) { |
| 2117 | | if ( current_user_can( $submenu_array[1] ) ) { |
| 2118 | | return true; |
| 2119 | | } else { |
| 2120 | | return false; |
| 2121 | | } |
| 2122 | | } |
| 2123 | | } |
| 2124 | | } |
| 2125 | | |
| 2126 | | foreach ( $menu as $menu_array ) { |
| 2127 | | if ( $menu_array[2] == $parent ) { |
| 2128 | | if ( current_user_can( $menu_array[1] ) ) { |
| 2129 | | return true; |
| 2130 | | } else { |
| 2131 | | return false; |
| 2132 | | } |
| 2133 | | } |
| 2134 | | } |
| 2135 | | |
| 2136 | | return true; |
| | 2081 | global $pagenow, $menu, $submenu, $_wp_menu_nopriv, $_wp_submenu_nopriv, |
| | 2082 | $plugin_page, $_registered_pages; |
| | 2083 | |
| | 2084 | $parent = get_admin_page_parent(); |
| | 2085 | |
| | 2086 | if ( ! isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $parent ][ $pagenow ] ) ) { |
| | 2087 | return false; |
| | 2088 | } |
| | 2089 | |
| | 2090 | if ( isset( $plugin_page ) ) { |
| | 2091 | if ( isset( $_wp_submenu_nopriv[ $parent ][ $plugin_page ] ) ) { |
| | 2092 | return false; |
| | 2093 | } |
| | 2094 | |
| | 2095 | $hookname = get_plugin_page_hookname( $plugin_page, $parent ); |
| | 2096 | |
| | 2097 | if ( ! isset( $_registered_pages[ $hookname ] ) ) { |
| | 2098 | return false; |
| | 2099 | } |
| | 2100 | } |
| | 2101 | |
| | 2102 | if ( empty( $parent ) ) { |
| | 2103 | if ( isset( $_wp_menu_nopriv[ $pagenow ] ) ) { |
| | 2104 | return false; |
| | 2105 | } |
| | 2106 | if ( isset( $_wp_submenu_nopriv[ $pagenow ][ $pagenow ] ) ) { |
| | 2107 | return false; |
| | 2108 | } |
| | 2109 | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $pagenow ][ $plugin_page ] ) ) { |
| | 2110 | return false; |
| | 2111 | } |
| | 2112 | if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { |
| | 2113 | return false; |
| | 2114 | } |
| | 2115 | foreach ( array_keys( $_wp_submenu_nopriv ) as $key ) { |
| | 2116 | if ( isset( $_wp_submenu_nopriv[ $key ][ $pagenow ] ) ) { |
| | 2117 | return false; |
| | 2118 | } |
| | 2119 | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[ $key ][ $plugin_page ] ) ) { |
| | 2120 | return false; |
| | 2121 | } |
| | 2122 | } |
| | 2123 | return true; |
| | 2124 | } |
| | 2125 | |
| | 2126 | if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[ $plugin_page ] ) ) { |
| | 2127 | return false; |
| | 2128 | } |
| | 2129 | |
| | 2130 | if ( isset( $submenu[ $parent ] ) ) { |
| | 2131 | foreach ( $submenu[ $parent ] as $submenu_array ) { |
| | 2132 | if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { |
| | 2133 | if ( current_user_can( $submenu_array[1] ) ) { |
| | 2134 | return true; |
| | 2135 | } else { |
| | 2136 | return false; |
| | 2137 | } |
| | 2138 | } elseif ( $submenu_array[2] == $pagenow ) { |
| | 2139 | if ( current_user_can( $submenu_array[1] ) ) { |
| | 2140 | return true; |
| | 2141 | } else { |
| | 2142 | return false; |
| | 2143 | } |
| | 2144 | } |
| | 2145 | } |
| | 2146 | } |
| | 2147 | |
| | 2148 | foreach ( $menu as $menu_array ) { |
| | 2149 | if ( $menu_array[2] == $parent ) { |
| | 2150 | if ( current_user_can( $menu_array[1] ) ) { |
| | 2151 | return true; |
| | 2152 | } else { |
| | 2153 | return false; |
| | 2154 | } |
| | 2155 | } |
| | 2156 | } |
| | 2157 | |
| | 2158 | return true; |