Make WordPress Core

Opened 3 years ago

Last modified 14 months ago

#33542 new feature request

User preferences API idea

Reported by: johnjamesjacoby Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Users Keywords: 2nd-opinion
Focuses: Cc:


When setting up a new site, many site Settings seem at first like user preferences even though they aren't. For sites with 1 user blogging out to the world, this makes sense, but for more robust installations a single set of site settings does not satisfy all users.

I'd like to propose a user preferences API be invented. This API would consist of a series of functions that connect usermeta to site & network options, and when invoked, will traverse the user/site/network hierarchy and use the first available setting. Something like:

$language = wp_get_user_preference( $user_id, 'WPLANG' );

Imagine then, that wp_get_user_preference() would first look in wp_usermeta, then in wp_options and then in wp_sitemeta if multisite. This is obviously a fuzzy example, and there are less obvious caveats (like what to do when usermeta keys do not match option keys, etc...) which can all be conditionally addressed as we poke holes in the idea.

Here are a few settings that could be candidates, taken from their verbiage in various administration screens:


  • Timezone
  • Date format
  • Time format
  • Start of week
  • Language


  • Formatting
  • Default Post Category
  • Default Post Format


  • Blog pages show at most
  • Syndication feeds show the most recent


  • Default article settings
  • Email me whenever
  • Avatar Display

Attachments (1)

wp-user-preferences.php (2.6 KB) - added by johnjamesjacoby 3 years ago.
A plugin-style example API

Download all attachments as: .zip

Change History (6)

#1 @johnjamesjacoby
3 years ago

Primitive, fuzzy pseudo-code might start by looking like this:

 * Get a user preference
 * @param  int     $user_id
 * @param  string  $key
function wp_get_user_preference( $user_id = 0, $key = '' ) {

	// Check usermeta first
	$retval = get_usermeta( $user_id, $key );

	// Nothing, so check site option
	if ( false === $retval ) {
		$retval = get_option( $key );

		// Nothing, so check network option if multisite
		if ( false === $retval && is_multisite() ) {
			$retval = get_site_option( $key );

	// Filter & return
	return apply_filters( 'wp_get_user_preference', $retval, $user_id, $key );

3 years ago

A plugin-style example API

#2 @johnjamesjacoby
3 years ago

Note that what starts as a simple suggestion can (and should IMO) turn into thoughts about UI, conveying to users that their preferences are/not in effect, anomalies where maybe a user should never be allowed a preference (I.E. they cannot disable SSL when a site forces SSL, etc...)

Each option & permutation would require scrutinization, testing, and adjustment before going into WordPress core. Until that happens, the API itself could be rolled in early and used for 1 or 2 critical preferences to start.

#3 @johnjamesjacoby
3 years ago

I've created a GitHub repository if anyone would like to collaborate on the code behind this idea further, and will likely release this in the plugins repository as well.

#4 @joostdevalk
2 years ago

I really want this too! Probably needs some more feedback from a core committer? :) Language as a user setting seems to me to be an awesome feature.

#5 @swissspidy
14 months ago

  • Milestone changed from Awaiting Review to Future Release

A user language option exists now, a timezone setting might follow in the future. Some might be added by plugins.

Having a wp_get_user_preference() wrapper sounds interesting.

Note: See TracTickets for help on using tickets.