adding a user attribute programmatically

Permalink
Hi everyone,

I am trying to add a user attribute programmatically but i cant seem to find the solution in the documentation.
If someone could please help me out that would be great :)

Gr

xb385
 
hutman replied on at Permalink Reply
hutman
You'd do it something like this

$member_name = UserAttributeKey::getByHandle('member_name');
if (!$member_name instanceof UserAttributeKey) {
    $member_name = UserAttributeKey::add('text', array(
        'akHandle' => 'member_name',
        'akName' => t('Member Name'),
        'akIsSearchable' => false,
        'akIsSearchableIndexed' => false,
        'uakProfileDisplay' => false,
        'uakProfileEdit' => true,
        'uakProfileEditRequired' => false,
        'uakRegisterEdit' => false,
        'uakRegisterEditRequired' => false,
        'uakMemberListDisplay' => false), $pkg);
xb385 replied on at Permalink Reply
xb385
Hi hutman,

that does look right (i cant test it right now) but the only question i have is this, does this apply the attribute to all members? it seems like it only adds the attribute to a specific username (member name) while i'm trying to add this to all the members

thx for the help!
xb385 replied on at Permalink Reply
xb385
oh now i see what it does, it checks if the membername attribute excists and adds it if it does not, yes then it should work for what im trying to do. will give feedback tonight!