Home Forums WC Vendors Pro Support New role vs. vendor role

NOTICE: We've Moved to a Ticket System for Support

As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system.  This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.

For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.

If you are a WC Vendors Pro customer please open a support ticket here. 

If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.

The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.

https://docs.wcvendors.com/

Thank you to all of our customers!

 

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #34741
    Anna
    Member

    Ben,
    If I am to create a new user role that has all of the vendor role capabilities…. will this new role behave in an identical fashion to “vendor” which using wc vendors?

    I am not sure if there are any places within the plugin that look specifically for the role VENDOR, and therefore the new role will not work in that case.

    Thank you!

    #34742
    WC Vendors Support
    Participant

    Everywhere in the plugin looks for the role name to be ‘vendor’ 🙂

    We did add a filter recently, you can see the code for it here: https://github.com/wcvendors/wcvendors/commit/45211c4112ba45747462ed37769a098e11aea903 that would allow ‘other’ roles to be vendor roles, too.

    #34749
    Anna
    Member

    Thanks, Ben. I now need to figure out what to do with this…

    Is this filter added to the current WCV?

    Do I then need to make something like this??:

    add_filter( 'wcvendors_vendor_roles','custom_wcvendors_vendor_roles',10, 1);
    function custom_wcvendors_vendor_roles () {
    if (is_object($user)) { 
    			$is_vendor = is_array( $user->roles ) ? in_array( 'NEWROLE', $user->roles ) : false;
                             foreach ($vendor_roles as $role ) {
                                $is_vendor = is_array( $user->roles ) ? in_array( $role , $user->roles ) : false;
                                  }
                } else { 
                        $is_vendor = false;
                       }
    }

    I hope I am at least on the right track… 😛

    #34750
    WC Vendors Support
    Participant

    Not even close! 🙂

    $vendor_roles = apply_filters( 'wcvendors_vendor_roles', array( 'vendor') );

    That shows you that it returns an array with only vendor in it array( 'vendor'). So, your filter should return an array with the vendor role, and the other role. That’s it! 🙂

    #34777
    Anna
    Member

    Oh.. well you can leave it to me to make something way more complicated that it actually is. 😛

    I’ll work on this again and check back with you. I cannot actually test this code and see if it works before implementing it on the site … so I’ll need to try and get it right. 😉

    Thanks, Ben.

    #34790
    Anna
    Member

    Ok…
    How does this look?

    function custom_wcvendors_vendor_roles ($vendor_roles) {
    
       $new_vendor_role = array('newrole');
    
       $vendor_roles = array_merge ($vendor_roles,$new_vendor_role); 
    
       return $vendor_roles;
    
    }
    
    add_filter ('wcvendors_vendor_roles','custom_wcvendors_vendor_roles');
    #34791
    WC Vendors Support
    Participant

    I like this:

    add_filter('wcvendors_vendor_roles', 'custom_wcvendors_vendor_roles');
    function custom_wcvendors_vendor_roles(){
    	$roles = array('vendor', 'newrole');
    	return $roles;
    }

    Tested? No. But it *should* work. 🙂 This ASSumes (read the first three letters carefully ;)) that your new vendor role is ‘newrole’. Our vendor role is ‘vendor’ which we call ‘Vendor”. The ‘Pending Vendor’ role is ‘pending’. So if your ‘New Vendor Role’ is called ‘newrole’ then all is good.

    #34792
    Anna
    Member

    Ahhh ok… I ASSumed that I needed to change the array completely and merge the two. 😉 I also thought I needed $vendor_roles instead of $roles.

    Alright- well I gave it a shot. I won’t be naming the new role ‘newrole’, no, but I know I need to add the actual name there.

    Thank you again, Ben. 🙂

    #34793
    WC Vendors Support
    Participant

    It can be $whatever_you_want. 🙂 What is important is you return $whatever_you_want; because what you return is $what_is_used 🙂 Some devs use $args = whatever; then return $args; because they like to return arguments, or some use $var whatever doesnt matter, just so long as what you are returning from the function is what you want the filter to have. 🙂

    #34796
    Anna
    Member

    OK, I understand. I had thought it needed to line up with what Jamie had in the github filter you linked earlier.
    Master Po, Young Grasshopper is learning. 😉

    #36718
    Anna
    Member

    Ben- quick question.

    In the scenario we discussed above, with the following code:

    add_filter('wcvendors_vendor_roles', 'custom_wcvendors_vendor_roles');
    function custom_wcvendors_vendor_roles(){
    	$roles = array('vendor', 'newrole');
    	return $roles;
    }

    The member role name I will be assigning is called “Gold”, but the role is actually “wpfs_gold” when I edit it in the User Role Editor. So in the code above, would I insert “wpfs_gold” or the name “Gold”? I am assuming the former (wpfs_gold), but I just want to be sure, since testing this involves a transaction. 😉

    If I can get this configured properly, I will be able to share a nice way for users of WC Vendors Pro to add a paid membership plan to obtain vendor access.

    Thank you!

    #36719
    WC Vendors Support
    Participant

    For the PHP portion of it, you refer to the role as the actual role name. If the role name is wpfs_gold that’s what you’d put in the code! Look forward to seeing what you’re working on! 🙂

    #36721
    Anna
    Member

    Thanks, Ben. Hopefully this’ll work out and , of course, I’ll share what I’ve done in case it can help others.

    #36729
    Anna
    Member

    So far most functions seem to be working fine- BUT…
    The user who subscribes and is given the role wpfs_gold (which I synced with ‘vendor’ role using the code above) can see ALL vendors’ media in the media library. Not just their own photos.

    I was careful to duplicate the vendor capabilities and assign them to wpfs_gold using user role editor, and have double-checked to make sure they are identical.

    Any ideas what may be causing them to be able to view all media?

    #36730
    Anna
    Member

    Yikes… no I do not think this code chunk is working. It is not accepting this role as a vendor. Ok… back to square one…

Viewing 15 posts - 1 through 15 (of 15 total)
  • The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.