wp_ajax_save_user_color_scheme() WordPress Function

The wp_ajax_save_user_color_scheme() function is used to save a user's color scheme preference in WordPress. This function is triggered when the user clicks the "Save" button on the "Color Scheme" option page.

wp_ajax_save_user_color_scheme() #

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


Source

File: wp-admin/includes/ajax-actions.php

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,
		)
	);
}


Top ↑

Changelog

Changelog
VersionDescription
3.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More