Changeset 11005 for trunk/wp-admin/update.php
- Timestamp:
- 04/19/2009 07:36:28 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/update.php
r10924 r11005 1 1 <?php 2 2 /** 3 * Update Plugin/Theme administration panel.3 * Update/Install Plugin/Theme administration panel. 4 4 * 5 5 * @package WordPress … … 10 10 require_once('admin.php'); 11 11 12 if ( ! current_user_can('update_plugins') ) 13 wp_die(__('You do not have sufficient permissions to update plugins for this blog.')); 14 15 /** 16 * Plugin upgrade display. 17 * 18 * @since 2.5 19 * 20 * @param string $plugin Plugin 21 */ 22 function do_plugin_upgrade($plugin) { 23 global $wp_filesystem; 24 25 $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin"); 26 if ( false === ($credentials = request_filesystem_credentials($url)) ) 27 return; 28 29 if ( ! WP_Filesystem($credentials) ) { 30 $error = true; 31 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() ) 32 $error = $wp_filesystem->errors; 33 request_filesystem_credentials($url, '', $error); //Failed to connect, Error and request again 34 return; 35 } 36 37 echo '<div class="wrap">'; 38 echo screen_icon(); 39 echo '<h2>' . __('Upgrade Plugin') . '</h2>'; 40 if ( $wp_filesystem->errors->get_error_code() ) { 41 foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 42 show_message($message); 43 echo '</div>'; 44 return; 45 } 46 47 $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is 48 49 $result = wp_update_plugin($plugin, 'show_message'); 50 51 if ( is_wp_error($result) ) { 52 show_message($result); 53 show_message( __('Plugin upgrade Failed') ); 54 } else { 55 $plugin_file = $result; 56 show_message( __('Plugin upgraded successfully') ); 57 if( $result && $was_activated ){ 58 show_message(__('Attempting reactivation of the plugin')); 59 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) .'"></iframe>'; 60 } 61 $update_actions = array( 62 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . attribute_escape(__('Activate this plugin')) . '" target="_parent">' . __('Activate Plugin') . '</a>', 63 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . attribute_escape(__('Goto plugins page')) . '" target="_parent">' . __('Return to Plugins page') . '</a>' 64 ); 65 if ( $was_activated ) 66 unset( $update_actions['activate_plugin'] ); 67 68 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $plugin_file); 69 if ( ! empty($update_actions) ) 70 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions)); 71 } 72 echo '</div>'; 73 } 74 75 /** 76 * Theme upgrade display. 77 * 78 * @since 2.5 79 * 80 * @param string $plugin Plugin 81 */ 82 function do_theme_upgrade($theme) { 83 global $wp_filesystem; 84 85 $url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($theme), 'upgrade-theme_' . urlencode($theme)); 86 if ( false === ($credentials = request_filesystem_credentials($url)) ) 87 return; 88 89 if ( ! WP_Filesystem($credentials) ) { 90 $error = true; 91 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() ) 92 $error = $wp_filesystem->errors; 93 request_filesystem_credentials($url, '', $error); //Failed to connect, Error and request again 94 return; 95 } 96 97 echo '<div class="wrap">'; 98 echo screen_icon(); 99 echo '<h2>' . __('Upgrade Theme') . '</h2>'; 100 if ( $wp_filesystem->errors->get_error_code() ) { 101 foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 102 show_message($message); 103 echo '</div>'; 104 return; 105 } 106 107 //TODO: Is theme currently active? 108 $was_current = false; //is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is 109 110 $result = wp_update_theme($theme, 'show_message'); 111 112 if ( is_wp_error($result) ) { 113 show_message($result); 114 show_message( __('Installation Failed') ); 115 } else { 116 //Result is the new plugin file relative to WP_PLUGIN_DIR 117 show_message( __('Theme upgraded successfully') ); 118 if( $result && $was_current ){ 119 show_message(__('Setting theme as Current')); 120 //TODO: Actually set it as active again. 121 //echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>'; 122 } 123 } 124 echo '</div>'; 125 } 12 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 126 13 127 14 if ( isset($_GET['action']) ) { 128 $plugin = isset($_ GET['plugin']) ? trim($_GET['plugin']) : '';15 $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : ''; 129 16 $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : ''; 130 $action = isset($_ GET['action']) ? $_GET['action'] : '';17 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; 131 18 132 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 133 23 check_admin_referer('upgrade-plugin_' . $plugin); 24 134 25 $title = __('Upgrade Plugin'); 135 26 $parent_file = 'plugins.php'; 136 require_once('admin-header.php'); 137 do_plugin_upgrade($plugin); 138 include('admin-footer.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 139 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 140 42 check_admin_referer('activate-plugin_' . $plugin); 141 43 if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) { … … 156 58 } 157 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 = add_query_arg( array( 81 'plugin' => $plugin, 82 'plugin_name' => $api->name . ' ' . $api->version, 83 'download_url' => $api->download_link 84 ), 'update.php?action=install-plugin'); 85 $type = 'web'; //Install plugin type, From Web or an Upload. 86 87 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) ); 88 $upgrader->install($api->download_link); 89 90 include('admin-footer.php'); 91 92 } elseif ( 'upload-plugin' == $action ) { 93 94 if ( ! current_user_can('install_plugins') ) 95 wp_die(__('You do not have sufficient permissions to install plugins for this blog.')); 96 97 check_admin_referer('plugin-upload'); 98 99 $file_upload = new File_Upload_Upgrader('pluginzip', 'package'); 100 101 $title = __('Upload Plugin'); 102 $parent_file = 'plugins.php'; 103 $submenu_file = 'plugin-install.php'; 104 require_once('admin-header.php'); 105 106 $title = sprintf( __('Installing Plugin from uploaded file: %s'), basename( $file_upload->filename ) ); 107 $nonce = 'plugin-upload'; 108 $url = add_query_arg(array('package' => $file_upload->filename ), 'update.php?action=upload-plugin'); 109 $type = 'upload'; //Install plugin type, From Web or an Upload. 110 111 $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) ); 112 $upgrader->install( $file_upload->package ); 113 114 include('admin-footer.php'); 115 158 116 } elseif ( 'upgrade-theme' == $action ) { 117 118 if ( ! current_user_can('update_themes') ) 119 wp_die(__('You do not have sufficient permissions to update themes for this blog.')); 120 159 121 check_admin_referer('upgrade-theme_' . $theme); 122 123 add_thickbox(); 124 wp_enqueue_script('theme-preview'); 160 125 $title = __('Upgrade Theme'); 161 126 $parent_file = 'themes.php'; 162 require_once('admin-header.php'); 163 do_theme_upgrade($theme); 164 include('admin-footer.php'); 127 $submenu_file = 'themes.php'; 128 require_once('admin-header.php'); 129 130 $nonce = 'upgrade-theme_' . $theme; 131 $url = 'update.php?action=upgrade-theme&theme=' . $theme; 132 133 $upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) ); 134 $upgrader->upgrade($theme); 135 136 include('admin-footer.php'); 137 138 } elseif ( 'install-theme' == $action ) { 139 140 if ( ! current_user_can('install_themes') ) 141 wp_die(__('You do not have sufficient permissions to install themes for this blog.')); 142 143 include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api.. 144 145 check_admin_referer('install-theme_' . $theme); 146 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth. 147 148 if ( is_wp_error($api) ) 149 wp_die($api); 150 151 add_thickbox(); 152 wp_enqueue_script('theme-preview'); 153 $title = __('Install Themes'); 154 $parent_file = 'themes.php'; 155 $submenu_file = 'theme-install.php'; 156 require_once('admin-header.php'); 157 158 $title = sprintf( __('Installing theme: %s'), $api->name . ' ' . $api->version ); 159 $nonce = 'install-theme_' . $theme; 160 $url = add_query_arg( array( 161 'theme' => $theme, 162 'theme_name' => $api->name . ' ' . $api->version, 163 'download_url' => $api->download_link 164 ), 'update.php?action=install-theme'); 165 $type = 'web'; //Install theme type, From Web or an Upload. 166 167 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ) ); 168 $upgrader->install($api->download_link); 169 170 include('admin-footer.php'); 171 172 } elseif ( 'upload-theme' == $action ) { 173 174 if ( ! current_user_can('install_themes') ) 175 wp_die(__('You do not have sufficient permissions to install themes for this blog.')); 176 177 check_admin_referer('theme-upload'); 178 179 $file_upload = new File_Upload_Upgrader('themezip', 'package'); 180 181 $title = __('Upload Theme'); 182 $parent_file = 'themes.php'; 183 $submenu_file = 'theme-install.php'; 184 add_thickbox(); 185 wp_enqueue_script('theme-preview'); 186 require_once('admin-header.php'); 187 188 $title = sprintf( __('Installing Theme from uploaded file: %s'), basename( $file_upload->filename ) ); 189 $nonce = 'theme-upload'; 190 $url = add_query_arg(array('package' => $file_upload->filename), 'update.php?action=upload-theme'); 191 $type = 'upload'; //Install plugin type, From Web or an Upload. 192 193 $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact('type', 'title', 'nonce', 'url') ) ); 194 $upgrader->install( $file_upload->package ); 195 196 include('admin-footer.php'); 197 198 } else { 199 do_action('update-custom_' . $action); 165 200 } 166 201 } 167 168 ?>
Note: See TracChangeset
for help on using the changeset viewer.