web/wp-admin/update.php
branchwordpress
changeset 109 03b0d1493584
child 132 4d4862461b8d
equal deleted inserted replaced
-1:000000000000 109:03b0d1493584
       
     1 <?php
       
     2 /**
       
     3  * Update/Install Plugin/Theme administration panel.
       
     4  *
       
     5  * @package WordPress
       
     6  * @subpackage Administration
       
     7  */
       
     8 
       
     9 /** WordPress Administration Bootstrap */
       
    10 require_once('admin.php');
       
    11 
       
    12 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
       
    13 
       
    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'] : '';
       
    18 
       
    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.'));
       
    22 
       
    23 		check_admin_referer('upgrade-plugin_' . $plugin);
       
    24 
       
    25 		$title = __('Upgrade Plugin');
       
    26 		$parent_file = 'plugins.php';
       
    27 		$submenu_file = 'plugins.php';
       
    28 		require_once('admin-header.php');
       
    29 
       
    30 		$nonce = 'upgrade-plugin_' . $plugin;
       
    31 		$url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
       
    32 
       
    33 		$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
       
    34 		$upgrader->upgrade($plugin);
       
    35 
       
    36 		include('admin-footer.php');
       
    37 
       
    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.'));
       
    41 
       
    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'] );
       
    47 			die();
       
    48 		}
       
    49 		iframe_header( __('Plugin Reactivation'), true );
       
    50 		if( isset($_GET['success']) )
       
    51 			echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
       
    52 
       
    53 		if( isset($_GET['failure']) ){
       
    54 			echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
       
    55 			error_reporting( E_ALL ^ E_NOTICE );
       
    56 			@ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
       
    57 			include(WP_PLUGIN_DIR . '/' . $plugin);
       
    58 		}
       
    59 		iframe_footer();
       
    60 	} elseif ( 'install-plugin' == $action ) {
       
    61 
       
    62 		if ( ! current_user_can('install_plugins') )
       
    63 			wp_die(__('You do not have sufficient permissions to install plugins for this blog.'));
       
    64 
       
    65 		include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api..
       
    66 
       
    67 		check_admin_referer('install-plugin_' . $plugin);
       
    68 		$api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
       
    69 
       
    70 		if ( is_wp_error($api) )
       
    71 	 		wp_die($api);
       
    72 
       
    73 		$title = __('Plugin Install');
       
    74 		$parent_file = 'plugins.php';
       
    75 		$submenu_file = 'plugin-install.php';
       
    76 		require_once('admin-header.php');
       
    77 
       
    78 		$title = sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version );
       
    79 		$nonce = 'install-plugin_' . $plugin;
       
    80 		$url = 'update.php?action=install-plugin&plugin=' . $plugin;
       
    81 		$type = 'web'; //Install plugin type, From Web or an Upload.
       
    82 
       
    83 		$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
       
    84 		$upgrader->install($api->download_link);
       
    85 
       
    86 		include('admin-footer.php');
       
    87 
       
    88 	} elseif ( 'upload-plugin' == $action ) {
       
    89 
       
    90 		if ( ! current_user_can('install_plugins') )
       
    91 			wp_die(__('You do not have sufficient permissions to install plugins for this blog.'));
       
    92 
       
    93 		check_admin_referer('plugin-upload');
       
    94 
       
    95 		$file_upload = new File_Upload_Upgrader('pluginzip', 'package');
       
    96 
       
    97 		$title = __('Upload Plugin');
       
    98 		$parent_file = 'plugins.php';
       
    99 		$submenu_file = 'plugin-install.php';
       
   100 		require_once('admin-header.php');
       
   101 
       
   102 		$title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) );
       
   103 		$nonce = 'plugin-upload';
       
   104 		$url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin');
       
   105 		$type = 'upload'; //Install plugin type, From Web or an Upload.
       
   106 
       
   107 		$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
       
   108 		$upgrader->install( $file_upload->package );
       
   109 
       
   110 		include('admin-footer.php');
       
   111 
       
   112 	} elseif ( 'upgrade-theme' == $action ) {
       
   113 
       
   114 		if ( ! current_user_can('update_themes') )
       
   115 			wp_die(__('You do not have sufficient permissions to update themes for this blog.'));
       
   116 
       
   117 		check_admin_referer('upgrade-theme_' . $theme);
       
   118 
       
   119 		add_thickbox();
       
   120 		wp_enqueue_script('theme-preview');
       
   121 		$title = __('Upgrade Theme');
       
   122 		$parent_file = 'themes.php';
       
   123 		$submenu_file = 'themes.php';
       
   124 		require_once('admin-header.php');
       
   125 
       
   126 		$nonce = 'upgrade-theme_' . $theme;
       
   127 		$url = 'update.php?action=upgrade-theme&theme=' . $theme;
       
   128 
       
   129 		$upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
       
   130 		$upgrader->upgrade($theme);
       
   131 
       
   132 		include('admin-footer.php');
       
   133 
       
   134 	} elseif ( 'install-theme' == $action ) {
       
   135 
       
   136 		if ( ! current_user_can('install_themes') )
       
   137 			wp_die(__('You do not have sufficient permissions to install themes for this blog.'));
       
   138 
       
   139 		include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api..
       
   140 
       
   141 		check_admin_referer('install-theme_' . $theme);
       
   142 		$api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
       
   143 
       
   144 		if ( is_wp_error($api) )
       
   145 	 		wp_die($api);
       
   146 
       
   147 		add_thickbox();
       
   148 		wp_enqueue_script('theme-preview');
       
   149 		$title = __('Install Themes');
       
   150 		$parent_file = 'themes.php';
       
   151 		$submenu_file = 'theme-install.php';
       
   152 		require_once('admin-header.php');
       
   153 
       
   154 		$title = sprintf( __('Installing theme: %s'), $api->name . ' ' . $api->version );
       
   155 		$nonce = 'install-theme_' . $theme;
       
   156 		$url = 'update.php?action=install-theme&theme=' . $theme;
       
   157 		$type = 'web'; //Install theme type, From Web or an Upload.
       
   158 
       
   159 		$upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) );
       
   160 		$upgrader->install($api->download_link);
       
   161 
       
   162 		include('admin-footer.php');
       
   163 
       
   164 	} elseif ( 'upload-theme' == $action ) {
       
   165 
       
   166 		if ( ! current_user_can('install_themes') )
       
   167 			wp_die(__('You do not have sufficient permissions to install themes for this blog.'));
       
   168 
       
   169 		check_admin_referer('theme-upload');
       
   170 
       
   171 		$file_upload = new File_Upload_Upgrader('themezip', 'package');
       
   172 
       
   173 		$title = __('Upload Theme');
       
   174 		$parent_file = 'themes.php';
       
   175 		$submenu_file = 'theme-install.php';
       
   176 		add_thickbox();
       
   177 		wp_enqueue_script('theme-preview');
       
   178 		require_once('admin-header.php');
       
   179 
       
   180 		$title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) );
       
   181 		$nonce = 'theme-upload';
       
   182 		$url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme');
       
   183 		$type = 'upload'; //Install plugin type, From Web or an Upload.
       
   184 
       
   185 		$upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) );
       
   186 		$upgrader->install( $file_upload->package );
       
   187 
       
   188 		include('admin-footer.php');
       
   189 
       
   190 	} else {
       
   191 		do_action('update-custom_' . $action);
       
   192 	}
       
   193 }