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 ( 'upgrade-plugin' == $action ) {
20 if ( ! current_user_can('update_plugins') )
21 wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
23 check_admin_referer('upgrade-plugin_' . $plugin);
25 $title = __('Upgrade Plugin');
26 $parent_file = 'plugins.php';
27 $submenu_file = 'plugins.php';
28 require_once('admin-header.php');
30 $nonce = 'upgrade-plugin_' . $plugin;
31 $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
33 $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
34 $upgrader->upgrade($plugin);
36 include('admin-footer.php');
38 } elseif ('activate-plugin' == $action ) {
39 if ( ! current_user_can('update_plugins') )
40 wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
42 check_admin_referer('activate-plugin_' . $plugin);
43 if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
44 wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
45 activate_plugin($plugin);
46 wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
49 iframe_header( __('Plugin Reactivation'), true );
50 if( isset($_GET['success']) )
51 echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
53 if( isset($_GET['failure']) ){
54 echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
56 if ( defined('E_RECOVERABLE_ERROR') )
57 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
59 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
61 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
62 include(WP_PLUGIN_DIR . '/' . $plugin);
65 } elseif ( 'install-plugin' == $action ) {
67 if ( ! current_user_can('install_plugins') )
68 wp_die(__('You do not have sufficient permissions to install plugins for this blog.'));
70 include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
72 check_admin_referer('install-plugin_' . $plugin);
73 $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
75 if ( is_wp_error($api) )
78 $title = __('Plugin Install');
79 $parent_file = 'plugins.php';
80 $submenu_file = 'plugin-install.php';
81 require_once('admin-header.php');
83 $title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
84 $nonce = 'install-plugin_' . $plugin;
85 $url = 'update.php?action=install-plugin&plugin=' . $plugin;
86 $type = 'web'; //Install plugin type, From Web or an Upload.
88 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
89 $upgrader->install($api->download_link);
91 include('admin-footer.php');
93 } elseif ( 'upload-plugin' == $action ) {
95 if ( ! current_user_can('install_plugins') )
96 wp_die(__('You do not have sufficient permissions to install plugins for this blog.'));
98 check_admin_referer('plugin-upload');
100 $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
102 $title = __('Upload Plugin');
103 $parent_file = 'plugins.php';
104 $submenu_file = 'plugin-install.php';
105 require_once('admin-header.php');
107 $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
108 $nonce = 'plugin-upload';
109 $url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin');
110 $type = 'upload'; //Install plugin type, From Web or an Upload.
112 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
113 $upgrader->install( $file_upload->package );
115 include('admin-footer.php');
117 } elseif ( 'upgrade-theme' == $action ) {
119 if ( ! current_user_can('update_themes') )
120 wp_die(__('You do not have sufficient permissions to update themes for this blog.'));
122 check_admin_referer('upgrade-theme_' . $theme);
125 wp_enqueue_script('theme-preview');
126 $title = __('Upgrade Theme');
127 $parent_file = 'themes.php';
128 $submenu_file = 'themes.php';
129 require_once('admin-header.php');
131 $nonce = 'upgrade-theme_' . $theme;
132 $url = 'update.php?action=upgrade-theme&theme=' . $theme;
134 $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
135 $upgrader->upgrade($theme);
137 include('admin-footer.php');
139 } elseif ( 'install-theme' == $action ) {
141 if ( ! current_user_can('install_themes') )
142 wp_die(__('You do not have sufficient permissions to install themes for this blog.'));
144 include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
146 check_admin_referer('install-theme_' . $theme);
147 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
149 if ( is_wp_error($api) )
153 wp_enqueue_script('theme-preview');
154 $title = __('Install Themes');
155 $parent_file = 'themes.php';
156 $submenu_file = 'theme-install.php';
157 require_once('admin-header.php');
159 $title = sprintf( __('Installing theme: %s'), $api->name . ' ' . $api->version );
160 $nonce = 'install-theme_' . $theme;
161 $url = 'update.php?action=install-theme&theme=' . $theme;
162 $type = 'web'; //Install theme type, From Web or an Upload.
164 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
165 $upgrader->install($api->download_link);
167 include('admin-footer.php');
169 } elseif ( 'upload-theme' == $action ) {
171 if ( ! current_user_can('install_themes') )
172 wp_die(__('You do not have sufficient permissions to install themes for this blog.'));
174 check_admin_referer('theme-upload');
176 $file_upload = new File_Upload_Upgrader('themezip', 'package');
178 $title = __('Upload Theme');
179 $parent_file = 'themes.php';
180 $submenu_file = 'theme-install.php';
182 wp_enqueue_script('theme-preview');
183 require_once('admin-header.php');
185 $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
186 $nonce = 'theme-upload';
187 $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
188 $type = 'upload'; //Install plugin type, From Web or an Upload.
190 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
191 $upgrader->install( $file_upload->package );
193 include('admin-footer.php');
196 do_action('update-custom_' . $action);