Make WordPress Core

Changeset 25873


Ignore:
Timestamp:
10/22/2013 09:18:09 PM (11 years ago)
Author:
nacin
Message:

Make some changes to the email templates to account for the fact that an auto update offer might not be to the latest version.

For example, 3.7.2 install is served a 3.7.3 update, but the current version is 3.8.1.

This commit also allows for core update notification emails to be sent even when we are unable to run an auto update due to filesystem configuration (VCS checkout or file permissions). But, since these emails go through WP_Automatic_Updater, they will not be sent if the updater is outright disabled.

fixes #25654.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r25871 r25873  
    16531653         * This filter parallels the AUTOMATIC_UPDATER_DISABLED constant in name.
    16541654         *
     1655         * This also disables update notification emails. That may change in the future.
     1656         *
    16551657         * @since 3.7.0
    16561658         * @param bool $disabled Whether the updater should be disabled.
     
    17291731     */
    17301732    public function should_update( $type, $item, $context ) {
     1733        // Used to see if WP_Filesystem is set up to allow unattended updates.
     1734        $skin = new Automatic_Upgrader_Skin;
     1735
    17311736        if ( $this->is_disabled() )
    17321737            return false;
    17331738
    1734         // Checks to see if WP_Filesystem is set up to allow unattended updates.
    1735         $skin = new Automatic_Upgrader_Skin;
    1736         if ( ! $skin->request_filesystem_credentials( false, $context ) )
     1739        // If we can't do an auto core update, we may still be able to email the user.
     1740        if ( ! $skin->request_filesystem_credentials( false, $context ) || $this->is_vcs_checkout( $context ) ) {
     1741            if ( 'core' == $type )
     1742                $this->notify_core_update( $item );
    17371743            return false;
    1738 
    1739         if ( $this->is_vcs_checkout( $context ) )
    1740             return false;
     1744        }
    17411745
    17421746        // Next up, is this an item we can update?
     
    17661770
    17671771        if ( ! $update ) {
    1768 
    1769             // See if we need to notify users of a core update.
    1770             if ( 'core' == $type && ! empty( $item->notify_email ) ) {
    1771                 $notify      = true;
    1772                 $notified    = get_site_option( 'auto_core_update_notified' );
    1773 
    1774                 // Don't notify if we've already notified the same email address of the same version.
    1775                 if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current )
    1776                     return false;
    1777 
    1778                 $this->send_email( 'manual', $item );
    1779             }
    1780 
     1772            if ( 'core' == $type )
     1773                $this->notify_core_update( $item );
    17811774            return false;
    17821775        }
     
    17961789        }
    17971790
     1791        return true;
     1792    }
     1793
     1794    /**
     1795     * Notifies an administrator of a core update.
     1796     *
     1797     * @since 3.7.0
     1798     *
     1799     * @param object $item The update offer.
     1800     */
     1801    protected function notify_core_update( $item ) {
     1802        // See if we need to notify users of a core update.
     1803        if ( empty( $item->notify_email ) )
     1804            return false;
     1805
     1806        $notify   = true;
     1807        $notified = get_site_option( 'auto_core_update_notified' );
     1808
     1809        // Don't notify if we've already notified the same email address of the same version.
     1810        if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current )
     1811            return false;
     1812
     1813        $this->send_email( 'manual', $item );
    17981814        return true;
    17991815    }
     
    18911907        global $wpdb, $wp_version;
    18921908
     1909        if ( $this->is_disabled() )
     1910            return;
     1911
    18931912        if ( ! is_main_network() || ! is_main_site() )
    18941913            return;
     
    20832102     * @since 3.7.0
    20842103     *
    2085      * @param string $type        The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
     2104     * @param string $type        The type of email to send. Can be one of 'success', 'fail', 'manual', 'critical'.
    20862105     * @param object $core_update The update offer that was attempted.
    20872106     * @param mixed  $result      Optional. The result for the core update. Can be WP_Error.
     
    20952114        ) );
    20962115
     2116        $next_user_core_update = get_preferred_from_update_core();
     2117        // If the update transient is empty, use the update we just performed
     2118        if ( ! $next_user_core_update )
     2119            $next_user_core_update = $core_update;
     2120        $newer_version_available = ( 'upgrade' == $next_user_core_update->response && version_compare( $next_user_core_update->version, $core_update, '>' ) );
     2121
     2122        $newer_version_available = true;
     2123        $next_user_core_update->version = $next_user_core_update->current = '3.8.1';
    20972124        /**
    20982125         * Filter whether to send an email following an automatic background core update.
     
    21292156        }
    21302157
    2131         $subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $core_update->current );
     2158        // If the auto update is not to the latest version, say that the current version of WP is available instead.
     2159        $version = 'success' === $type ? $core_update->current : $next_user_core_update->current;
     2160        $subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $version );
    21322161
    21332162        $body = '';
     
    21362165            case 'success' :
    21372166                $body .= sprintf( __( 'Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.' ), home_url(), $core_update->current );
    2138                 $body .= "\n\n" . __( 'No further action is needed on your part.' );
     2167                $body .= "\n\n";
     2168                if ( ! $newer_version_available )
     2169                    $body .= __( 'No further action is needed on your part.' ) . ' ';
    21392170
    21402171                // Can only reference the About screen if their update was successful.
    21412172                list( $about_version ) = explode( '-', $core_update->current, 2 );
    2142                 $body .= ' ' . sprintf( __( "For more on version %s, see the About WordPress screen:" ), $about_version );
     2173                $body .= sprintf( __( "For more on version %s, see the About WordPress screen:" ), $about_version );
    21432174                $body .= "\n" . admin_url( 'about.php' );
     2175
     2176                if ( $newer_version_available ) {
     2177                    $body .= "\n\n" . sprintf( __( 'WordPress %s is also now available.' ), $next_user_core_update->current ) . ' ';
     2178                    $body .= __( 'Updating is easy and only takes a few moments:' );
     2179                    $body .= "\n" . network_admin_url( 'update-core.php' );
     2180                }
     2181
    21442182                break;
    21452183
    21462184            case 'fail' :
    21472185            case 'manual' :
    2148                 $body .= sprintf( __( 'Please update your site at %1$s to WordPress %2$s.' ), home_url(), $core_update->current );
     2186                $body .= sprintf( __( 'Please update your site at %1$s to WordPress %2$s.' ), home_url(), $next_user_core_update->current );
    21492187
    21502188                $body .= "\n\n";
    2151                 if ( 'fail' == $type )
     2189
     2190                // Don't show this message if there is a newer version available.
     2191                // Potential for confusion, and also not useful for them to know at this point.
     2192                if ( 'fail' == $type && ! $newer_version_available )
    21522193                    $body .= __( 'We tried but were unable to update your site automatically.' ) . ' ';
     2194
    21532195                $body .= __( 'Updating is easy and only takes a few moments:' );
    21542196                $body .= "\n" . network_admin_url( 'update-core.php' );
     
    21562198
    21572199            case 'critical' :
    2158                 $body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update to the latest version of WordPress, %2$s.' ), home_url(), $core_update->current );
     2200                if ( $newer_version_available )
     2201                    $body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update WordPress to version %2$s.' ), home_url(), $core_update->current );
     2202                else
     2203                    $body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update to the latest version of WordPress, %2$s.' ), home_url(), $core_update->current );
    21592204
    21602205                $body .= "\n\n" . __( "This means your site may be offline or broken. Don't panic; this can be fixed." );
     
    21662211
    21672212        // Updates are important!
    2168         if ( $type != 'success' )
     2213        if ( $type != 'success' || $newer_version_available )
    21692214            $body .= "\n\n" . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' );
    21702215
     
    21732218        $body .= "\n" . __( 'http://wordpress.org/support/' );
    21742219
    2175         // If things are successful, mention plugins and themes if any are out of date.
    2176         if ( $type == 'success' && ( get_plugin_updates() || get_theme_updates() ) ) {
     2220        // If things are successful and we're now on the latest, mention plugins and themes if any are out of date.
     2221        if ( $type == 'success' && ! $newer_version_available && ( get_plugin_updates() || get_theme_updates() ) ) {
    21772222            $body .= "\n\n" . __( 'You also have some plugins or themes with updates available. Update them now:' );
    21782223            $body .= "\n" . network_admin_url();
     
    21832228        if ( 'critical' == $type && is_wp_error( $result ) ) {
    21842229            $body .= "\n***\n\n";
    2185             $body .= __( 'We have some data that describes the error your site encountered.' );
     2230            $body .= sprintf( __( 'Your site was running version %s.' ), $GLOBALS['wp_version'] );
     2231            $body .= ' ' . __( 'We have some data that describes the error your site encountered.' );
    21862232            $body .= ' ' . __( 'Your hosting company, support forum volunteers, or a friendly developer may be able to use this information to help you:' );
    21872233
  • trunk/src/wp-includes/update.php

    r25841 r25873  
    416416
    417417    $upgrader = new WP_Automatic_Updater;
    418     if ( $upgrader->is_disabled() )
    419         return;
    420 
    421418    $upgrader->run();
    422419}
Note: See TracChangeset for help on using the changeset viewer.