• Resolved Luigino

    (@luigino)


    Hello everyone!!

    I imported like almost 600 users from a db inside wp_users and I’d like to assign default role to all users imported via SQL… I know capability is usually stored in wp_usermeta with metakey = ‘wp_capabilities’ and actually I see only administrator role in meta_value field….. How I can assign default subscriber role to all those almost 600 users via SQL? Thanks in advance to all!!

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • In the usermeta table, a record with the meta_key capabilities would have to be created for each user. This contains a serialized array with the roles.

    Example:

    meta_key: wp_capabilities
    meta_value: a:1:{s:13: "administrator";b:1;}

    Also, you should set user_level. Here is an overview about it:
    https://gist.github.com/octalmage/d748456cfd48db849207

    Attention: both meta_keys capabilities and user_level are prefixed with the database prefix your project uses. So e.g. “wp_” if it is “wp_”.

    So you would have to add 2 records per user. This makes a SQL statement relatively complex. I would recommend to solve this fix via PHP by looping through all users and adding them via

    $user->add_role( 'yourrole' );

    to set the desired role.

    Thread Starter Luigino

    (@luigino)

    At the end I solved with a little PHP procedure calling wp_insert_user() from that another table specifying the role as default’s wordpress. Thanks anyway!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Assign role to users via SQL’ is closed to new replies.