Make WordPress Core

Ticket #51742: 51742.5.diff

File 51742.5.diff, 7.6 KB (added by azaozz, 4 years ago)
  • src/wp-admin/update-core.php

     
    306306 * @since 5.6.0
    307307 */
    308308function core_auto_updates_settings() {
    309         $upgrade_major_value = '';
    310         if ( isset( $_POST['core-auto-updates-settings'] ) && wp_verify_nonce( $_POST['set_core_auto_updates_settings'], 'core-auto-updates-nonce' ) ) {
    311                 if ( isset( $_POST['core-auto-updates-major'] ) && 1 === (int) $_POST['core-auto-updates-major'] ) {
    312                         update_site_option( 'auto_update_core_major', 1 );
    313                 } else {
    314                         update_site_option( 'auto_update_core_major', 0 );
     309        if ( isset( $_GET['core-major-auto-updates-saved'] ) ) {
     310                if ( 'enabled' === $_GET['core-major-auto-updates-saved'] ) {
     311                        $notice_text = __( 'WordPress will auto-update to next major versions.' );
     312                        echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
     313                } elseif ( 'disabled' === $_GET['core-major-auto-updates-saved'] ) {
     314                        $notice_text = __( 'WordPress will no longer auto-update to next major versions.' );
     315                        echo '<div class="notice notice-success is-dismissible"><p>' . $notice_text . '</p></div>';
    315316                }
    316                 echo '<div class="notice notice-success is-dismissible"><p>';
    317                 _e( 'WordPress auto-update settings updated.' );
    318                 echo '</p></div>';
    319317        }
    320318
    321         $upgrade_dev   = get_site_option( 'auto_update_core_dev', true );
    322         $upgrade_minor = get_site_option( 'auto_update_core_minor', true );
    323         $upgrade_major = get_site_option( 'auto_update_core_major', false );
     319        $upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' );
     320        $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' );
     321        $upgrade_major = get_site_option( 'auto_update_core_major', 'disabled' );
    324322
     323        $upgrade_major_optin_enabled = true;
    325324        // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false.
    326325        if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
    327326                if ( false === WP_AUTO_UPDATE_CORE ) {
    328327                        // Defaults to turned off, unless a filter allows it.
    329                         $upgrade_dev   = false;
    330                         $upgrade_minor = false;
    331                         $upgrade_major = false;
     328                        $upgrade_dev   = 'disabled';
     329                        $upgrade_minor = 'disabled';
     330                        $upgrade_major = 'disabled';
    332331                } elseif ( true === WP_AUTO_UPDATE_CORE
    333332                        || 'beta' === WP_AUTO_UPDATE_CORE
    334333                        || 'rc' === WP_AUTO_UPDATE_CORE
    335334                ) {
    336335                        // ALL updates for core.
    337                         $upgrade_dev   = true;
    338                         $upgrade_minor = true;
    339                         $upgrade_major = true;
     336                        $upgrade_dev   = 'enabled';
     337                        $upgrade_minor = 'enabled';
     338                        $upgrade_major = 'enabled';
    340339                } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
    341340                        // Only minor updates for core.
    342                         $upgrade_dev   = false;
    343                         $upgrade_minor = true;
    344                         $upgrade_major = false;
     341                        $upgrade_dev   = 'disabled';
     342                        $upgrade_minor = 'enabled';
     343                        $upgrade_major = 'disabled';
    345344                }
     345
     346                // The UI is overriden by the WP_AUTO_UPDATE_CORE constant.
     347                $upgrade_major_optin_enabled = false;
    346348        }
    347349
     350        // Is the UI overriden by a plugin using the allow_major_auto_core_updates filter?
     351        if ( has_filter( 'allow_major_auto_core_updates' ) ) {
     352                $upgrade_major_optin_enabled = false;
     353        }
     354
    348355        /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
    349356        $upgrade_dev = apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev );
    350357        /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
     
    357364                'minor' => $upgrade_minor,
    358365                'major' => $upgrade_major,
    359366        );
     367
     368        if ( $auto_update_settings['major'] ) {
     369                $wp_version = get_bloginfo( 'version' );
     370                $updates    = get_core_updates();
     371                if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
     372                        echo '<p>' . wp_get_auto_update_message() . '</p>';
     373                }
     374        }
     375
     376        $action_url = self_admin_url( 'update-core.php?action=core-major-auto-updates-settings' );
    360377        ?>
    361         <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" name="core-auto-updates" class="form-core-auto-updates">
    362                 <?php wp_nonce_field( 'core-auto-updates-nonce', 'set_core_auto_updates_settings' ); ?>
    363                 <h2><?php _e( 'Auto-update settings' ); ?></h2>
     378
     379        <?php if ( $upgrade_major_optin_enabled ) : ?>
    364380                <p>
    365381                        <?php
    366                         if ( $auto_update_settings['major'] ) {
    367                                 $wp_version = get_bloginfo( 'version' );
    368                                 $updates    = get_core_updates();
    369                                 if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
    370                                         echo wp_get_auto_update_message();
    371                                 }
     382                        if ( 'enabled' === $upgrade_major ) {
     383                                echo sprintf(
     384                                        /* Translators: Action link to disable core auto-updates. */
     385                                        __( 'Auto-updates for regular feature updates are on. You can <a href="%s">turn them off.</a>' ),
     386                                        wp_nonce_url( add_query_arg( 'value', 'disable', $action_url ), 'core-major-auto-updates-nonce' )
     387                                );
     388                        } else {
     389                                echo sprintf(
     390                                        /* Translators: Action link to enable core auto-updates. */
     391                                        __( 'You are invited to <a href="%s">automatically keep this site up-to-date with regular feature updates.</a>' ),
     392                                        wp_nonce_url( add_query_arg( 'value', 'enable', $action_url ), 'core-major-auto-updates-nonce' )
     393                                );
    372394                        }
    373395                        ?>
    374396                </p>
     397        <?php elseif ( 'enabled' === $upgrade_major ) : ?>
    375398                <p>
    376                         <input type="checkbox" name="core-auto-updates-major" id="core-auto-updates-major" value="1" <?php checked( $auto_update_settings['major'], 1 ); ?> />
    377                         <label for="core-auto-updates-major">
    378                                 <?php _e( 'Automatically keep this site up-to-date with regular feature updates.' ); ?>
    379                         </label>
     399                        <?php _e( 'This website is set to keep itself up-to-date with regular feature updates.' ); ?>
    380400                </p>
    381                 <?php
    382                 /**
    383                  * Fires after the major core auto-update checkbox.
    384                  *
    385                  * @since 5.6.0
    386                  */
    387                 do_action( 'after_core_auto_updates_settings_fields', $auto_update_settings );
    388                 ?>
     401        <?php else: ?>
    389402                <p>
    390                         <input id="core-auto-updates-settings" class="button" type="submit" value="<?php esc_attr_e( 'Save' ); ?>" name="core-auto-updates-settings" />
     403                        <?php _e( 'Auto-updates for regular feature updates are not available for this website.' ); ?>
    391404                </p>
    392         </form>
     405        <?php endif; ?>
     406
    393407        <?php
     408        /**
     409         * Fires after the major core auto-update settings.
     410         *
     411         * @since 5.6.0
     412         */
     413        do_action( 'after_core_auto_updates_settings', $auto_update_settings );
    394414}
    395415
    396416/**
     
    957977        ?>
    958978        <div class="wrap">
    959979        <h1><?php _e( 'WordPress Updates' ); ?></h1>
     980        <p><?php _e( 'Here you can find information about updates, set auto-updates and see what plugins or themes need updating.' ); ?></p>
     981
    960982        <?php
    961983        if ( $upgrade_error ) {
    962984                echo '<div class="error"><p>';
     
    9821004        echo '</p>';
    9831005
    9841006        if ( current_user_can( 'update_core' ) ) {
     1007                core_auto_updates_settings();
    9851008                core_upgrade_preamble();
    986                 core_auto_updates_settings();
    9871009        }
    9881010        if ( current_user_can( 'update_plugins' ) ) {
    9891011                list_plugin_updates();
     
    11581180
    11591181        require_once ABSPATH . 'wp-admin/admin-footer.php';
    11601182
     1183} elseif ( 'core-major-auto-updates-settings' === $action ) {
     1184        $redirect_url = self_admin_url( 'update-core.php' );
     1185
     1186        if ( isset( $_GET['value'] ) ) {
     1187                check_admin_referer( 'core-major-auto-updates-nonce' );
     1188
     1189                if ( 'enable' === $_GET['value'] ) {
     1190                        update_site_option( 'auto_update_core_major', 'enabled' );
     1191                        $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'enabled', $redirect_url );
     1192                } elseif ( 'disable' === $_GET['value'] ) {
     1193                        update_site_option( 'auto_update_core_major', 'disabled' );
     1194                        $redirect_url = add_query_arg( 'core-major-auto-updates-saved', 'disabled', $redirect_url );
     1195                }
     1196        }
     1197
     1198        wp_redirect( $redirect_url );
     1199        exit;
    11611200} else {
    11621201        /**
    11631202         * Fires for each custom update action on the WordPress Updates screen.