• Resolved Joe Bloggs

    (@joe-bloggs)


    Hi Guys,

    I wonder if you could help me out with this, I just can’t get my head around the logic behind the protected content with the shortcodes.

    Basically I have got the following scenario :

    User Roles :
    VISITOR ( visitor, not logged in, no role )
    SUPERVISOR ( supervisor )
    MANAGER ( manager )

    There is a contact page featuring the contact details. The following function is calling the print of the details :

    <?php $order = array('company', 'address_1', 'address_2', 'city', 'postcode', 'state', 'country');
                        $result = array();
                        foreach($order as $elem){
                        if($user_meta[$elem][0] != "")
                        $result[] = $user_meta[$elem][0];
                        }
                        echo implode(', ', $result);
                        ?>

    And this is what is supposed to happen :

    VISITOR cannot see any contact details, just a note that says “Sign In or Register to view contact details”

    SUPERVISOR can only see his own contact details and other supervisors contact details, but cannot see managers contact details.

    MANAGER can see everybodys contact details including his own.

    I’m not a php expert and trying to learn on this project. I’ve tried different variations with if(current_user_is), current_user_can, if user is logged in etc., + putting in the membership shortcodes [level-supervisor], [level-manager], but I just can’t make this thing work properly.

    Would you be please able to show me the exact code to set this up ??

    Many Thanks

    https://ww.wp.xz.cn/plugins/membership/

Viewing 1 replies (of 1 total)
  • Plugin Support Predrag – WPMU DEV Support

    (@wpmudev-support1)

    Hi @joe Bloggs,

    I hope you are well today and thank you for your question.

    The following code will work for visitors and managers. Just use it in place of the above code.

    <?php 
    
    	if( is_user_logged_in() ){
    
    	     $user = wp_get_current_user();
    
    	    if ( empty( $user ) ){
    
    		    $user_roles = (array) $user->roles;
    
    		    if( in_array( "manager", $user_roles ) {
    
    				$order = array('company', 'address_1', 'address_2', 'city', 'postcode', 'state', 'country');
    		        $result = array();
    		        foreach($order as $elem){
    		       	 if($user_meta[$elem][0] != "")
    		        	$result[] = $user_meta[$elem][0];
    		        }
    		        echo implode(', ', $result);
    		    }
    
    	    }else{
    	    	echo "Error occured getting user details.";
    	    }
        }else{
        	echo "Sign In or Register to view contact details";
        }
    ?>

    To make the supervisor functionality works i need to know how you are saving and retrieving manager and supervisor specific contact details or populating the $user_meta variable in the above code.

    Best Regards,
    Vinod Dalvi

Viewing 1 replies (of 1 total)

The topic ‘Protected Content Shortcodes Logic’ is closed to new replies.