mbr/role/alternate
Usage
This filter hook enables you to define the WordPress role Super Admin, Administrator, Editor, Author, Contributor and Subscriber for users whose associated ActiveCampaign contact has specific ActiveCampaign tags.
If this filter hook is used, the WordPress user role will be updated each time the user logs in, as well as when the mbr_genpass webhook module is used.
This filter hook will remove all existing roles from the logged in user and apply the role returned by the filter.
If you wish to always retain one of the WordPress default roles Super Admin, Administrator, Editor, Author, Contributor and Subscriber in addition to adding/removing roles based upon tags you should use the Role To Tags module rather than this mbr/role/alternate filter.
Parameters
Parameters | Description |
---|---|
$default_role | Contains the default WordPress role for your site as selected in WordPress, Settings, General, New User Default Role. |
$arrTAGS | Contains an array of all ActiveCampaign tag ids assigned to this user. |
Examples
- Example 1
For the ActiveCampaign contact associated with the logged in user all user roles will be removed and if they have the tag id 1228 they will be given the WordPress role Administrator. Else if they have the tag 1230 they will be given the WordPress role Moderator. Else if they have the tag 1232 they will be given the WordPress role Editor. Else they will be given the default WordPress role as selected in WordPress, Settings, General, New User Default Role.
function my_mbr_alternate_role_hook($default_role, $arrTAGS=array()) {
// $default_role is the default role defined for this site
// $arrTAGS is an array containing the tag ids assigned to the current user
IF (in_array(1228, $arrTAGS)) :
return 'administrator';
ELSEIF (in_array(1230, $arrTAGS)) :
return 'moderator';
ELSEIF (in_array(1232, $arrTAGS)) :
return 'editor';
ENDIF;
return $default_role;
}
add_filter('mbr/role/alternate', 'my_mbr_alternate_role_hook',1,2);