Make WordPress Core

Ticket #25654: 25654.2.diff

File 25654.2.diff, 8.0 KB (added by nacin, 11 years ago)
  • wp-admin/includes/class-wp-upgrader.php

     
    16911691         *                        should be checked.
    16921692         */
    16931693        public function should_update( $type, $item, $context ) {
    1694                 if ( $this->is_disabled() )
    1695                         return false;
    1696 
    1697                 // Checks to see if WP_Filesystem is set up to allow unattended updates.
     1694                // Used to see if WP_Filesystem is set up to allow unattended updates.
    16981695                $skin = new Automatic_Upgrader_Skin;
    1699                 if ( ! $skin->request_filesystem_credentials( false, $context ) )
    1700                         return false;
    17011696
    1702                 if ( $this->is_vcs_checkout( $context ) )
     1697                if ( $this->is_disabled() || ! $skin->request_filesystem_credentials( false, $context ) || $this->is_vcs_checkout( $context ) ) {
     1698                        if ( 'core' == $type )
     1699                                $this->notify_core_update( $item );
    17031700                        return false;
     1701                }
    17041702
    17051703                // Next up, is this an item we can update?
    17061704                if ( 'core' == $type )
     
    17281726                $update = apply_filters( 'auto_update_' . $type, $update, $item );
    17291727
    17301728                if ( ! $update ) {
    1731 
    1732                         // See if we need to notify users of a core update.
    1733                         if ( 'core' == $type && ! empty( $item->notify_email ) ) {
    1734                                 $notify      = true;
    1735                                 $notified    = get_site_option( 'auto_core_update_notified' );
    1736 
    1737                                 // Don't notify if we've already notified the same email address of the same version.
    1738                                 if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current )
    1739                                         return false;
    1740 
    1741                                 $this->send_email( 'manual', $item );
    1742                         }
    1743 
     1729                        if ( 'core' == $type )
     1730                                $this->notify_core_update( $item );
    17441731                        return false;
    17451732                }
    17461733
     
    17621749        }
    17631750
    17641751        /**
     1752         * Notifies an administrator of a core update.
     1753         *
     1754         * @since 3.7.0
     1755         *
     1756         * @param object $item The update offer.
     1757         */
     1758        protected function notify_core_update( $core_update ) {
     1759                // See if we need to notify users of a core update.
     1760                if ( empty( $item->notify_email ) )
     1761                        return false;
     1762
     1763                $notify   = true;
     1764                $notified = get_site_option( 'auto_core_update_notified' );
     1765
     1766                // Don't notify if we've already notified the same email address of the same version.
     1767                if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current )
     1768                        return false;
     1769
     1770                $this->send_email( 'manual', $item );
     1771                return true;
     1772        }
     1773
     1774        /**
    17651775         * Update an item, if appropriate.
    17661776         *
    17671777         * @since 3.7.0
     
    20612071         *
    20622072         * @since 3.7.0
    20632073         *
    2064          * @param string $type        The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
     2074         * @param string $type        The type of email to send. Can be one of 'success', 'fail', 'manual', 'critical'.
    20652075         * @param object $core_update The update offer that was attempted.
    20662076         * @param mixed  $result      Optional. The result for the core update. Can be WP_Error.
    20672077         */
    2068         protected function send_email( $type, $core_update, $result = null ) {
     2078        public function send_email( $type, $core_update, $result = null ) {
    20692079                update_site_option( 'auto_core_update_notified', array(
    20702080                        'type'      => $type,
    20712081                        'email'     => get_site_option( 'admin_email' ),
     
    20732083                        'timestamp' => time(),
    20742084                ) );
    20752085
     2086                $next_user_core_update = get_preferred_from_update_core();
     2087                // If the update transient is empty, use the update we just performed
     2088                if ( ! $next_user_core_update )
     2089                        $next_user_core_update = $core_update;
     2090                $newer_version_available = ( 'upgrade' == $next_user_core_update->response && version_compare( $next_user_core_update->version, $core_update, '>' ) );
     2091
     2092                $newer_version_available = true;
     2093                $next_user_core_update->version = $next_user_core_update->current = '3.8.1';
    20762094                /**
    20772095                 * Filter whether to send an email following an automatic background core update.
    20782096                 *
     
    21072125                                return;
    21082126                }
    21092127
    2110                 $subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $core_update->current );
     2128                // If the auto update is not to the latest version, say that the current version of WP is available instead.
     2129                $version = 'success' === $type ? $core_update->current : $next_user_core_update->current;
     2130                $subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $version );
    21112131
    21122132                $body = '';
    21132133
     
    21142134                switch ( $type ) {
    21152135                        case 'success' :
    21162136                                $body .= sprintf( __( 'Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.' ), home_url(), $core_update->current );
    2117                                 $body .= "\n\n" . __( 'No further action is needed on your part.' );
     2137                                $body .= "\n\n";
     2138                                if ( ! $newer_version_available )
     2139                                        $body .= __( 'No further action is needed on your part.' ) . ' ';
    21182140
    21192141                                // Can only reference the About screen if their update was successful.
    21202142                                list( $about_version ) = explode( '-', $core_update->current, 2 );
    2121                                 $body .= ' ' . sprintf( __( "For more on version %s, see the About WordPress screen:" ), $about_version );
     2143                                $body .= sprintf( __( "For more on version %s, see the About WordPress screen:" ), $about_version );
    21222144                                $body .= "\n" . admin_url( 'about.php' );
     2145
     2146                                if ( $newer_version_available ) {
     2147                                        $body .= "\n\n" . sprintf( __( 'WordPress %s is also now available.' ), $next_user_core_update->current ) . ' ';
     2148                                        $body .= __( 'Updating is easy and only takes a few moments:' );
     2149                                        $body .= "\n" . network_admin_url( 'update-core.php' );
     2150                                }
     2151
    21232152                                break;
    21242153
    21252154                        case 'fail' :
    21262155                        case 'manual' :
    2127                                 $body .= sprintf( __( 'Please update your site at %1$s to WordPress %2$s.' ), home_url(), $core_update->current );
     2156                                $body .= sprintf( __( 'Please update your site at %1$s to WordPress %2$s.' ), home_url(), $next_user_core_update->current );
    21282157
    21292158                                $body .= "\n\n";
    2130                                 if ( 'fail' == $type )
     2159
     2160                                // Don't show this message if there is a newer version available.
     2161                                // Potential for confusion, and also not useful for them to know at this point.
     2162                                if ( 'fail' == $type && ! $newer_version_available )
    21312163                                        $body .= __( 'We tried but were unable to update your site automatically.' ) . ' ';
     2164
    21322165                                $body .= __( 'Updating is easy and only takes a few moments:' );
    21332166                                $body .= "\n" . network_admin_url( 'update-core.php' );
    21342167                                break;
    21352168
    21362169                        case 'critical' :
    2137                                 $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 );
     2170                                if ( $newer_version_available )
     2171                                        $body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update WordPress.' ), home_url(), $core_update->current );
     2172                                else
     2173                                        $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 );
    21382174
    21392175                                $body .= "\n\n" . __( "This means your site may be offline or broken. Don't panic; this can be fixed." );
    21402176
     
    21442180                }
    21452181
    21462182                // Updates are important!
    2147                 if ( $type != 'success' )
     2183                if ( $type != 'success' || $newer_version_available )
    21482184                        $body .= "\n\n" . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' );
    21492185
    21502186                // Add a note about the support forums to all emails.
     
    21512187                $body .= "\n\n" . __( 'If you experience any issues or need support, the volunteers in the WordPress.org support forums may be able to help.' );
    21522188                $body .= "\n" . __( 'http://wordpress.org/support/' );
    21532189
    2154                 // If things are successful, mention plugins and themes if any are out of date.
    2155                 if ( $type == 'success' && ( get_plugin_updates() || get_theme_updates() ) ) {
     2190                // If things are successful and we're now on the latest, mention plugins and themes if any are out of date.
     2191                if ( $type == 'success' && ! $newer_version_available && ( get_plugin_updates() || get_theme_updates() ) ) {
    21562192                        $body .= "\n\n" . __( 'You also have some plugins or themes with updates available. Update them now:' );
    21572193                        $body .= "\n" . network_admin_url();
    21582194                }