Here is the setup: I am implementing Wordpress with two specific plugins: Ultimate Members and Yith Vendors which is a woocommece addon.
What I need to do is change a field's data in the database for the Ultimate Members "role" when the capability of the WortdPress user changes to include "yith_vendor" or the WP roles changes to include "vendor" role.
The way that I need this to work is when a visitor to my site registers (they are doing so through a form that is part of the Ultimate Members plugin) and Ultimate members sets a role associated with the plugin and sets the wordpress role to subscriber. Now when a user registers to open a store they are doing so through the yith vendor plugin. When yith-vendor form is submitted a user role is added called vendor and a new capability is added called yith-vendor.
At this point Ultimate Members plugin does not see the change to the users WP role or capabilities; but it needs to.
So what I am trying to do is change the Ultimate Member role to match the WordPress role of "vendor" based in changes to the WP roles or capabilites.
There are two ways to trigger this: 1.) by monitoring the WP capabilities or roles.
Both are arrays and what I need to do is monitor for changes to WP roles or WP capabilities when the yith vendor application form is submitted.
When the change occurs, I need then to update the Ultimate Member role to vendor.
Key points:
there is a Ultimate Member database field called "role" Wordpress has both roles and capability arrays.
What has been done so far but does not work. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
add_action('after_yith_vendor_form_submitted', 'sync_um_and_wp_role', 99 );
function sync_um_and_wp_role( $user_id ) {
// the role the Ultimate member has when submitting a store application.
$um_role = 'member';
// The WP role that the user will get when the yith-vendor form is submitted.
// or the capability will be yith_vendor ( I tried both ways)
$wp_role = 'vendor';
$current_user = wp_get_current_user();
$roles = $current_user->roles;
return $roles;
{
return FALSE;
}
// if the role matches the WP role "vendor" we want to update
// if the capabilites matches yith_vendor we ant to update
if( $roles == $wp_role ) {
// set the um user
um_fetch_user( $user_id );
// update the user meta's role
update_user_meta( $user_id, 'role', 'vendor');
//there was a thought that maybe the WP user was not set -
// update wp user's role
// $wp_user_object = new WP_User( $user_id );
// $wp_user_object->set_role( $wp_role );
}
//reset the user so we won't override the current logged in user
um_reset_user( );
}
add_action('after_yith_vendor_form_submitted'
is a Wordpress hook? If not, then I am curious how you think that will work. Secondly, questions concerning third party plugins and/or themes are off topic, you better asked them at the developers own support forums.