diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php index 4343c6c1ba..1debecdc53 100644 --- a/wp-admin/includes/update.php +++ b/wp-admin/includes/update.php @@ -8,11 +8,79 @@ // The admin side of our 1.1 update system +/** + * Selects the first update version from the update_core option + * + * @return object the response from the API + */ +function get_preferred_from_update_core() { + $updates = get_core_updates(); + if ( !is_array( $updates ) ) + return false; + if ( empty( $updates ) ) + return (object)array('response' => 'latest'); + return $updates[0]; +} + +/** + * Get available core updates + * + * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too, + * set $options['available'] to false to skip not-dimissed updates. + * @return array Array of the update objects + */ +function get_core_updates( $options = array() ) { + $options = array_merge( array('available' => true, 'dismissed' => false ), $options ); + $dismissed = get_option( 'dismissed_update_core' ); + if ( !is_array( $dismissed ) ) $dismissed = array(); + $from_api = get_option( 'update_core' ); + if ( !is_array( $from_api ) ) return false; + $result = array(); + foreach($from_api as $update) { + if ( array_key_exists( $update->current.'|'.$update->locale, $dismissed ) ) { + if ( $options['dismissed'] ) { + $update->dismissed = true; + $result[]= $update; + } + } else { + if ( $options['available'] ) { + $update->dismissed = false; + $result[]= $update; + } + } + } + return $result; +} + +function dismiss_core_update( $update ) { + $dismissed = get_option( 'dismissed_update_core' ); + $dismissed[ $update->current.'|'.$update->locale ] = true; + return update_option( 'dismissed_update_core', $dismissed ); +} + +function undismiss_core_update( $version, $locale ) { + $dismissed = get_option( 'dismissed_update_core' ); + $key = $version.'|'.$locale; + if ( !isset( $dismissed[$key] ) ) return false; + unset( $dismissed[$key] ); + return update_option( 'dismissed_update_core', $dismissed ); +} + +function find_core_update( $version, $locale ) { + $from_api = get_option( 'update_core' ); + if ( !is_array( $from_api ) ) return false; + foreach($from_api as $update) { + if ( $update->current == $version && $update->locale == $locale ) + return $update; + } + return false; +} + function core_update_footer( $msg = '' ) { if ( !current_user_can('manage_options') ) return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] ); - $cur = get_option( 'update_core' ); + $cur = get_preferred_from_update_core(); if ( ! isset( $cur->current ) ) $cur->current = ''; @@ -39,7 +107,7 @@ function core_update_footer( $msg = '' ) { add_filter( 'update_footer', 'core_update_footer' ); function update_nag() { - $cur = get_option( 'update_core' ); + $cur = get_preferred_from_update_core(); if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) return false; @@ -55,7 +123,7 @@ function update_nag() { // Called directly from dashboard function update_right_now_message() { - $cur = get_option( 'update_core' ); + $cur = get_preferred_from_update_core(); $msg = sprintf( __('You are using WordPress %s.'), $GLOBALS['wp_version'] ); if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') ) @@ -320,7 +388,7 @@ function wp_update_theme($theme, $feedback = '') { } -function wp_update_core($feedback = '') { +function wp_update_core($current, $feedback = '') { global $wp_filesystem; @set_time_limit( 300 ); @@ -329,7 +397,6 @@ function wp_update_core($feedback = '') { add_filter('update_feedback', $feedback); // Is an update available? - $current = get_option( 'update_core' ); if ( !isset( $current->response ) || $current->response == 'latest' ) return new WP_Error('up_to_date', __('WordPress is at the latest version.')); diff --git a/wp-admin/menu.php b/wp-admin/menu.php index 23e6982b5e..ddf69e0727 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -86,6 +86,7 @@ $menu[45] = array( __('Tools'), 'manage_options', 'import.php', '', '', 'menu-to $submenu['import.php'][10] = array( __('Export'), 'import', 'export.php' ); if ( ! $is_opera ) $submenu['import.php'][20] = array( __('Turbo'), 'read', 'turbo.php' ); + $submenu['import.php'][30] = array( __('Update'), 'read', wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core')); $menu[50] = array( __('Settings'), 'manage_options', 'options-general.php', '', 'menu-top-last', 'menu-settings', 'images/menu/settings.png' ); $submenu['options-general.php'][10] = array(__('General'), 'manage_options', 'options-general.php'); diff --git a/wp-admin/update.php b/wp-admin/update.php index 5f5846a24c..4ecb837175 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -122,6 +122,64 @@ function do_theme_upgrade($theme) { echo ''; } +function list_core_update( $update ) { + $version_string = 'en_US' == $update->locale? + $update->current : sprintf("%s–%s", $update->current, $update->locale); + if ( 'development' == $update->response ) { + $message = __('You are using a development version of WordPress. You can upgrade to the latest nightly build automatically or download the nightly build and install it manually:'); + $submit = __('Download nightly build'); + } else { + $message = sprintf(__('You can upgrade to version %s automatically or download the package and install it manually:'), $version_string); + $submit = sprintf(__('Download %s'), $version_string); + } + + echo '
'; + echo $message; + echo '
'; + echo ''; + +} + +function dismissed_updates() { + $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) ); + if ( $dismissed ) { + + $show_text = js_escape(__('Show hidden updates')); + $hide_text = js_escape(__('Hide hidden updates')); + ?> + + '.__('Show hidden updates').''; + echo ''; - _e('A new version of WordPress is available for upgrade. Before upgrading, please backup your database and files.'); - echo '
'; - - if ( 'development' == $update->response ) { - $message = __('You are using a development version of WordPress. You can upgrade to the latest nightly build automatically or download the nightly build and install it manually. Which would you like to do?'); - $submit = __('Download nightly build'); - } else { - $message = sprintf(__('You can upgrade to version %s automatically or download the package and install it manually. Which would you like to do?'), $update->current); - $submit = sprintf(__('Download %s'), $update->current); + echo ''; + _e('Important: before upgrading, please backup your database and files.'); + echo '
'; - echo $message; - echo '
'; - echo '