-1

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( );
}
5
  • First of all, welcome to wpse. I do not mean to be nasty and I am maybe blonde but.. that hook you use 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.
    – Charles
    Commented Feb 10, 2016 at 5:44
  • @charles I understand what you mean regarding third party plugins but I am not asking to change any of the plugins. As a matter of fact, I think the plugins in their right are working as advertised. All I am trying to do is manage how they are all playing together and fill this one gap I have. Commented Feb 10, 2016 at 12:59
  • @charles I am only now learning this aspect of WordPress and the utilization of action hooks. Your question prompted me to dig deeper and I have come to understand the vendor does not at this time have a hook for this...THE GOOD news is they are working with me to create that hook and incorporate it into their plugin. Once that is in place the rest should follow nicely. Thanks! Commented Feb 10, 2016 at 16:40
  • Hey that is good news, I hoop the project will progress the way you want. Cheers.
    – Charles
    Commented Feb 10, 2016 at 21:18
  • The developer of the plugin have come through. It took a bit but I have been able to achieve what I was looking for. I appreciate al of the suggestions. Rich Commented Feb 27, 2016 at 17:32

1 Answer 1

0

Something you may use to accomplish this a plugin with a role and capability manager. You could then assign whatever permissions to either role you want, or create a new role altogether.

3
  • Got it---BUT---The role in WP is not the issue. Changing the role field for the Ultimate Members plugin is. The WP roles are fine but UM doesn't see the WP roles it manages it's own. I wouldn't have written the plugin this way but it is what it is and now I need to change that role in the database. Commented Feb 9, 2016 at 19:07
  • @user2197724 Maybe changing to another plugin, namely members from Justin Tadlock will solve your problem. Ps, read my comment below your question first please.
    – Charles
    Commented Feb 10, 2016 at 5:52
  • The developer of the plugin has come through. It took a bit but I have been able to achieve what I was looking for. I appreciate al of the suggestions. Rich Commented Feb 27, 2016 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.