You can use update_user_option()
function (see codex)
Your loop looks fine to me, so probably this would work:
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query(array('role' => 'Subscriber'));
// Get the results
$users = $wp_user_query->get_results();
// Check for results
if (!empty($users)) {
// loop trough each author
foreach ($users as $user)
{
// update option
update_user_option( $user->ID, 'show_admin_bar_front', 'true');
}
}
Things to pay attention to:
-
You’re looping through all queried users, so in
update_user_option
the first parameter needs to be the id retrieved from current user
object (not the hardcoded ID) -
The third parameter in
update_user_option
should be of a string type apparently, so"true"
, nottrue