From 16b6b6b8e41ede72423e5df9e0077e0d357c1454 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 2 Dec 2013 19:44:50 +0000 Subject: [PATCH] Simplify the color scheme profile saving JS. see #25858. git-svn-id: https://develop.svn.wordpress.org/trunk@26535 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 15 ++++++--------- src/wp-admin/js/user-profile.js | 9 ++++----- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index a28e2c68c0..6985bcfdf4 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -2249,18 +2249,15 @@ function wp_ajax_get_revision_diffs() { function wp_ajax_save_user_color_scheme() { global $_wp_admin_css_colors; - $user_id = intval( $_POST['user_id'] ); + $user_id = get_current_user_id(); + check_ajax_referer( 'update-user_' . $user_id, 'nonce' ); + $color_scheme = sanitize_key( $_POST['color_scheme'] ); - if ( get_current_user_id() !== $user_id ) + if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) { wp_send_json_error(); + } - if ( ! get_user_by( 'id', $user_id ) ) - wp_send_json_error(); - - if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) - wp_send_json_error(); - - update_user_option( $user_id, 'admin_color', $color_scheme, true ); + update_user_meta( $user_id, 'admin_color', $color_scheme ); wp_send_json_success(); } diff --git a/src/wp-admin/js/user-profile.js b/src/wp-admin/js/user-profile.js index 31ade5cbce..0f1dbee38b 100644 --- a/src/wp-admin/js/user-profile.js +++ b/src/wp-admin/js/user-profile.js @@ -83,8 +83,7 @@ current_user_id = $( 'input[name="checkuser_id"]' ).val(); $colorpicker.on( 'click.colorpicker', '.color-option', function() { - var $this = $(this), - color_scheme = $this.children( 'input[name="admin_color"]' ).val(); + var $this = $(this); if ( $this.hasClass( 'selected' ) ) { return; @@ -106,9 +105,9 @@ // update user option $.post( ajaxurl, { - action: 'save-user-color-scheme', - color_scheme: color_scheme, - user_id: user_id + action: 'save-user-color-scheme', + color_scheme: $this.children( 'input[name="admin_color"]' ).val(), + nonce: $('#_wpnonce').val() }); } });