Ticket #51742: 51742.5.diff
File 51742.5.diff, 7.6 KB (added by , 4 years ago) |
---|
-
src/wp-admin/update-core.php
306 306 * @since 5.6.0 307 307 */ 308 308 function 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>'; 315 316 } 316 echo '<div class="notice notice-success is-dismissible"><p>';317 _e( 'WordPress auto-update settings updated.' );318 echo '</p></div>';319 317 } 320 318 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' ); 324 322 323 $upgrade_major_optin_enabled = true; 325 324 // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'minor', false. 326 325 if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { 327 326 if ( false === WP_AUTO_UPDATE_CORE ) { 328 327 // 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'; 332 331 } elseif ( true === WP_AUTO_UPDATE_CORE 333 332 || 'beta' === WP_AUTO_UPDATE_CORE 334 333 || 'rc' === WP_AUTO_UPDATE_CORE 335 334 ) { 336 335 // 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'; 340 339 } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { 341 340 // 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'; 345 344 } 345 346 // The UI is overriden by the WP_AUTO_UPDATE_CORE constant. 347 $upgrade_major_optin_enabled = false; 346 348 } 347 349 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 348 355 /** This filter is documented in wp-admin/includes/class-core-upgrader.php */ 349 356 $upgrade_dev = apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ); 350 357 /** This filter is documented in wp-admin/includes/class-core-upgrader.php */ … … 357 364 'minor' => $upgrade_minor, 358 365 'major' => $upgrade_major, 359 366 ); 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' ); 360 377 ?> 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 ) : ?> 364 380 <p> 365 381 <?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 ); 372 394 } 373 395 ?> 374 396 </p> 397 <?php elseif ( 'enabled' === $upgrade_major ) : ?> 375 398 <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.' ); ?> 380 400 </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: ?> 389 402 <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.' ); ?> 391 404 </p> 392 </form> 405 <?php endif; ?> 406 393 407 <?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 ); 394 414 } 395 415 396 416 /** … … 957 977 ?> 958 978 <div class="wrap"> 959 979 <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 960 982 <?php 961 983 if ( $upgrade_error ) { 962 984 echo '<div class="error"><p>'; … … 982 1004 echo '</p>'; 983 1005 984 1006 if ( current_user_can( 'update_core' ) ) { 1007 core_auto_updates_settings(); 985 1008 core_upgrade_preamble(); 986 core_auto_updates_settings();987 1009 } 988 1010 if ( current_user_can( 'update_plugins' ) ) { 989 1011 list_plugin_updates(); … … 1158 1180 1159 1181 require_once ABSPATH . 'wp-admin/admin-footer.php'; 1160 1182 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; 1161 1200 } else { 1162 1201 /** 1163 1202 * Fires for each custom update action on the WordPress Updates screen.