I need to charge a fee when users join the directory. Since HivePress didn’t offer this option, I found a workaround using Forminator forms.
I added custom code to automatically create a new vendor in HivePress when a user with registers.
This part is working well. However, when users (Not designer) sign up to message or leave a review via the HivePress registration form, they are also being assigned the “Contributor” role and given a vendor profile, which I do not want.
I tried changing the default role for new users to “Subscriber,” but this impacted the Forminator form as well, preventing designers from signing up correctly. I also tried fixing with code but it didn’t work.
Current Setup:
- Forminator Forms: Used to handle the registration process and charge a fee for designers
- HivePress: Used to manage vendors.
- Custom Code: Automatically creates a vendor in HivePress when a user with the “Contributor” role is registered.
Goal:
- Ensure that users registering via HivePress are not assigned the “Contributor” role and assigned ‘Subscriber instead’ so a vendor is not created.
- Maintain the ability for users registering via Forminator to be assigned the “Contributor” role and be created as vendors.
Here is the original code that I added:
// Create a new vendor when a user registers
add_action('user_register', 'create_hivepress_vendor', 10, 1);
function create_hivepress_vendor($user_id) {
if (!function_exists('hivepress')) {
return;
}
// Create a new vendor post
$vendor_id = wp_insert_post([
'post_title' => get_user_meta($user_id, 'nickname', true),
'post_type' => 'hp_vendor',
'post_status' => 'publish',
'post_author' => $user_id
]);
if (is_wp_error($vendor_id)) {
error_log('Error creating vendor: ' . $vendor_id->get_error_message());
return;
}
// Update vendor meta
update_post_meta($vendor_id, 'hp_user', $user_id);
update_user_meta($user_id, 'hp_vendor', $vendor_id);
// Assign vendor role
$user = new WP_User($user_id);
$user->add_role('vendor');
}
Any help with this will be greatly appreciated.