diff --git a/src/wp-admin/admin-ajax.php b/src/wp-admin/admin-ajax.php
index 3213d55028..2966c21252 100644
a
|
b
|
$core_actions_post = array( |
60 | 60 | 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', |
61 | 61 | 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', |
62 | 62 | 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', |
63 | | 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail', |
| 63 | 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail', |
64 | 64 | 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post', |
65 | 65 | 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'delete-plugin', |
66 | 66 | 'search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', |
… |
… |
$core_actions_post = array( |
69 | 69 | |
70 | 70 | // Deprecated |
71 | 71 | $core_actions_post[] = 'wp-fullscreen-save-post'; |
| 72 | $core_actions_post[] = 'save-user-color-scheme'; |
72 | 73 | |
73 | 74 | // Register core Ajax calls. |
74 | 75 | if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) ) |
diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php
index e132ac8101..ad3c7d0a67 100644
a
|
b
|
function wp_ajax_get_revision_diffs() { |
2874 | 2874 | } |
2875 | 2875 | |
2876 | 2876 | /** |
2877 | | * Ajax handler for auto-saving the selected color scheme for |
2878 | | * a user's own profile. |
2879 | | * |
2880 | | * @since 3.8.0 |
2881 | | * |
2882 | | * @global array $_wp_admin_css_colors |
2883 | | */ |
2884 | | function wp_ajax_save_user_color_scheme() { |
2885 | | global $_wp_admin_css_colors; |
2886 | | |
2887 | | check_ajax_referer( 'save-color-scheme', 'nonce' ); |
2888 | | |
2889 | | $color_scheme = sanitize_key( $_POST['color_scheme'] ); |
2890 | | |
2891 | | if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) { |
2892 | | wp_send_json_error(); |
2893 | | } |
2894 | | |
2895 | | $previous_color_scheme = get_user_meta( get_current_user_id(), 'admin_color', true ); |
2896 | | update_user_meta( get_current_user_id(), 'admin_color', $color_scheme ); |
2897 | | |
2898 | | wp_send_json_success( array( |
2899 | | 'previousScheme' => 'admin-color-' . $previous_color_scheme, |
2900 | | 'currentScheme' => 'admin-color-' . $color_scheme |
2901 | | ) ); |
2902 | | } |
2903 | | |
2904 | | /** |
2905 | 2877 | * Ajax handler for getting themes from themes_api(). |
2906 | 2878 | * |
2907 | 2879 | * @since 3.9.0 |
diff --git a/src/wp-admin/includes/deprecated.php b/src/wp-admin/includes/deprecated.php
index a9e0e6f9d1..06672d6068 100644
a
|
b
|
function post_form_autocomplete_off() { |
1478 | 1478 | echo ' autocomplete="off"'; |
1479 | 1479 | } |
1480 | 1480 | } |
| 1481 | |
| 1482 | /** |
| 1483 | * Ajax handler for auto-saving the selected color scheme for |
| 1484 | * a user's own profile. |
| 1485 | * |
| 1486 | * @since 3.8.0 |
| 1487 | * @deprecated 4.8.0 Use /wp/v2/users REST API endpoint instead. |
| 1488 | * |
| 1489 | * @global array $_wp_admin_css_colors |
| 1490 | */ |
| 1491 | function wp_ajax_save_user_color_scheme() { |
| 1492 | global $_wp_admin_css_colors; |
| 1493 | |
| 1494 | _deprecated_function( __FUNCTION__, '4.8.0', '/wp/v2/users' ); |
| 1495 | |
| 1496 | check_ajax_referer( 'save-color-scheme', 'nonce' ); |
| 1497 | |
| 1498 | $color_scheme = sanitize_key( $_POST['color_scheme'] ); |
| 1499 | |
| 1500 | if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) { |
| 1501 | wp_send_json_error(); |
| 1502 | } |
| 1503 | |
| 1504 | $previous_color_scheme = get_user_meta( get_current_user_id(), 'admin_color', true ); |
| 1505 | update_user_meta( get_current_user_id(), 'admin_color', $color_scheme ); |
| 1506 | |
| 1507 | wp_send_json_success( array( |
| 1508 | 'previousScheme' => 'admin-color-' . $previous_color_scheme, |
| 1509 | 'currentScheme' => 'admin-color-' . $color_scheme |
| 1510 | ) ); |
| 1511 | } |
diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php
index 679b9ac5d6..277d6456dd 100644
a
|
b
|
function admin_color_scheme_picker( $user_id ) { |
658 | 658 | <fieldset id="color-picker" class="scheme-list"> |
659 | 659 | <legend class="screen-reader-text"><span><?php _e( 'Admin Color Scheme' ); ?></span></legend> |
660 | 660 | <?php |
661 | | wp_nonce_field( 'save-color-scheme', 'color-nonce', false ); |
662 | 661 | foreach ( $_wp_admin_css_colors as $color => $color_info ) : |
663 | 662 | |
664 | 663 | ?> |
diff --git a/src/wp-admin/js/user-profile.js b/src/wp-admin/js/user-profile.js
index ca99584215..1c919eba85 100644
a
|
b
|
|
327 | 327 | } |
328 | 328 | |
329 | 329 | $(document).ready( function() { |
330 | | var $colorpicker, $stylesheet, user_id, current_user_id, |
| 330 | var $colorpicker, $stylesheet, user_id, current_user_id, current_scheme, |
331 | 331 | select = $( '#display_name' ), |
332 | 332 | current_name = select.val(), |
333 | 333 | greeting = $( '#wp-admin-bar-my-account' ).find( '.display-name' ); |
… |
… |
|
391 | 391 | $stylesheet = $( '#colors-css' ); |
392 | 392 | user_id = $( 'input#user_id' ).val(); |
393 | 393 | current_user_id = $( 'input[name="checkuser_id"]' ).val(); |
| 394 | current_scheme = $( 'input[name="admin_color"]:checked' ).val(); |
394 | 395 | |
395 | 396 | $colorpicker.on( 'click.colorpicker', '.color-option', function() { |
396 | | var colors, |
| 397 | var colors, user, previous_scheme |
397 | 398 | $this = $(this); |
398 | 399 | |
399 | 400 | if ( $this.hasClass( 'selected' ) ) { |
… |
… |
|
425 | 426 | } |
426 | 427 | |
427 | 428 | // update user option |
428 | | $.post( ajaxurl, { |
429 | | action: 'save-user-color-scheme', |
430 | | color_scheme: $this.children( 'input[name="admin_color"]' ).val(), |
431 | | nonce: $('#color-nonce').val() |
432 | | }).done( function( response ) { |
433 | | if ( response.success ) { |
434 | | $( 'body' ).removeClass( response.data.previousScheme ).addClass( response.data.currentScheme ); |
435 | | } |
| 429 | previous_scheme = current_scheme; |
| 430 | current_scheme = $this.children( 'input[name="admin_color"]' ).val(); |
| 431 | |
| 432 | user = new wp.api.models.UsersMe(); |
| 433 | user.save( { meta: { admin_color: current_scheme } } ).done( function ( response ) { |
| 434 | $( 'body' ).removeClass( 'admin-color-' + previous_scheme ).addClass( 'admin-color-' + current_scheme ); |
436 | 435 | }); |
437 | 436 | } |
438 | 437 | }); |
diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php
index 8f0237028d..b72efaedc5 100644
a
|
b
|
add_filter( 'get_post_format', '_post_format_get_term' ); |
426 | 426 | add_filter( 'get_terms', '_post_format_get_terms', 10, 3 ); |
427 | 427 | add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' ); |
428 | 428 | |
| 429 | // User |
| 430 | add_action( 'init', 'create_initial_user_meta', 0 ); |
| 431 | |
429 | 432 | // KSES |
430 | 433 | add_action( 'init', 'kses_init' ); |
431 | 434 | add_action( 'set_current_user', 'kses_init' ); |
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php
index ff7d8bb855..25213de631 100644
a
|
b
|
function wp_default_scripts( &$scripts ) { |
406 | 406 | 'mismatch' => _x( 'Mismatch', 'password mismatch' ), |
407 | 407 | ) ); |
408 | 408 | |
409 | | $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 ); |
| 409 | $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util', 'wp-api' ), false, 1 ); |
410 | 410 | did_action( 'init' ) && $scripts->localize( 'user-profile', 'userProfileL10n', array( |
411 | 411 | 'warn' => __( 'Your new password has not been saved.' ), |
412 | 412 | 'warnWeak' => __( 'Confirm use of weak password' ), |
diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
index 2bb4e0543e..ef556c10b1 100644
a
|
b
|
|
7 | 7 | */ |
8 | 8 | |
9 | 9 | /** |
| 10 | * Registers the initial user meta. |
| 11 | * |
| 12 | * @since 4.8.0 |
| 13 | */ |
| 14 | function create_initial_user_meta() { |
| 15 | register_meta( 'user', 'admin_color', array( |
| 16 | 'type' => 'string', |
| 17 | 'description' => __( 'Admin color scheme' ), |
| 18 | 'single' => true, |
| 19 | 'sanitize_callback' => 'wp_sanitize_admin_color', |
| 20 | 'show_in_rest' => true, |
| 21 | )); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Sanitizes admin_color meta value. |
| 26 | * |
| 27 | * @since 4.8.0 |
| 28 | * |
| 29 | * @param string $value Supplied admin color scheme value. |
| 30 | * @return string Sanitized admin color scheme value. |
| 31 | */ |
| 32 | function wp_sanitize_admin_color( $value ) { |
| 33 | $value = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $value ); |
| 34 | $value = sanitize_key( $value ); |
| 35 | if ( empty( $value ) ) { |
| 36 | return 'fresh'; |
| 37 | } |
| 38 | |
| 39 | return $value; |
| 40 | } |
| 41 | |
| 42 | /** |
10 | 43 | * Authenticates and logs a user in with 'remember' capability. |
11 | 44 | * |
12 | 45 | * The credentials is an array that has 'user_login', 'user_password', and |