• I’m using this bit of code here below to display a store button on user profiles, utilizing a vendor plugin.

    For user role allocation, I am using your User Role Editor.

    I notice the code doesn’t work for certain users that its supposed to work for, but does for others.

    I’m guessing the problem is in this line here:
    if ( $wcv_profile_info->roles[0] == "vendor" ) {

    I’m not familiar with PHP but I’m guessing the “0” has to do with position in the array. If I change that “0” to a “1”, the button is shown for the users it wasn’t showing for when set to “0”, but now those that were showing when it was set to “0” are not.

    Would this have something to do with the use of User Role Editor’s assigning of user roles juggling up the array?

    Is there a way to get it work so if a user contains the role “vendor” anywhere/at all it will work?

    add_action('bp_member_header_actions', 'wcvendors_pro_bp_member_header_actions');
    function wcvendors_pro_bp_member_header_actions(){
            $wcv_profile_id         = bp_displayed_user_id();
            $wcv_profile_info       = get_userdata( bp_displayed_user_id() );
            $wcv_profile_role       = implode( $wcv_profile_info->roles );
            $store_url              = WCVendors_Pro_Vendor_Controller::get_vendor_store_url( $wcv_profile_id );
            $sold_by                = '<span class="visit-store-btn"><a href="'.$store_url.'">Visit Store</a></span>';
    
            if ( $wcv_profile_info->roles[0] == "vendor" ) {
                    $vendor_name_message = get_the_author_meta( 'user_login' );
                    $current_user = wp_get_current_user();
                    echo $sold_by;
            }
    }
    • This topic was modified 2 years, 7 months ago by homelesshenry.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Is It User Role Editor Causing This Problem?’ is closed to new replies.