Hide Fields From Logged Out Users

This topic contains 2 replies, has 3 voices, and was last updated by  Kiran 3 years, 4 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #438867

    Luca
    Full Member
    Post count: 23

    Hi! I’m trying to see if I can use your plugin instead of AWPCP – there are a few things which are MUCH better in yours!

    The website content will be mostly user-submitted listings. I need some fields to be visible only to logged in members, and completely hidden from unregistered visitors/bots/etc. For example, could contact info fields such as email for listings be visible only to registered members? Is there any easy way to do this? Also, since I just added almost a dozen of your plugins, I’d like to avoid fiddling with ANOTHER separate plugin to hide things…

    PS: I wonder if I’m missing anything obvious in the settings… I don’t want this to be admin-only, since all subscribers should see it.

    Thanks!

    #438874

    Guust
    Moderator
    Post count: 29970

    You will need a membership plugin to achieve what you describe.
    I doubt that there is any simple code that would hide fields completely for other than logged in users, but I will get a developer to have a look at your question too, just in case.
    Thanks

    #438881

    Kiran
    Moderator
    Post count: 7069

    Hello Luca,

    Add following code snippet to hide fields from guest users.

    
    
    function _gd_custom_setup_guest_hide_field() {
    	if ( is_user_logged_in() ) {
    		return;
    	}
    
    	$fields = array();
    	$fields[] = 'geodir_contact';
    	$fields[] = 'geodir_email';
    	// ADD MORE FIELDS HERE
    
    	if ( ! empty( $fields ) ) {
    		foreach ( $fields as $field ) {
    			add_filter( 'geodir_show_' . $field, '_gd_custom_guest_hide_field', 10, 2 );
    		}
    	}
    }
    add_filter( 'init', '_gd_custom_setup_guest_hide_field', 10 );
    
    function _gd_custom_guest_hide_field( $html, $params ) {
    	if ( ! is_user_logged_in() ) {
    		$html = '';
    	}
    	return $html;
    }

    Currently it is working with phone & email fields but you can add more fields at “// ADD MORE FIELDS HERE”.

    Thanks,
    Kiran

Viewing 3 posts - 1 through 3 (of 3 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket