Php function?
Quote from matt43078 on February 10, 2023, 7:49 pmHi, I’ve been trying to find the correct way to write a php function, where a logged in user pushes a button and the button automatically assigns the Asgaros usergroup to that person. I have a dynamic.ooo Elementor form which switches roles based on submission and I’m sure there’s got to be a way to do it with Asgaros instead of traditional roles.
This is the latest code – and it doesn’t work. Any suggestions? Hugely grateful too, this is the best Forums plugin there is, hands down.
function add_user_to_usergroup($user_id, $usergroup_id) {
// Check if the user is already in the usergroup
if (asgarosforum_is_member_of_usergroup($user_id, $usergroup_id)) {
return;
}// Add the user to the usergroup
$usergroups = asgarosforum_get_usergroups_for_user($user_id);
$usergroups[] = $usergroup_id;
update_user_meta($user_id, ‘asgarosforum_usergroup’, $usergroups);
}add_action(‘dynamicooo_elementor_pro/forms/after_submit’, ‘add_user_to_usergroup_on_form_submit’, 10, 2);
function add_user_to_usergroup_on_form_submit($record, $ajax_handler) {
$user_id = get_current_user_id();
$usergroup_id = 388;
add_user_to_usergroup($user_id, $usergroup_id);
}
Hi, I’ve been trying to find the correct way to write a php function, where a logged in user pushes a button and the button automatically assigns the Asgaros usergroup to that person. I have a dynamic.ooo Elementor form which switches roles based on submission and I’m sure there’s got to be a way to do it with Asgaros instead of traditional roles.
This is the latest code – and it doesn’t work. Any suggestions? Hugely grateful too, this is the best Forums plugin there is, hands down.
function add_user_to_usergroup($user_id, $usergroup_id) {
// Check if the user is already in the usergroup
if (asgarosforum_is_member_of_usergroup($user_id, $usergroup_id)) {
return;
}
// Add the user to the usergroup
$usergroups = asgarosforum_get_usergroups_for_user($user_id);
$usergroups[] = $usergroup_id;
update_user_meta($user_id, ‘asgarosforum_usergroup’, $usergroups);
}
add_action(‘dynamicooo_elementor_pro/forms/after_submit’, ‘add_user_to_usergroup_on_form_submit’, 10, 2);
function add_user_to_usergroup_on_form_submit($record, $ajax_handler) {
$user_id = get_current_user_id();
$usergroup_id = 388;
add_user_to_usergroup($user_id, $usergroup_id);
}
Quote from matt43078 on February 13, 2023, 4:16 pmI guess I’ll leave a negative review and move on. Was so hopeful for this one, but not sure why you all had to create this monster that bypasses the typical wordpress roles. It is so nearly perfection, were it not for this seemingly impossible problem.
I guess I’ll leave a negative review and move on. Was so hopeful for this one, but not sure why you all had to create this monster that bypasses the typical wordpress roles. It is so nearly perfection, were it not for this seemingly impossible problem.
Quote from Asgaros on March 9, 2023, 3:29 amHello @matt43078
Usergroups are just a grouping of users and have nothing to do with roles. So using roles is the wrong place here.
The “idea” of your code looks fine so far, but I guess some of the functions have to get replaced with the correct ones. You can find the relevant ones in the includes/forum-usergroups.php file.
Hello @matt43078
Usergroups are just a grouping of users and have nothing to do with roles. So using roles is the wrong place here.
The “idea” of your code looks fine so far, but I guess some of the functions have to get replaced with the correct ones. You can find the relevant ones in the includes/forum-usergroups.php file.