3 * Update/Install Plugin/Theme administration panel.
6 * @subpackage Administration
9 if ( ! defined( 'IFRAME_REQUEST' ) && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ) ) )
10 define( 'IFRAME_REQUEST', true );
12 /** WordPress Administration Bootstrap */
13 require_once( dirname( __FILE__ ) . '/admin.php' );
15 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
17 if ( isset($_GET['action']) ) {
18 $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
19 $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
20 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
22 if ( 'update-selected' == $action ) {
23 if ( ! current_user_can( 'update_plugins' ) )
24 wp_die( __( 'You do not have sufficient permissions to update plugins for this site.' ) );
26 check_admin_referer( 'bulk-update-plugins' );
28 if ( isset( $_GET['plugins'] ) )
29 $plugins = explode( ',', stripslashes($_GET['plugins']) );
30 elseif ( isset( $_POST['checked'] ) )
31 $plugins = (array) $_POST['checked'];
35 $plugins = array_map('urldecode', $plugins);
37 $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
38 $nonce = 'bulk-update-plugins';
40 wp_enqueue_script( 'updates' );
43 $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
44 $upgrader->bulk_upgrade( $plugins );
48 } elseif ( 'upgrade-plugin' == $action ) {
49 if ( ! current_user_can('update_plugins') )
50 wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
52 check_admin_referer('upgrade-plugin_' . $plugin);
54 $title = __('Update Plugin');
55 $parent_file = 'plugins.php';
56 $submenu_file = 'plugins.php';
58 wp_enqueue_script( 'updates' );
59 require_once(ABSPATH . 'wp-admin/admin-header.php');
61 $nonce = 'upgrade-plugin_' . $plugin;
62 $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
64 $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
65 $upgrader->upgrade($plugin);
67 include(ABSPATH . 'wp-admin/admin-footer.php');
69 } elseif ('activate-plugin' == $action ) {
70 if ( ! current_user_can('update_plugins') )
71 wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
73 check_admin_referer('activate-plugin_' . $plugin);
74 if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
75 wp_redirect( admin_url('update.php?action=activate-plugin&failure=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce']) );
76 activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
77 wp_redirect( admin_url('update.php?action=activate-plugin&success=true&plugin=' . urlencode( $plugin ) . '&_wpnonce=' . $_GET['_wpnonce']) );
80 iframe_header( __('Plugin Reactivation'), true );
81 if ( isset($_GET['success']) )
82 echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
84 if ( isset($_GET['failure']) ){
85 echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
87 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 );
88 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
89 wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
90 include( WP_PLUGIN_DIR . '/' . $plugin );
93 } elseif ( 'install-plugin' == $action ) {
95 if ( ! current_user_can('install_plugins') )
96 wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
98 include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
100 check_admin_referer('install-plugin_' . $plugin);
101 $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
103 if ( is_wp_error($api) )
106 $title = __('Plugin Install');
107 $parent_file = 'plugins.php';
108 $submenu_file = 'plugin-install.php';
109 require_once(ABSPATH . 'wp-admin/admin-header.php');
111 $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
112 $nonce = 'install-plugin_' . $plugin;
113 $url = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin );
114 if ( isset($_GET['from']) )
115 $url .= '&from=' . urlencode(stripslashes($_GET['from']));
117 $type = 'web'; //Install plugin type, From Web or an Upload.
119 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
120 $upgrader->install($api->download_link);
122 include(ABSPATH . 'wp-admin/admin-footer.php');
124 } elseif ( 'upload-plugin' == $action ) {
126 if ( ! current_user_can('install_plugins') )
127 wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
129 check_admin_referer('plugin-upload');
131 $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
133 $title = __('Upload Plugin');
134 $parent_file = 'plugins.php';
135 $submenu_file = 'plugin-install.php';
136 require_once(ABSPATH . 'wp-admin/admin-header.php');
138 $title = sprintf( __('Installing Plugin from uploaded file: %s'), esc_html( basename( $file_upload->filename ) ) );
139 $nonce = 'plugin-upload';
140 $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-plugin');
141 $type = 'upload'; //Install plugin type, From Web or an Upload.
143 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
144 $result = $upgrader->install( $file_upload->package );
146 if ( $result || is_wp_error($result) )
147 $file_upload->cleanup();
149 include(ABSPATH . 'wp-admin/admin-footer.php');
151 } elseif ( 'upgrade-theme' == $action ) {
153 if ( ! current_user_can('update_themes') )
154 wp_die(__('You do not have sufficient permissions to update themes for this site.'));
156 check_admin_referer('upgrade-theme_' . $theme);
158 wp_enqueue_script( 'customize-loader' );
159 wp_enqueue_script( 'updates' );
161 $title = __('Update Theme');
162 $parent_file = 'themes.php';
163 $submenu_file = 'themes.php';
164 require_once(ABSPATH . 'wp-admin/admin-header.php');
166 $nonce = 'upgrade-theme_' . $theme;
167 $url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
169 $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
170 $upgrader->upgrade($theme);
172 include(ABSPATH . 'wp-admin/admin-footer.php');
173 } elseif ( 'update-selected-themes' == $action ) {
174 if ( ! current_user_can( 'update_themes' ) )
175 wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) );
177 check_admin_referer( 'bulk-update-themes' );
179 if ( isset( $_GET['themes'] ) )
180 $themes = explode( ',', stripslashes($_GET['themes']) );
181 elseif ( isset( $_POST['checked'] ) )
182 $themes = (array) $_POST['checked'];
186 $themes = array_map('urldecode', $themes);
188 $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
189 $nonce = 'bulk-update-themes';
191 wp_enqueue_script( 'updates' );
194 $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
195 $upgrader->bulk_upgrade( $themes );
198 } elseif ( 'install-theme' == $action ) {
200 if ( ! current_user_can('install_themes') )
201 wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
203 include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
205 check_admin_referer( 'install-theme_' . $theme );
206 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
208 if ( is_wp_error($api) )
211 wp_enqueue_script( 'customize-loader' );
213 $title = __('Install Themes');
214 $parent_file = 'themes.php';
215 $submenu_file = 'themes.php';
216 require_once(ABSPATH . 'wp-admin/admin-header.php');
218 $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
219 $nonce = 'install-theme_' . $theme;
220 $url = 'update.php?action=install-theme&theme=' . urlencode( $theme );
221 $type = 'web'; //Install theme type, From Web or an Upload.
223 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
224 $upgrader->install($api->download_link);
226 include(ABSPATH . 'wp-admin/admin-footer.php');
228 } elseif ( 'upload-theme' == $action ) {
230 if ( ! current_user_can('install_themes') )
231 wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
233 check_admin_referer('theme-upload');
235 $file_upload = new File_Upload_Upgrader('themezip', 'package');
237 wp_enqueue_script( 'customize-loader' );
239 $title = __('Upload Theme');
240 $parent_file = 'themes.php';
241 $submenu_file = 'theme-install.php';
243 require_once(ABSPATH . 'wp-admin/admin-header.php');
245 $title = sprintf( __('Installing Theme from uploaded file: %s'), esc_html( basename( $file_upload->filename ) ) );
246 $nonce = 'theme-upload';
247 $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-theme');
248 $type = 'upload'; //Install plugin type, From Web or an Upload.
250 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
251 $result = $upgrader->install( $file_upload->package );
253 if ( $result || is_wp_error($result) )
254 $file_upload->cleanup();
256 include(ABSPATH . 'wp-admin/admin-footer.php');
260 * Fires when a custom plugin or theme update request is received.
262 * The dynamic portion of the hook name, $action, refers to the action
263 * provided in the request for wp-admin/update.php. Can be used to
264 * provide custom update functionality for themes and plugins.
268 do_action( "update-custom_{$action}" );