Yes it's possible, if you add an OR
condition in your page template for yours existing user roles view (or display) conditions. This condition will be based on a custom field set in the user meta data.
So when you will click on that "button", it will update the value of the user custom field and will allow to display the "premium content" (for example). For this purpose you can use get_user_meta()
and update_user_meta()
Wordpress Functions.
You define first that 2 variables at the beginning of your php file or template:
// Getting the user iD
$user_id = get_current_user_id();
// Looking if our user custom field exist and has a value
$custom_value = get_user_meta($user_id, '_custom_user_meta', true);
Then your condition is going to be a little like:
if($user_role == 'premium' && $custom_value){
// Displays the premium content
}
Now when pressing on your "button", it will update that $custom_value to true, allowing this user to see that premium content on form submission (or with ajax).
So you will have to put this code just after the 2 variables above:
if('yes' == $_post['button_id']){
// $custom_value and $user_id are already defined normally (see above)
if($custom_value){
update_user_meta($user_id, '_custom_user_meta', 0); // updated to false
} else {
update_user_meta($user_id, '_custom_user_meta', 1); // updated to true
}
}
This should work…
Update (based on your comment)
Alternatively, for The Admin as in your comment, You can target 'administrator'
user role in your condition AND (&&
) a special cookie that will be set by your "button". This way you will not have to use a custom field.