wp/wp-admin/update.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    10 	define( 'IFRAME_REQUEST', true );
    10 	define( 'IFRAME_REQUEST', true );
    11 
    11 
    12 /** WordPress Administration Bootstrap */
    12 /** WordPress Administration Bootstrap */
    13 require_once( dirname( __FILE__ ) . '/admin.php' );
    13 require_once( dirname( __FILE__ ) . '/admin.php' );
    14 
    14 
    15 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    15 include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    16 
    16 
    17 if ( isset($_GET['action']) ) {
    17 if ( isset($_GET['action']) ) {
    18 	$plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
    18 	$plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
    19 	$theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
    19 	$theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
    20 	$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    20 	$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    35 		$plugins = array_map('urldecode', $plugins);
    35 		$plugins = array_map('urldecode', $plugins);
    36 
    36 
    37 		$url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
    37 		$url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
    38 		$nonce = 'bulk-update-plugins';
    38 		$nonce = 'bulk-update-plugins';
    39 
    39 
    40 		wp_enqueue_script('jquery');
    40 		wp_enqueue_script( 'updates' );
    41 		iframe_header();
    41 		iframe_header();
    42 
    42 
    43 		$upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
    43 		$upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
    44 		$upgrader->bulk_upgrade( $plugins );
    44 		$upgrader->bulk_upgrade( $plugins );
    45 
    45 
    52 		check_admin_referer('upgrade-plugin_' . $plugin);
    52 		check_admin_referer('upgrade-plugin_' . $plugin);
    53 
    53 
    54 		$title = __('Update Plugin');
    54 		$title = __('Update Plugin');
    55 		$parent_file = 'plugins.php';
    55 		$parent_file = 'plugins.php';
    56 		$submenu_file = 'plugins.php';
    56 		$submenu_file = 'plugins.php';
       
    57 
       
    58 		wp_enqueue_script( 'updates' );
    57 		require_once(ABSPATH . 'wp-admin/admin-header.php');
    59 		require_once(ABSPATH . 'wp-admin/admin-header.php');
    58 
    60 
    59 		$nonce = 'upgrade-plugin_' . $plugin;
    61 		$nonce = 'upgrade-plugin_' . $plugin;
    60 		$url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
    62 		$url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
    61 
    63 
    82 		if ( isset($_GET['failure']) ){
    84 		if ( isset($_GET['failure']) ){
    83 			echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
    85 			echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
    84 
    86 
    85 			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 );
    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 );
    86 			@ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
    88 			@ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
    87 			include(WP_PLUGIN_DIR . '/' . $plugin);
    89 			wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
       
    90 			include( WP_PLUGIN_DIR . '/' . $plugin );
    88 		}
    91 		}
    89 		iframe_footer();
    92 		iframe_footer();
    90 	} elseif ( 'install-plugin' == $action ) {
    93 	} elseif ( 'install-plugin' == $action ) {
    91 
    94 
    92 		if ( ! current_user_can('install_plugins') )
    95 		if ( ! current_user_can('install_plugins') )
    93 			wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
    96 			wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
    94 
    97 
    95 		include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
    98 		include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
    96 
    99 
    97 		check_admin_referer('install-plugin_' . $plugin);
   100 		check_admin_referer('install-plugin_' . $plugin);
    98 		$api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
   101 		$api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
    99 
   102 
   100 		if ( is_wp_error($api) )
   103 		if ( is_wp_error($api) )
   118 
   121 
   119 		include(ABSPATH . 'wp-admin/admin-footer.php');
   122 		include(ABSPATH . 'wp-admin/admin-footer.php');
   120 
   123 
   121 	} elseif ( 'upload-plugin' == $action ) {
   124 	} elseif ( 'upload-plugin' == $action ) {
   122 
   125 
   123 		if ( ! current_user_can('install_plugins') )
   126 		if ( ! current_user_can( 'upload_plugins' ) ) {
   124 			wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
   127 			wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
       
   128 		}
   125 
   129 
   126 		check_admin_referer('plugin-upload');
   130 		check_admin_referer('plugin-upload');
   127 
   131 
   128 		$file_upload = new File_Upload_Upgrader('pluginzip', 'package');
   132 		$file_upload = new File_Upload_Upgrader('pluginzip', 'package');
   129 
   133 
   151 			wp_die(__('You do not have sufficient permissions to update themes for this site.'));
   155 			wp_die(__('You do not have sufficient permissions to update themes for this site.'));
   152 
   156 
   153 		check_admin_referer('upgrade-theme_' . $theme);
   157 		check_admin_referer('upgrade-theme_' . $theme);
   154 
   158 
   155 		wp_enqueue_script( 'customize-loader' );
   159 		wp_enqueue_script( 'customize-loader' );
       
   160 		wp_enqueue_script( 'updates' );
   156 
   161 
   157 		$title = __('Update Theme');
   162 		$title = __('Update Theme');
   158 		$parent_file = 'themes.php';
   163 		$parent_file = 'themes.php';
   159 		$submenu_file = 'themes.php';
   164 		$submenu_file = 'themes.php';
   160 		require_once(ABSPATH . 'wp-admin/admin-header.php');
   165 		require_once(ABSPATH . 'wp-admin/admin-header.php');
   182 		$themes = array_map('urldecode', $themes);
   187 		$themes = array_map('urldecode', $themes);
   183 
   188 
   184 		$url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
   189 		$url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
   185 		$nonce = 'bulk-update-themes';
   190 		$nonce = 'bulk-update-themes';
   186 
   191 
   187 		wp_enqueue_script('jquery');
   192 		wp_enqueue_script( 'updates' );
   188 		iframe_header();
   193 		iframe_header();
   189 
   194 
   190 		$upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
   195 		$upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
   191 		$upgrader->bulk_upgrade( $themes );
   196 		$upgrader->bulk_upgrade( $themes );
   192 
   197 
   194 	} elseif ( 'install-theme' == $action ) {
   199 	} elseif ( 'install-theme' == $action ) {
   195 
   200 
   196 		if ( ! current_user_can('install_themes') )
   201 		if ( ! current_user_can('install_themes') )
   197 			wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
   202 			wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
   198 
   203 
   199 		include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
   204 		include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); //for themes_api..
   200 
   205 
   201 		check_admin_referer('install-theme_' . $theme);
   206 		check_admin_referer( 'install-theme_' . $theme );
   202 		$api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
   207 		$api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
   203 
   208 
   204 		if ( is_wp_error($api) )
   209 		if ( is_wp_error($api) )
   205 	 		wp_die($api);
   210 	 		wp_die($api);
   206 
   211 
   221 
   226 
   222 		include(ABSPATH . 'wp-admin/admin-footer.php');
   227 		include(ABSPATH . 'wp-admin/admin-footer.php');
   223 
   228 
   224 	} elseif ( 'upload-theme' == $action ) {
   229 	} elseif ( 'upload-theme' == $action ) {
   225 
   230 
   226 		if ( ! current_user_can('install_themes') )
   231 		if ( ! current_user_can( 'upload_themes' ) ) {
   227 			wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
   232 			wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
       
   233 		}
   228 
   234 
   229 		check_admin_referer('theme-upload');
   235 		check_admin_referer('theme-upload');
   230 
   236 
   231 		$file_upload = new File_Upload_Upgrader('themezip', 'package');
   237 		$file_upload = new File_Upload_Upgrader('themezip', 'package');
   232 
   238 
   250 			$file_upload->cleanup();
   256 			$file_upload->cleanup();
   251 
   257 
   252 		include(ABSPATH . 'wp-admin/admin-footer.php');
   258 		include(ABSPATH . 'wp-admin/admin-footer.php');
   253 
   259 
   254 	} else {
   260 	} else {
   255 		do_action('update-custom_' . $action);
   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}" );
   256 	}
   271 	}
   257 }
   272 }