Adding extra user roles to a WordPress user can be useful. This code recipe will add extra user roles to the recently created user from Zapier.

In this example, we will simply add the role of “editor” to the recently created user, you are able to add custom roles to the user. This won’t replace the user’s existing role but add onto it. You may be able to use ->set_role( 'your_role' ); to change the user’s role instead.

Add this code to your child theme’s functions.php or custom plugin.

<?php
/**
* This will allow you to add additional roles to a user when the user is created through Zapier and added to WordPress.
* This uses the 'create_user' action and doesn't replace existing role assigned to the user.
* Copy line 12 and adjust it for each role you would like to add.
* Add this code below into your child theme's functions.php file or custom plugin.
*/
function my_wp_zapier_add_extra_role( $user_id ) {
$user = new WP_User( $user_id );
$user->add_role( 'editor' );
// $user->add_role( 'custom_role_slug' );
}
add_action( 'wp_zapier_after_create_user', 'my_wp_zapier_add_extra_role' );
//add_action( 'wp_zapier_after_update_user', 'my_wp_zapier_add_extra_role' );

Purchase WP Zapier Plugin

WP Zapier Integration

 

If you have any further questions, please feel free to open a support ticket.