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('./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('jquery');
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';
57 require_once(ABSPATH . 'wp-admin/admin-header.php');
59 $nonce = 'upgrade-plugin_' . $plugin;
60 $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
62 $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
63 $upgrader->upgrade($plugin);
65 include(ABSPATH . 'wp-admin/admin-footer.php');
67 } elseif ('activate-plugin' == $action ) {
68 if ( ! current_user_can('update_plugins') )
69 wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
71 check_admin_referer('activate-plugin_' . $plugin);
72 if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
73 wp_redirect( admin_url('update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) );
74 activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
75 wp_redirect( admin_url('update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) );
78 iframe_header( __('Plugin Reactivation'), true );
79 if ( isset($_GET['success']) )
80 echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
82 if ( isset($_GET['failure']) ){
83 echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
85 if ( defined('E_RECOVERABLE_ERROR') )
86 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 error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
90 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
91 include(WP_PLUGIN_DIR . '/' . $plugin);
94 } elseif ( 'install-plugin' == $action ) {
96 if ( ! current_user_can('install_plugins') )
97 wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
99 include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
101 check_admin_referer('install-plugin_' . $plugin);
102 $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
104 if ( is_wp_error($api) )
107 $title = __('Plugin Install');
108 $parent_file = 'plugins.php';
109 $submenu_file = 'plugin-install.php';
110 require_once(ABSPATH . 'wp-admin/admin-header.php');
112 $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
113 $nonce = 'install-plugin_' . $plugin;
114 $url = 'update.php?action=install-plugin&plugin=' . $plugin;
115 if ( isset($_GET['from']) )
116 $url .= '&from=' . urlencode(stripslashes($_GET['from']));
118 $type = 'web'; //Install plugin type, From Web or an Upload.
120 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
121 $upgrader->install($api->download_link);
123 include(ABSPATH . 'wp-admin/admin-footer.php');
125 } elseif ( 'upload-plugin' == $action ) {
127 if ( ! current_user_can('install_plugins') )
128 wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
130 check_admin_referer('plugin-upload');
132 $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
134 $title = __('Upload Plugin');
135 $parent_file = 'plugins.php';
136 $submenu_file = 'plugin-install.php';
137 require_once(ABSPATH . 'wp-admin/admin-header.php');
139 $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
140 $nonce = 'plugin-upload';
141 $url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin');
142 $type = 'upload'; //Install plugin type, From Web or an Upload.
144 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
145 $upgrader->install( $file_upload->package );
147 include(ABSPATH . 'wp-admin/admin-footer.php');
149 } elseif ( 'upgrade-theme' == $action ) {
151 if ( ! current_user_can('update_themes') )
152 wp_die(__('You do not have sufficient permissions to update themes for this site.'));
154 check_admin_referer('upgrade-theme_' . $theme);
157 wp_enqueue_script('theme-preview');
158 $title = __('Update Theme');
159 $parent_file = 'themes.php';
160 $submenu_file = 'themes.php';
161 require_once(ABSPATH . 'wp-admin/admin-header.php');
163 $nonce = 'upgrade-theme_' . $theme;
164 $url = 'update.php?action=upgrade-theme&theme=' . $theme;
166 $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
167 $upgrader->upgrade($theme);
169 include(ABSPATH . 'wp-admin/admin-footer.php');
170 } elseif ( 'update-selected-themes' == $action ) {
171 if ( ! current_user_can( 'update_themes' ) )
172 wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) );
174 check_admin_referer( 'bulk-update-themes' );
176 if ( isset( $_GET['themes'] ) )
177 $themes = explode( ',', stripslashes($_GET['themes']) );
178 elseif ( isset( $_POST['checked'] ) )
179 $themes = (array) $_POST['checked'];
183 $themes = array_map('urldecode', $themes);
185 $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
186 $nonce = 'bulk-update-themes';
188 wp_enqueue_script('jquery');
191 $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
192 $upgrader->bulk_upgrade( $themes );
195 } elseif ( 'install-theme' == $action ) {
197 if ( ! current_user_can('install_themes') )
198 wp_die(__('You do not have sufficient permissions to install themes for this site.'));
200 include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
202 check_admin_referer('install-theme_' . $theme);
203 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
205 if ( is_wp_error($api) )
209 wp_enqueue_script('theme-preview');
210 $title = __('Install Themes');
211 $parent_file = 'themes.php';
212 $submenu_file = 'themes.php';
213 require_once(ABSPATH . 'wp-admin/admin-header.php');
215 $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
216 $nonce = 'install-theme_' . $theme;
217 $url = 'update.php?action=install-theme&theme=' . $theme;
218 $type = 'web'; //Install theme type, From Web or an Upload.
220 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
221 $upgrader->install($api->download_link);
223 include(ABSPATH . 'wp-admin/admin-footer.php');
225 } elseif ( 'upload-theme' == $action ) {
227 if ( ! current_user_can('install_themes') )
228 wp_die(__('You do not have sufficient permissions to install themes for this site.'));
230 check_admin_referer('theme-upload');
232 $file_upload = new File_Upload_Upgrader('themezip', 'package');
234 $title = __('Upload Theme');
235 $parent_file = 'themes.php';
236 $submenu_file = 'theme-install.php';
238 wp_enqueue_script('theme-preview');
239 require_once(ABSPATH . 'wp-admin/admin-header.php');
241 $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
242 $nonce = 'theme-upload';
243 $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
244 $type = 'upload'; //Install plugin type, From Web or an Upload.
246 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
247 $upgrader->install( $file_upload->package );
249 include(ABSPATH . 'wp-admin/admin-footer.php');
252 do_action('update-custom_' . $action);