Using WordPress ‘get_user_option_{$option}’ PHP filter

The get_user_option_{$option} WordPress PHP filter allows you to modify a specific user option value. The dynamic portion of the hook name, $option, refers to the user option name.

Usage

add_filter('get_user_option_example_option', 'customize_example_option', 10, 3);

function customize_example_option($result, $option, $user) {
    // your custom code here
    return $result;
}

Parameters

  • $result (mixed) – Value for the user’s option.
  • $option (string) – Name of the option being retrieved.
  • $user (WP_User) – WP_User object of the user whose option is being retrieved.

More information

See WordPress Developer Resources: get_user_option_{$option}

Examples

Modify the user’s admin color scheme

In this example, we will modify the user’s admin color scheme.

add_filter('get_user_option_admin_color', 'change_admin_color_scheme', 10, 3);

function change_admin_color_scheme($result, $option, $user) {
    $result = 'ectoplasm';
    return $result;
}

Change the user’s dashboard layout

In this example, we will modify the user’s dashboard layout.

add_filter('get_user_option_screen_layout_dashboard', 'change_dashboard_layout', 10, 3);

function change_dashboard_layout($result, $option, $user) {
    $result = 2;
    return $result;
}

Set a custom date format

In this example, we will set a custom date format for the user.

add_filter('get_user_option_date_format', 'change_date_format', 10, 3);

function change_date_format($result, $option, $user) {
    $result = 'F j, Y';
    return $result;
}

Modify the user’s timezone

In this example, we will modify the user’s timezone.

add_filter('get_user_option_timezone_string', 'change_timezone_string', 10, 3);

function change_timezone_string($result, $option, $user) {
    $result = 'America/New_York';
    return $result;
}

Customize the user’s post per page setting

In this example, we will customize the user’s post per page setting.

add_filter('get_user_option_posts_per_page', 'change_posts_per_page', 10, 3);

function change_posts_per_page($result, $option, $user) {
    $result = 10;
    return $result;
}