Make WordPress Core

Ticket #51742: 51742.3.diff

File 51742.3.diff, 5.1 KB (added by audrasjb, 4 years ago)

Move the auto-updates UI ti the top and replace form/checkbox with action links

  • src/wp-admin/update-core.php

    diff --git a/src/wp-admin/update-core.php b/src/wp-admin/update-core.php
    index c08e57f6e9..b9f6e0750d 100644
    a b function core_upgrade_preamble() { 
    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'] ) {
     309        if ( isset( $_GET['core-auto-updates-major'] ) ) {
     310                if ( 1 === (int) $_GET['core-auto-updates-major'] ) {
    312311                        update_site_option( 'auto_update_core_major', 1 );
    313312                } else {
    314313                        update_site_option( 'auto_update_core_major', 0 );
    function core_auto_updates_settings() { 
    322321        $upgrade_minor = get_site_option( 'auto_update_core_minor', true );
    323322        $upgrade_major = get_site_option( 'auto_update_core_major', false );
    324323
     324        $major_optin_disabled = false;
    325325        // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false.
    326326        if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
    327327                if ( false === WP_AUTO_UPDATE_CORE ) {
    function core_auto_updates_settings() { 
    343343                        $upgrade_minor = true;
    344344                        $upgrade_major = false;
    345345                }
     346                $major_optin_disabled = true;
    346347        }
    347348
    348349        /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
    function core_auto_updates_settings() { 
    352353        /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
    353354        $upgrade_major = apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
    354355
     356        $is_major_optin_disabled = apply_filters( 'allow_major_auto_core_updates', null );
     357        if ( isset( $is_major_optin_disabled ) ) {
     358                $major_optin_disabled = true;
     359        }
     360
    355361        $auto_update_settings = array(
    356362                'dev'   => $upgrade_dev,
    357363                'minor' => $upgrade_minor,
    358364                'major' => $upgrade_major,
    359365        );
     366
     367        if ( $auto_update_settings['major'] ) {
     368                $wp_version = get_bloginfo( 'version' );
     369                $updates    = get_core_updates();
     370                if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
     371                        echo '<p>' . wp_get_auto_update_message() . '</p>';
     372                }
     373        }
    360374        ?>
    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>
     375
     376        <?php if ( 0 === (int) $major_optin_disabled ) : ?>
    364377                <p>
    365378                        <?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                                 }
     379                        if ( 0 === (int) $upgrade_major ) {
     380                                echo sprintf(
     381                                        /* Translators: Action link to enable core auto-updates. */
     382                                        __( 'You are invited to <a href="%s">automatically keep this site up-to-date with regular feature updates.</a>' ),
     383                                        esc_url( strtok( $_SERVER['REQUEST_URI'], '?' ) ) . '?core-auto-updates-major=1'
     384                                );
     385                        } else {
     386                                echo sprintf(
     387                                        /* Translators: Action link to disable core auto-updates. */
     388                                        __( 'Auto-updates for regular feature updates are on. You can <a href="%s">turn them off.</a>' ),
     389                                        esc_url( strtok( $_SERVER['REQUEST_URI'], '?' ) ) . '?core-auto-updates-major=0'
     390                                );
    372391                        }
    373392                        ?>
    374393                </p>
     394        <?php else: ?>
    375395                <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>
    380                 </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                 ?>
    389                 <p>
    390                         <input id="core-auto-updates-settings" class="button" type="submit" value="<?php esc_attr_e( 'Save' ); ?>" name="core-auto-updates-settings" />
     396                        <?php _e( 'This website is set to keep itself up-to-date with regular feature updates.' ); ?>
    391397                </p>
    392         </form>
     398        <?php endif; ?>
     399
    393400        <?php
     401        /**
     402         * Fires after the major core auto-update option.
     403         *
     404         * @since 5.6.0
     405         */
     406        do_action( 'after_core_auto_updates_settings_fields', $auto_update_settings );
    394407}
    395408
    396409/**
    if ( 'upgrade-core' === $action ) { 
    957970        ?>
    958971        <div class="wrap">
    959972        <h1><?php _e( 'WordPress Updates' ); ?></h1>
     973        <p><?php _e( 'Here you can find information about updates, set auto-updates and see what plugins or themes need updating.' ); ?></p>
     974
    960975        <?php
    961976        if ( $upgrade_error ) {
    962977                echo '<div class="error"><p>';
    if ( 'upgrade-core' === $action ) { 
    982997        echo '</p>';
    983998
    984999        if ( current_user_can( 'update_core' ) ) {
    985                 core_upgrade_preamble();
    9861000                core_auto_updates_settings();
     1001                core_upgrade_preamble();
    9871002        }
    9881003        if ( current_user_can( 'update_plugins' ) ) {
    9891004                list_plugin_updates();