Using WordPress ‘get_all_user_settings()’ PHP function

The get_all_user_settings() WordPress PHP function retrieves all user interface settings.

Usage

$all_user_settings = get_all_user_settings();

Parameters

  • None

More information

See WordPress Developer Resources: get_all_user_settings

Examples

Display All User Settings

Retrieve and display all user settings in an unordered list.

$all_user_settings = get_all_user_settings();

echo '<ul>';
foreach ($all_user_settings as $key => $value) {
    echo '<li><strong>' . $key . ':</strong> ' . $value . '</li>';
}
echo '</ul>';

Filter User Settings by Prefix

Retrieve user settings with a specific prefix and display them in a table.

$prefix = 'myplugin_';
$all_user_settings = get_all_user_settings();
$filtered_settings = array_filter(
    $all_user_settings,
    function ($key) use ($prefix) {
        return strpos($key, $prefix) === 0;
    },
    ARRAY_FILTER_USE_KEY
);

echo '<table>';
foreach ($filtered_settings as $key => $value) {
    echo '<tr><td><strong>' . $key . '</strong></td><td>' . $value . '</td></tr>';
}
echo '</table>';

Update User Setting

Update a specific user setting using the get_all_user_settings() and set_user_setting() functions.

$setting_key = 'myplugin_setting';
$new_value = 'New Value';
$all_user_settings = get_all_user_settings();

if (array_key_exists($setting_key, $all_user_settings)) {
    set_user_setting($setting_key, $new_value);
}

Delete User Setting

Delete a specific user setting using the get_all_user_settings() and delete_user_setting() functions.

$setting_key = 'myplugin_setting';
$all_user_settings = get_all_user_settings();

if (array_key_exists($setting_key, $all_user_settings)) {
    delete_user_setting($setting_key);
}

Count User Settings with a Prefix

Count the number of user settings with a specific prefix.

$prefix = 'myplugin_';
$all_user_settings = get_all_user_settings();
$filtered_settings = array_filter(
    $all_user_settings,
    function ($key) use ($prefix) {
        return strpos($key, $prefix) === 0;
    },
    ARRAY_FILTER_USE_KEY
);

$count = count($filtered_settings);
echo 'Number of settings with prefix "' . $prefix . '": ' . $count;