Using WordPress ‘is_user_option_local()’ PHP function

The is_user_option_local WordPress PHP function checks whether a usermeta key is related to the current blog.

Usage

To use the function, simply call it with the required parameter, $key, and optional parameters $user_id and $blog_id:

is_user_option_local($key, $user_id, $blog_id);

Parameters

  • $key (string) – The usermeta key to check.
  • $user_id (int) – Optional. Defaults to the current user.
  • $blog_id (int) – Optional. Defaults to the current blog.

More information

See WordPress Developer Resources: is_user_option_local

Examples

This example checks whether the usermeta key ‘my_custom_key’ is related to the current blog.

$key = 'my_custom_key';
$is_local = is_user_option_local($key);
// $is_local will be true or false

This example checks whether the usermeta key ‘my_custom_key’ is related to the specified user and blog.

$key = 'my_custom_key';
$user_id = 2;
$blog_id = 3;
$is_local = is_user_option_local($key, $user_id, $blog_id);
// $is_local will be true or false

This example checks whether the usermeta key ‘my_custom_key’ is related to the current user on the specified blog.

$key = 'my_custom_key';
$blog_id = 3;
$is_local = is_user_option_local($key, null, $blog_id);
// $is_local will be true or false

This example checks whether the usermeta key ‘my_custom_key’ is related to the specified user on the current blog.

$key = 'my_custom_key';
$user_id = 2;
$is_local = is_user_option_local($key, $user_id);
// $is_local will be true or false

This example checks whether the usermeta keys ‘my_custom_key_1’ and ‘my_custom_key_2’ are related to the current blog.

$keys = ['my_custom_key_1', 'my_custom_key_2'];
$is_local = array_map('is_user_option_local', $keys);
// $is_local will be an array with true or false values