PageRenderTime 39ms CodeModel.GetById 10ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/wp-admin/update.php

https://gitlab.com/webteam/job_aag
PHP | 272 lines | 179 code | 77 blank | 16 comment | 37 complexity | 86b7431cd724423305464f6c19608838 MD5 | raw file
  1<?php
  2/**
  3 * Update/Install Plugin/Theme administration panel.
  4 *
  5 * @package WordPress
  6 * @subpackage Administration
  7 */
  8
  9if ( ! defined( 'IFRAME_REQUEST' ) && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'update-selected', 'activate-plugin', 'update-selected-themes' ) ) )
 10	define( 'IFRAME_REQUEST', true );
 11
 12/** WordPress Administration Bootstrap */
 13require_once( dirname( __FILE__ ) . '/admin.php' );
 14
 15include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
 16
 17if ( 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'] : '';
 21
 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.' ) );
 25
 26		check_admin_referer( 'bulk-update-plugins' );
 27
 28		if ( isset( $_GET['plugins'] ) )
 29			$plugins = explode( ',', stripslashes($_GET['plugins']) );
 30		elseif ( isset( $_POST['checked'] ) )
 31			$plugins = (array) $_POST['checked'];
 32		else
 33			$plugins = array();
 34
 35		$plugins = array_map('urldecode', $plugins);
 36
 37		$url = 'update.php?action=update-selected&amp;plugins=' . urlencode(implode(',', $plugins));
 38		$nonce = 'bulk-update-plugins';
 39
 40		wp_enqueue_script( 'updates' );
 41		iframe_header();
 42
 43		$upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
 44		$upgrader->bulk_upgrade( $plugins );
 45
 46		iframe_footer();
 47
 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.'));
 51
 52		check_admin_referer('upgrade-plugin_' . $plugin);
 53
 54		$title = __('Update Plugin');
 55		$parent_file = 'plugins.php';
 56		$submenu_file = 'plugins.php';
 57
 58		wp_enqueue_script( 'updates' );
 59		require_once(ABSPATH . 'wp-admin/admin-header.php');
 60
 61		$nonce = 'upgrade-plugin_' . $plugin;
 62		$url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
 63
 64		$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
 65		$upgrader->upgrade($plugin);
 66
 67		include(ABSPATH . 'wp-admin/admin-footer.php');
 68
 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.'));
 72
 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']) );
 78			die();
 79		}
 80		iframe_header( __('Plugin Reactivation'), true );
 81		if ( isset($_GET['success']) )
 82			echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
 83
 84		if ( isset($_GET['failure']) ){
 85			echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
 86
 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 );
 91		}
 92		iframe_footer();
 93	} elseif ( 'install-plugin' == $action ) {
 94
 95		if ( ! current_user_can('install_plugins') )
 96			wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
 97
 98		include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
 99
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.
102
103		if ( is_wp_error($api) )
104	 		wp_die($api);
105
106		$title = __('Plugin Install');
107		$parent_file = 'plugins.php';
108		$submenu_file = 'plugin-install.php';
109		require_once(ABSPATH . 'wp-admin/admin-header.php');
110
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']));
116
117		$type = 'web'; //Install plugin type, From Web or an Upload.
118
119		$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
120		$upgrader->install($api->download_link);
121
122		include(ABSPATH . 'wp-admin/admin-footer.php');
123
124	} elseif ( 'upload-plugin' == $action ) {
125
126		if ( ! current_user_can( 'upload_plugins' ) ) {
127			wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
128		}
129
130		check_admin_referer('plugin-upload');
131
132		$file_upload = new File_Upload_Upgrader('pluginzip', 'package');
133
134		$title = __('Upload Plugin');
135		$parent_file = 'plugins.php';
136		$submenu_file = 'plugin-install.php';
137		require_once(ABSPATH . 'wp-admin/admin-header.php');
138
139		$title = sprintf( __('Installing Plugin from uploaded file: %s'), esc_html( basename( $file_upload->filename ) ) );
140		$nonce = 'plugin-upload';
141		$url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-plugin');
142		$type = 'upload'; //Install plugin type, From Web or an Upload.
143
144		$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
145		$result = $upgrader->install( $file_upload->package );
146
147		if ( $result || is_wp_error($result) )
148			$file_upload->cleanup();
149
150		include(ABSPATH . 'wp-admin/admin-footer.php');
151
152	} elseif ( 'upgrade-theme' == $action ) {
153
154		if ( ! current_user_can('update_themes') )
155			wp_die(__('You do not have sufficient permissions to update themes for this site.'));
156
157		check_admin_referer('upgrade-theme_' . $theme);
158
159		wp_enqueue_script( 'customize-loader' );
160		wp_enqueue_script( 'updates' );
161
162		$title = __('Update Theme');
163		$parent_file = 'themes.php';
164		$submenu_file = 'themes.php';
165		require_once(ABSPATH . 'wp-admin/admin-header.php');
166
167		$nonce = 'upgrade-theme_' . $theme;
168		$url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
169
170		$upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
171		$upgrader->upgrade($theme);
172
173		include(ABSPATH . 'wp-admin/admin-footer.php');
174	} elseif ( 'update-selected-themes' == $action ) {
175		if ( ! current_user_can( 'update_themes' ) )
176			wp_die( __( 'You do not have sufficient permissions to update themes for this site.' ) );
177
178		check_admin_referer( 'bulk-update-themes' );
179
180		if ( isset( $_GET['themes'] ) )
181			$themes = explode( ',', stripslashes($_GET['themes']) );
182		elseif ( isset( $_POST['checked'] ) )
183			$themes = (array) $_POST['checked'];
184		else
185			$themes = array();
186
187		$themes = array_map('urldecode', $themes);
188
189		$url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
190		$nonce = 'bulk-update-themes';
191
192		wp_enqueue_script( 'updates' );
193		iframe_header();
194
195		$upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
196		$upgrader->bulk_upgrade( $themes );
197
198		iframe_footer();
199	} elseif ( 'install-theme' == $action ) {
200
201		if ( ! current_user_can('install_themes') )
202			wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
203
204		include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); //for themes_api..
205
206		check_admin_referer( 'install-theme_' . $theme );
207		$api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
208
209		if ( is_wp_error($api) )
210	 		wp_die($api);
211
212		wp_enqueue_script( 'customize-loader' );
213
214		$title = __('Install Themes');
215		$parent_file = 'themes.php';
216		$submenu_file = 'themes.php';
217		require_once(ABSPATH . 'wp-admin/admin-header.php');
218
219		$title = sprintf( __('Installing Theme: %s'), $api->name . ' ' . $api->version );
220		$nonce = 'install-theme_' . $theme;
221		$url = 'update.php?action=install-theme&theme=' . urlencode( $theme );
222		$type = 'web'; //Install theme type, From Web or an Upload.
223
224		$upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
225		$upgrader->install($api->download_link);
226
227		include(ABSPATH . 'wp-admin/admin-footer.php');
228
229	} elseif ( 'upload-theme' == $action ) {
230
231		if ( ! current_user_can( 'upload_themes' ) ) {
232			wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
233		}
234
235		check_admin_referer('theme-upload');
236
237		$file_upload = new File_Upload_Upgrader('themezip', 'package');
238
239		wp_enqueue_script( 'customize-loader' );
240
241		$title = __('Upload Theme');
242		$parent_file = 'themes.php';
243		$submenu_file = 'theme-install.php';
244
245		require_once(ABSPATH . 'wp-admin/admin-header.php');
246
247		$title = sprintf( __('Installing Theme from uploaded file: %s'), esc_html( basename( $file_upload->filename ) ) );
248		$nonce = 'theme-upload';
249		$url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-theme');
250		$type = 'upload'; //Install plugin type, From Web or an Upload.
251
252		$upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
253		$result = $upgrader->install( $file_upload->package );
254
255		if ( $result || is_wp_error($result) )
256			$file_upload->cleanup();
257
258		include(ABSPATH . 'wp-admin/admin-footer.php');
259
260	} else {
261		/**
262		 * Fires when a custom plugin or theme update request is received.
263		 *
264		 * The dynamic portion of the hook name, `$action`, refers to the action
265		 * provided in the request for wp-admin/update.php. Can be used to
266		 * provide custom update functionality for themes and plugins.
267		 *
268		 * @since 2.8.0
269		 */
270		do_action( "update-custom_{$action}" );
271	}
272}