WordPress at Your Fingertips
function is not described

wp_ajax_save_user_color_scheme() WP 3.8.0

Ajax handler for auto-saving the selected color scheme for a user's own profile.

No Hooks.

Return

null. Nothing.

Usage

wp_ajax_save_user_color_scheme();

Notes

  • Global. Array. $_wp_admin_css_colors

Changelog

Since 3.8.0 Introduced.

Code of wp_ajax_save_user_color_scheme() WP 5.8.2

function wp_ajax_save_user_color_scheme() {
	global $_wp_admin_css_colors;

	check_ajax_referer( 'save-color-scheme', 'nonce' );

	$color_scheme = sanitize_key( $_POST['color_scheme'] );

	if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) {
		wp_send_json_error();
	}

	$previous_color_scheme = get_user_meta( get_current_user_id(), 'admin_color', true );
	update_user_meta( get_current_user_id(), 'admin_color', $color_scheme );

	wp_send_json_success(
		array(
			'previousScheme' => 'admin-color-' . $previous_color_scheme,
			'currentScheme'  => 'admin-color-' . $color_scheme,
		)
	);
}