3 * Plugins administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
12 if ( ! current_user_can('activate_plugins') )
13 wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) );
15 $wp_list_table = _get_list_table('WP_Plugins_List_Table');
16 $pagenum = $wp_list_table->get_pagenum();
18 $action = $wp_list_table->current_action();
20 $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
21 $s = isset($_REQUEST['s']) ? urlencode($_REQUEST['s']) : '';
23 // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
24 $_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']);
26 wp_enqueue_script( 'updates' );
32 if ( ! current_user_can('activate_plugins') )
33 wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
35 if ( is_multisite() && ! is_network_admin() && is_network_only_plugin( $plugin ) ) {
36 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
40 check_admin_referer('activate-plugin_' . $plugin);
42 $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), is_network_admin() );
43 if ( is_wp_error( $result ) ) {
44 if ( 'unexpected_output' == $result->get_error_code() ) {
45 $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s");
46 wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
53 if ( ! is_network_admin() ) {
54 $recent = (array) get_option( 'recently_activated' );
55 unset( $recent[ $plugin ] );
56 update_option( 'recently_activated', $recent );
58 $recent = (array) get_site_option( 'recently_activated' );
59 unset( $recent[ $plugin ] );
60 update_site_option( 'recently_activated', $recent );
63 if ( isset($_GET['from']) && 'import' == $_GET['from'] ) {
64 wp_redirect( self_admin_url("import.php?import=" . str_replace('-importer', '', dirname($plugin))) ); // overrides the ?error=true one above and redirects to the Imports page, stripping the -importer suffix
66 wp_redirect( self_admin_url("plugins.php?activate=true&plugin_status=$status&paged=$page&s=$s") ); // overrides the ?error=true one above
70 case 'activate-selected':
71 if ( ! current_user_can('activate_plugins') )
72 wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
74 check_admin_referer('bulk-plugins');
76 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
78 if ( is_network_admin() ) {
79 foreach ( $plugins as $i => $plugin ) {
80 // Only activate plugins which are not already network activated.
81 if ( is_plugin_active_for_network( $plugin ) ) {
82 unset( $plugins[ $i ] );
86 foreach ( $plugins as $i => $plugin ) {
87 // Only activate plugins which are not already active and are not network-only when on Multisite.
88 if ( is_plugin_active( $plugin ) || ( is_multisite() && is_network_only_plugin( $plugin ) ) ) {
89 unset( $plugins[ $i ] );
94 if ( empty($plugins) ) {
95 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
99 activate_plugins($plugins, self_admin_url('plugins.php?error=true'), is_network_admin() );
101 if ( ! is_network_admin() ) {
102 $recent = (array) get_option('recently_activated' );
104 $recent = (array) get_site_option('recently_activated' );
107 foreach ( $plugins as $plugin ) {
108 unset( $recent[ $plugin ] );
111 if ( ! is_network_admin() ) {
112 update_option( 'recently_activated', $recent );
114 update_site_option( 'recently_activated', $recent );
117 wp_redirect( self_admin_url("plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s") );
120 case 'update-selected' :
122 check_admin_referer( 'bulk-plugins' );
124 if ( isset( $_GET['plugins'] ) )
125 $plugins = explode( ',', $_GET['plugins'] );
126 elseif ( isset( $_POST['checked'] ) )
127 $plugins = (array) $_POST['checked'];
131 $title = __( 'Update Plugins' );
132 $parent_file = 'plugins.php';
134 wp_enqueue_script( 'updates' );
135 require_once(ABSPATH . 'wp-admin/admin-header.php');
137 echo '<div class="wrap">';
138 echo '<h1>' . esc_html( $title ) . '</h1>';
140 $url = self_admin_url('update.php?action=update-selected&plugins=' . urlencode( join(',', $plugins) ));
141 $url = wp_nonce_url($url, 'bulk-update-plugins');
143 echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
145 require_once(ABSPATH . 'wp-admin/admin-footer.php');
149 if ( ! current_user_can('activate_plugins') )
150 wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
152 check_admin_referer('plugin-activation-error_' . $plugin);
154 $valid = validate_plugin($plugin);
155 if ( is_wp_error($valid) )
159 error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
162 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
163 // Go back to "sandbox" scope so we get the same errors as before
164 plugin_sandbox_scrape( $plugin );
165 /** This action is documented in wp-admin/includes/plugin.php */
166 do_action( "activate_{$plugin}" );
170 if ( ! current_user_can('activate_plugins') )
171 wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.'));
173 check_admin_referer('deactivate-plugin_' . $plugin);
175 if ( ! is_network_admin() && is_plugin_active_for_network( $plugin ) ) {
176 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
180 deactivate_plugins( $plugin, false, is_network_admin() );
182 if ( ! is_network_admin() ) {
183 update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) );
185 update_site_option( 'recently_activated', array( $plugin => time() ) + (array) get_site_option( 'recently_activated' ) );
188 if ( headers_sent() )
189 echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s" ) . "' />";
191 wp_redirect( self_admin_url("plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s") );
194 case 'deactivate-selected':
195 if ( ! current_user_can('activate_plugins') )
196 wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.'));
198 check_admin_referer('bulk-plugins');
200 $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
201 // Do not deactivate plugins which are already deactivated.
202 if ( is_network_admin() ) {
203 $plugins = array_filter( $plugins, 'is_plugin_active_for_network' );
205 $plugins = array_filter( $plugins, 'is_plugin_active' );
206 $plugins = array_diff( $plugins, array_filter( $plugins, 'is_plugin_active_for_network' ) );
208 if ( empty($plugins) ) {
209 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
213 deactivate_plugins( $plugins, false, is_network_admin() );
215 $deactivated = array();
216 foreach ( $plugins as $plugin ) {
217 $deactivated[ $plugin ] = time();
220 if ( ! is_network_admin() ) {
221 update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) );
223 update_site_option( 'recently_activated', $deactivated + (array) get_site_option( 'recently_activated' ) );
226 wp_redirect( self_admin_url("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s") );
229 case 'delete-selected':
230 if ( ! current_user_can('delete_plugins') ) {
231 wp_die(__('You do not have sufficient permissions to delete plugins for this site.'));
234 check_admin_referer('bulk-plugins');
236 //$_POST = from the plugin form; $_GET = from the FTP details screen.
237 $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
238 if ( empty( $plugins ) ) {
239 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
243 $plugins = array_filter($plugins, 'is_plugin_inactive'); // Do not allow to delete Activated plugins.
244 if ( empty( $plugins ) ) {
245 wp_redirect( self_admin_url( "plugins.php?error=true&main=true&plugin_status=$status&paged=$page&s=$s" ) );
249 include(ABSPATH . 'wp-admin/update.php');
251 $parent_file = 'plugins.php';
253 if ( ! isset($_REQUEST['verify-delete']) ) {
254 wp_enqueue_script('jquery');
255 require_once(ABSPATH . 'wp-admin/admin-header.php');
259 $files_to_delete = $plugin_info = array();
260 $have_non_network_plugins = false;
261 $plugin_translations = wp_get_installed_translations( 'plugins' );
262 foreach ( (array) $plugins as $plugin ) {
263 $plugin_slug = dirname( $plugin );
265 if ( '.' == $plugin_slug ) {
266 $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
267 if ( $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) ) {
268 $plugin_info[ $plugin ] = $data;
269 $plugin_info[ $plugin ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
270 if ( ! $plugin_info[ $plugin ]['Network'] ) {
271 $have_non_network_plugins = true;
275 // Locate all the files in that folder.
276 $files = list_files( WP_PLUGIN_DIR . '/' . $plugin_slug );
278 $files_to_delete = array_merge( $files_to_delete, $files );
281 // Get plugins list from that folder.
282 if ( $folder_plugins = get_plugins( '/' . $plugin_slug ) ) {
283 foreach ( $folder_plugins as $plugin_file => $data ) {
284 $plugin_info[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $data );
285 $plugin_info[ $plugin_file ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
286 if ( ! $plugin_info[ $plugin_file ]['Network'] ) {
287 $have_non_network_plugins = true;
292 // Add translation files.
293 if ( ! empty( $plugin_translations[ $plugin_slug ] ) ) {
294 $translations = $plugin_translations[ $plugin_slug ];
296 foreach ( $translations as $translation => $data ) {
297 $files_to_delete[] = $plugin_slug . '-' . $translation . '.po';
298 $files_to_delete[] = $plugin_slug . '-' . $translation . '.mo';
303 $plugins_to_delete = count( $plugin_info );
305 <?php if ( 1 == $plugins_to_delete ) : ?>
306 <h1><?php _e( 'Delete Plugin' ); ?></h1>
307 <?php if ( $have_non_network_plugins && is_network_admin() ) : ?>
308 <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'This plugin may be active on other sites in the network.' ); ?></p></div>
310 <p><?php _e( 'You are about to remove the following plugin:' ); ?></p>
312 <h1><?php _e( 'Delete Plugins' ); ?></h1>
313 <?php if ( $have_non_network_plugins && is_network_admin() ) : ?>
314 <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These plugins may be active on other sites in the network.' ); ?></p></div>
316 <p><?php _e( 'You are about to remove the following plugins:' ); ?></p>
320 $data_to_delete = false;
321 foreach ( $plugin_info as $plugin ) {
322 if ( $plugin['is_uninstallable'] ) {
323 /* translators: 1: plugin name, 2: plugin author */
324 echo '<li>', sprintf( __( '<strong>%1$s</strong> by <em>%2$s</em> (will also <strong>delete its data</strong>)' ), $plugin['Name'], $plugin['AuthorName'] ), '</li>';
325 $data_to_delete = true;
327 /* translators: 1: plugin name, 2: plugin author */
328 echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $plugin['Name'], $plugin['AuthorName'] ), '</li>';
334 if ( $data_to_delete )
335 _e('Are you sure you wish to delete these files and data?');
337 _e('Are you sure you wish to delete these files?');
339 <form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
340 <input type="hidden" name="verify-delete" value="1" />
341 <input type="hidden" name="action" value="delete-selected" />
343 foreach ( (array) $plugins as $plugin ) {
344 echo '<input type="hidden" name="checked[]" value="' . esc_attr( $plugin ) . '" />';
347 <?php wp_nonce_field('bulk-plugins') ?>
348 <?php submit_button( $data_to_delete ? __( 'Yes, delete these files and data' ) : __( 'Yes, delete these files' ), 'button', 'submit', false ); ?>
351 $referer = wp_get_referer();
353 <form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
354 <?php submit_button( __( 'No, return me to the plugin list' ), 'button', 'submit', false ); ?>
357 <p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p>
358 <div id="files-list" style="display:none;">
361 foreach ( (array) $files_to_delete as $file ) {
362 echo '<li>' . esc_html( str_replace( WP_PLUGIN_DIR, '', $file ) ) . '</li>';
369 require_once(ABSPATH . 'wp-admin/admin-footer.php');
372 $plugins_to_delete = count( $plugins );
373 } // endif verify-delete
375 $delete_result = delete_plugins( $plugins );
377 set_transient('plugins_delete_result_' . $user_ID, $delete_result); //Store the result in a cache rather than a URL param due to object type & length
378 wp_redirect( self_admin_url("plugins.php?deleted=$plugins_to_delete&plugin_status=$status&paged=$page&s=$s") );
381 case 'clear-recent-list':
382 if ( ! is_network_admin() ) {
383 update_option( 'recently_activated', array() );
385 update_site_option( 'recently_activated', array() );
391 $wp_list_table->prepare_items();
393 wp_enqueue_script('plugin-install');
396 add_screen_option( 'per_page', array( 'default' => 999 ) );
398 get_current_screen()->add_help_tab( array(
400 'title' => __('Overview'),
402 '<p>' . __('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.') . '</p>' .
404 /* translators: 1: Plugin Browser/Installer URL, 2: WordPress Plugin Directory URL 3: local plugin directory */
405 __( 'You can find additional plugins for your site by using the <a href="%1$s">Plugin Browser/Installer</a> functionality or by browsing the <a href="%2$s" target="_blank">WordPress Plugin Directory</a> directly and installing new plugins manually. To manually install a plugin you generally just need to upload the plugin file into your %3$s directory. Once a plugin has been installed, you can activate it here.' ),
406 'plugin-install.php',
407 'https://wordpress.org/plugins/',
408 '<code>/wp-content/plugins</code>'
411 get_current_screen()->add_help_tab( array(
412 'id' => 'compatibility-problems',
413 'title' => __('Troubleshooting'),
415 '<p>' . __('Most of the time, plugins play nicely with the core of WordPress and with other plugins. Sometimes, though, a plugin’s code will get in the way of another plugin, causing compatibility issues. If your site starts doing strange things, this may be the problem. Try deactivating all your plugins and re-activating them in various combinations until you isolate which one(s) caused the issue.') . '</p>' .
417 /* translators: WP_PLUGIN_DIR constant value */
418 __( 'If something goes wrong with a plugin and you can’t use WordPress, delete or rename that file in the %s directory and it will be automatically deactivated.' ),
419 '<code>' . WP_PLUGIN_DIR . '</code>'
423 get_current_screen()->set_help_sidebar(
424 '<p><strong>' . __('For more information:') . '</strong></p>' .
425 '<p>' . __('<a href="https://codex.wordpress.org/Managing_Plugins#Plugin_Management" target="_blank">Documentation on Managing Plugins</a>') . '</p>' .
426 '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
429 get_current_screen()->set_screen_reader_content( array(
430 'heading_views' => __( 'Filter plugins list' ),
431 'heading_pagination' => __( 'Plugins list navigation' ),
432 'heading_list' => __( 'Plugins list' ),
435 $title = __('Plugins');
436 $parent_file = 'plugins.php';
438 require_once(ABSPATH . 'wp-admin/admin-header.php');
440 $invalid = validate_active_plugins();
441 if ( ! empty( $invalid ) ) {
442 foreach ( $invalid as $plugin_file => $error ) {
443 echo '<div id="message" class="error"><p>';
445 /* translators: 1: plugin file 2: error message */
446 __( 'The plugin %1$s has been <strong>deactivated</strong> due to an error: %2$s' ),
447 '<code>' . esc_html( $plugin_file ) . '</code>',
448 $error->get_error_message() );
454 <?php if ( isset($_GET['error']) ) :
456 if ( isset( $_GET['main'] ) )
457 $errmsg = __( 'You cannot delete a plugin while it is active on the main site.' );
458 elseif ( isset($_GET['charsout']) )
459 $errmsg = sprintf(__('The plugin generated %d characters of <strong>unexpected output</strong> during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.'), $_GET['charsout']);
461 $errmsg = __('Plugin could not be activated because it triggered a <strong>fatal error</strong>.');
463 <div id="message" class="error"><p><?php echo $errmsg; ?></p>
465 if ( ! isset( $_GET['main'] ) && ! isset( $_GET['charsout'] ) && wp_verify_nonce( $_GET['_error_nonce'], 'plugin-activation-error_' . $plugin ) ) {
466 $iframe_url = add_query_arg( array(
467 'action' => 'error_scrape',
468 'plugin' => urlencode( $plugin ),
469 '_wpnonce' => urlencode( $_GET['_error_nonce'] ),
470 ), admin_url( 'plugins.php' ) );
472 <iframe style="border:0" width="100%" height="70px" src="<?php echo esc_url( $iframe_url ); ?>"></iframe>
477 <?php elseif ( isset($_GET['deleted']) ) :
478 $delete_result = get_transient( 'plugins_delete_result_' . $user_ID );
479 // Delete it once we're done.
480 delete_transient( 'plugins_delete_result_' . $user_ID );
482 if ( is_wp_error($delete_result) ) : ?>
483 <div id="message" class="error notice is-dismissible"><p><?php printf( __('Plugin could not be deleted due to an error: %s'), $delete_result->get_error_message() ); ?></p></div>
485 <div id="message" class="updated notice is-dismissible">
488 if ( 1 == (int) $_GET['deleted'] ) {
489 _e( 'The selected plugin has been <strong>deleted</strong>.' );
491 _e( 'The selected plugins have been <strong>deleted</strong>.' );
497 <?php elseif ( isset($_GET['activate']) ) : ?>
498 <div id="message" class="updated notice is-dismissible"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
499 <?php elseif (isset($_GET['activate-multi'])) : ?>
500 <div id="message" class="updated notice is-dismissible"><p><?php _e('Selected plugins <strong>activated</strong>.'); ?></p></div>
501 <?php elseif ( isset($_GET['deactivate']) ) : ?>
502 <div id="message" class="updated notice is-dismissible"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
503 <?php elseif (isset($_GET['deactivate-multi'])) : ?>
504 <div id="message" class="updated notice is-dismissible"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div>
505 <?php elseif ( 'update-selected' == $action ) : ?>
506 <div id="message" class="updated notice is-dismissible"><p><?php _e('All selected plugins are up to date.'); ?></p></div>
510 <h1><?php echo esc_html( $title );
511 if ( ( ! is_multisite() || is_network_admin() ) && current_user_can('install_plugins') ) { ?>
512 <a href="<?php echo self_admin_url( 'plugin-install.php' ); ?>" class="page-title-action"><?php echo esc_html_x('Add New', 'plugin'); ?></a>
515 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( $s ) ); ?>
520 * Fires before the plugins list table is rendered.
522 * This hook also fires before the plugins list table is rendered in the Network Admin.
524 * Please note: The 'active' portion of the hook name does not refer to whether the current
525 * view is for active plugins, but rather all plugins actively-installed.
529 * @param array $plugins_all An array containing all installed plugins.
531 do_action( 'pre_current_active_plugins', $plugins['all'] );
534 <?php $wp_list_table->views(); ?>
537 <?php $wp_list_table->search_box( __( 'Search Installed Plugins' ), 'plugin' ); ?>
540 <form method="post" id="bulk-action-form">
542 <input type="hidden" name="plugin_status" value="<?php echo esc_attr($status) ?>" />
543 <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
545 <?php $wp_list_table->display(); ?>
551 wp_print_request_filesystem_credentials_modal();
553 include(ABSPATH . 'wp-admin/admin-footer.php');