3 * Update/Install Plugin/Theme administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
12 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
14 if ( isset($_GET['action']) ) {
15 $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
16 $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
17 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
19 if ( 'update-selected' == $action ) {
20 if ( ! current_user_can( 'update_plugins' ) )
21 wp_die( __( 'You do not have sufficient permissions to update plugins for this site.' ) );
23 check_admin_referer( 'bulk-update-plugins' );
25 if ( isset( $_GET['plugins'] ) )
26 $plugins = explode( ',', stripslashes($_GET['plugins']) );
27 elseif ( isset( $_POST['checked'] ) )
28 $plugins = (array) $_POST['checked'];
32 $plugins = array_map('urldecode', $plugins);
34 $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
35 $nonce = 'bulk-update-plugins';
37 require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
38 wp_enqueue_script('jquery');
41 $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
42 $upgrader->bulk_upgrade( $plugins );
46 } elseif ( 'upgrade-plugin' == $action ) {
47 if ( ! current_user_can('update_plugins') )
48 wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
50 check_admin_referer('upgrade-plugin_' . $plugin);
52 $title = __('Upgrade Plugin');
53 $parent_file = 'plugins.php';
54 $submenu_file = 'plugins.php';
55 require_once('./admin-header.php');
57 $nonce = 'upgrade-plugin_' . $plugin;
58 $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
60 $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
61 $upgrader->upgrade($plugin);
63 include('./admin-footer.php');
65 } elseif ('activate-plugin' == $action ) {
66 if ( ! current_user_can('update_plugins') )
67 wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
69 check_admin_referer('activate-plugin_' . $plugin);
70 if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
71 wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
72 activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ) );
73 wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
76 iframe_header( __('Plugin Reactivation'), true );
77 if ( isset($_GET['success']) )
78 echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
80 if ( isset($_GET['failure']) ){
81 echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
83 if ( defined('E_RECOVERABLE_ERROR') )
84 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);
86 error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
88 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
89 include(WP_PLUGIN_DIR . '/' . $plugin);
92 } elseif ( 'install-plugin' == $action ) {
94 if ( ! current_user_can('install_plugins') )
95 wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
97 include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
99 check_admin_referer('install-plugin_' . $plugin);
100 $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
102 if ( is_wp_error($api) )
105 $title = __('Plugin Install');
106 $parent_file = 'plugins.php';
107 $submenu_file = 'plugin-install.php';
108 require_once('./admin-header.php');
110 $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
111 $nonce = 'install-plugin_' . $plugin;
112 $url = 'update.php?action=install-plugin&plugin=' . $plugin;
113 if ( isset($_GET['from']) )
114 $url .= '&from=' . urlencode(stripslashes($_GET['from']));
116 $type = 'web'; //Install plugin type, From Web or an Upload.
118 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
119 $upgrader->install($api->download_link);
121 include('./admin-footer.php');
123 } elseif ( 'upload-plugin' == $action ) {
125 if ( ! current_user_can('install_plugins') )
126 wp_die(__('You do not have sufficient permissions to install plugins for this site.'));
128 check_admin_referer('plugin-upload');
130 $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
132 $title = __('Upload Plugin');
133 $parent_file = 'plugins.php';
134 $submenu_file = 'plugin-install.php';
135 require_once('./admin-header.php');
137 $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
138 $nonce = 'plugin-upload';
139 $url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin');
140 $type = 'upload'; //Install plugin type, From Web or an Upload.
142 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
143 $upgrader->install( $file_upload->package );
145 include('./admin-footer.php');
147 } elseif ( 'upgrade-theme' == $action ) {
149 if ( ! current_user_can('update_themes') )
150 wp_die(__('You do not have sufficient permissions to update themes for this site.'));
152 check_admin_referer('upgrade-theme_' . $theme);
155 wp_enqueue_script('theme-preview');
156 $title = __('Upgrade Theme');
157 $parent_file = 'themes.php';
158 $submenu_file = 'themes.php';
159 require_once('./admin-header.php');
161 $nonce = 'upgrade-theme_' . $theme;
162 $url = 'update.php?action=upgrade-theme&theme=' . $theme;
164 $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
165 $upgrader->upgrade($theme);
167 include('./admin-footer.php');
168 } elseif ( 'update-selected-themes' == $action ) {
169 if ( ! current_user_can( 'update_themes' ) )
170 wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) );
172 check_admin_referer( 'bulk-update-themes' );
174 if ( isset( $_GET['themes'] ) )
175 $themes = explode( ',', stripslashes($_GET['themes']) );
176 elseif ( isset( $_POST['checked'] ) )
177 $themes = (array) $_POST['checked'];
181 $themes = array_map('urldecode', $themes);
183 $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
184 $nonce = 'bulk-update-themes';
186 require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
187 wp_enqueue_script('jquery');
190 $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
191 $upgrader->bulk_upgrade( $themes );
194 } elseif ( 'install-theme' == $action ) {
196 if ( ! current_user_can('install_themes') )
197 wp_die(__('You do not have sufficient permissions to install themes for this site.'));
199 include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
201 check_admin_referer('install-theme_' . $theme);
202 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
204 if ( is_wp_error($api) )
208 wp_enqueue_script('theme-preview');
209 $title = __('Install Themes');
210 $parent_file = 'themes.php';
211 $submenu_file = 'themes.php';
212 require_once('./admin-header.php');
214 $title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
215 $nonce = 'install-theme_' . $theme;
216 $url = 'update.php?action=install-theme&theme=' . $theme;
217 $type = 'web'; //Install theme type, From Web or an Upload.
219 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
220 $upgrader->install($api->download_link);
222 include('./admin-footer.php');
224 } elseif ( 'upload-theme' == $action ) {
226 if ( ! current_user_can('install_themes') )
227 wp_die(__('You do not have sufficient permissions to install themes for this site.'));
229 check_admin_referer('theme-upload');
231 $file_upload = new File_Upload_Upgrader('themezip', 'package');
233 $title = __('Upload Theme');
234 $parent_file = 'themes.php';
235 $submenu_file = 'theme-install.php';
237 wp_enqueue_script('theme-preview');
238 require_once('./admin-header.php');
240 $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
241 $nonce = 'theme-upload';
242 $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
243 $type = 'upload'; //Install plugin type, From Web or an Upload.
245 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
246 $upgrader->install( $file_upload->package );
248 include('./admin-footer.php');
251 do_action('update-custom_' . $action);