BuddyDev

Search

[Resolved] Multiple Member Types in same directory

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21314

    Hi Brajesh,

    Another question in a new topic…

    I want to display PMP Pro Membership Levels on BuddyPress Directory profile cards/informations, but nobody gets there, theme developer and PMP Pro support don’t want to make me a code snippet to do this (if you can do this, you’re the best). Theme developer make me a code snippet to display member type on this, and it works fine.

    So, I thought is it maybe possible to make a member type x premium (so I will have member type x and member type x premium) and synchronize it with my PMP Pro membership premium level, and have the same directory for both member types ? Like this I will be able to display member type premium on BP Directory profile informations.

    Do you understand all…?

    Thanks,
    Joss

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #21317

    Hi Joss,
    Thank you for the question.

    1. Showing PMPro level, it is doable.
    2. Listing users from 2 member types in one directory:- BuddyPress member types directory does not allow it. You can use our shortcode to achieve this though.

    For 1, I will look test install for PMPro a bit late today and post the code.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21326

    Thank you Brajesh 🙂

    Here the code snippet of my theme developer, it can help you…
    The first function is to display member type on BuddyPress directory profile informations AND user profile page. The second is to display Location from xprofile location, but I don’t use it. Theme developer sayed me : “Please also note that you don’t need to edit our snippet to achieve this as we recommend to add a new function to the following theme action: gwangi_buddypress_member_xprofile_custom_fields

    Code I use to display Member Type and Location that I don’t use :

    add_action( 'gwangi_buddypress_member_xprofile_custom_fields', 'gwangi_buddypress_member_type', 10 );
    add_action( 'gwangi_buddypress_member_xprofile_custom_fields', 'gwangi_buddypress_member_type', 10 );
    
    function gwangi_buddypress_member_type() {
    	if ( bp_is_user() ) {
    		$user_id = bp_get_displayed_user()->id;
    	}
    	else {
    		$user_id = bp_get_member_user_id();
    	}
    
    	$member_type_name = bp_get_member_type( $user_id );
    	$member_type = bp_get_member_type_object( $member_type_name );
    	?>
    	<div class="bp-member-xprofile-custom-field bp-member-type"><?php echo $member_type->labels['singular_name']; ?></div>
    	<?php
    }
    
    if ( ! function_exists( 'gwangi_bp_xprofile_location_member_location' ) ) :
    	/**
    	 * Print the HTML for BP xProfile Location Field in the BP Member Directory.
    	 *
    	 * @since 1.1.9
    	 */
    	function gwangi_bp_xprofile_location_member_location() {
    		if ( function_exists( 'xprofile_get_field_data' ) ) :
    			$location     = xprofile_get_field_data( 'Mon adresse', bp_get_member_user_id() );
    			$allowed_html = array(
    				'a' => array(
    					'href' => array(),
    					'rel'  => array(),
    				),
    			);
    
    			if ( ! empty( $location ) ) :
    				$location_parts = explode( ', ', $location );
    				if ( ! empty( $location_parts[1] ) ) : ?>
    					<div class="bp-member-xprofile-custom-field bp-member-location"><?php echo wp_kses( $location_parts[1], $allowed_html ); ?></div>
    					<?php
    				endif;
    			endif;
    		endif;
    	}
    endif;
  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #21351

    Hi Joss,
    Please try adding this in your bp-custom.php

    
    
    /**
     * Print user's active membership level.
     */
    function buddydev_show_pmpro_membership_level_in_dir() {
    	// for the logged in user.
    	$level = pmpro_getMembershipLevelForUser( bp_get_member_user_id() );
    
    	if ( ! $level ) {
    		return;
    	}
    
    	echo '<div class="bp-member-xprofile-custom-field bp-member-level">' . $level->name . '</div>';
    }
    
    add_action( 'gwangi_buddypress_member_xprofile_custom_fields', 'buddydev_show_pmpro_membership_level_in_dir', 10 );
    

    Does it work for you?

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21375

    Brajesh, you’re the best !!

    It works fine !

    If I want to display only one membership level, do you know how can I do this ?

    Thanks,
    Joss

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21376

    Brajesh,

    Your code display also membership level on BP profile page, and it not display the right level, do you know why ?

    Thanks,
    Joss

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #21394

    Hi Joss,
    I am using the hook provided by you in the previous reply

    
    gwangi_buddypress_member_xprofile_custom_fields
    

    Please ask the theme developer for the correct hook or you can use the updated code like this

    
    
    function buddydev_show_pmpro_membership_level_in_dir() {
    	if ( ! bp_is_members_directory() ) {
    		return;
    	}
    	// for the logged in user.
    	$level = pmpro_getMembershipLevelForUser( bp_get_member_user_id() );
    
    	if ( ! $level ) {
    		return;
    	}
    
    	echo '<div class="bp-member-xprofile-custom-field bp-member-level">' . $level->name . '</div>';
    }
    
    add_action( 'gwangi_buddypress_member_xprofile_custom_fields', 'buddydev_show_pmpro_membership_level_in_dir', 10 );
    

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21421

    Yes, it works fine like this !!

    Do you know if I can display only level 1 or level 2 ?

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #21449

    Hi Joss,
    I am sorry, But I do not understand your last question.

    1. You can skip using the membership level.

    If you are looking to show users belonging to level 1 from pmpro, I am sorry, I won’t be of much help.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 34
    Joss Luberia on #21481

    Hi Brajesh,

    I want to display only Level 2, and not level 1 or 3.

    PMP Pro support team give me a code to display only the level I want on BP Profile page and I think you can adjust your code to make the same feature on BP directory. Look at the function $only_show on line 16.

    /*
    Remove "Membership Level" on the BuddyPress profile page, and instead only show the membership level name
    */
    
    function my_pmpro_bp_show_level_on_bp_profile() {
    	
    	if ( !function_exists('pmpro_getMembershipLevelForUser') ) {
    		return;
    	}
    	
    	$level = pmpro_getMembershipLevelForUser(bp_displayed_user_id());
    	
    	$show_level = get_option('pmpro_bp_show_level_on_bp_profile');
    	
    	//Only show for levels 1, and 2.
    	$only_show = array(2);
    	
    	if( $show_level == 'yes' && !empty( $level ) && in_array($level->id, $only_show)) {
    	?>
    	<div class="pmpro_bp_show_level_on_bp_profile">
    		<strong><?php echo $level->name; ?> </strong>
    	</div>
    	<?php
    	}
    }
    remove_filter( 'bp_profile_header_meta', 'pmpro_bp_show_level_on_bp_profile' );
    add_filter( 'bp_profile_header_meta', 'my_pmpro_bp_show_level_on_bp_profile' );

    Can you adjust your code to show only level 2 on my member directory ?

    Thank you Brajesh,
    Joss

The topic ‘ [Resolved] Multiple Member Types in same directory’ is closed to new replies.

This topic is: resolved