Skip to main content

i4w_alternate_role

Usage

This hook enables you to influence and manipulate the WordPress role (administrator, moderator, editor, etc) for users with certain Keap tags.

If this hook is used, the WordPress user role will be updated each time the user logs in, as well as when the “i4w_genpass” module is used.

Aside from the membership tags, an additional tag needs to be assigned to those individuals who should have any WordPress role other than the default (usually “subscriber”) role on the site.

Parameters

iMember360 will pass the following parameters to your filter function:

ParameterDescription
$default_roleContains the default WordPress role for your site.
$tagsContains an array of all Keap tags assigned to this user.
$cidThe contact ID of the current user.

Example

PHP
function my_i4w_alternate_role_hook($default_role, $tags="", $cid=0) {
// $default_role is the default role defined for this site
// $tags is a raw CSV string, i.e. 123,234,345,456,etc
// containing the tags assigned to the current user
// $cid is the user's Contact ID
$arrTAGS = explode(',', $tags);
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('i4w_alternate_role', 'my_i4w_alternate_role_hook', 1, 2);