Tagged: buddypress, member types
I am using member type plugin for Buddypress. I would like to display the member type (single and multiple) under the profile name in the profile page and members page. I tried the following code in bp-custom.php but the profile page is gone and an error message is returned. Please help me with the correct code to achieve the above requirement. Thanks in advance.
/**
* Get an array of member type labels based on member types.
*
* @param array $member_types member types.
*
* @return array
*/
function buddydev_get_member_type_labels( $member_types ) {$labels = array();
if ( ! $member_types ) {
return $labels;
}
foreach ( $member_types as $member_type ) {
$mtype_object = bp_get_member_type_object( $member_type );
if ( ! $mtype_object ) {
continue;
}$labels[] = $mtype_object->labels[‘singular_name’];
}return $labels;
}/**
* Print the list of member types of the user in member directory.
*/
function buddydev_show_member_type_labels() {
$user_id = bp_get_member_user_id();if ( ! $user_id ) {
return;// It should never happen but in case someone put the ac
}$labels = buddydev_get_member_type_labels( bp_get_member_type( $user_id, false ) );
echo join( ‘, ‘, $labels );
}add_action( ‘bp_directory_members_item’, ‘buddydev_show_member_type_labels’ );
function buddydev_show_member_type_for_displayed_user() {
if ( ! bp_is_user() ) {
return; // just a safeguard, it should never happen.
}$user_id = bp_displayed_user_id();
$labels = buddydev_get_member_type_labels( bp_get_member_type( $user_id, false ) );echo join( ‘, ‘, $labels );
}add_action( ‘bp_member_header_actions’, ‘buddydev_show_member_type_for_displayed_user’ );
Hi Ashwin,
Thank you for the question.Please use backticks(`) to post the code or link me to them. The above code is entity encoded and will cause fatal error.
Regards
BrajeshHere it is. Can you help me with the correct code. My site link is youtooart.com Your help is much appretiated.
` /**
* Get an array of member type labels based on member types.
*
* @param array $member_types member types.
*
* @return array
*/
function buddydev_get_member_type_labels( $member_types ) {$labels = array();
if ( ! $member_types ) {
return $labels;
}
foreach ( $member_types as $member_type ) {
$mtype_object = bp_get_member_type_object( $member_type );
if ( ! $mtype_object ) {
continue;
}$labels[] = $mtype_object->labels[‘singular_name’];
}return $labels;
}/**
* Print the list of member types of the user in member directory.
*/
function buddydev_show_member_type_labels() {
$user_id = bp_get_member_user_id();if ( ! $user_id ) {
return;// It should never happen but in case someone put the ac
}$labels = buddydev_get_member_type_labels( bp_get_member_type( $user_id, false ) );
echo join( ‘, ‘, $labels );
}add_action( ‘bp_directory_members_item’, ‘buddydev_show_member_type_labels’ );
function buddydev_show_member_type_for_displayed_user() {
if ( ! bp_is_user() ) {
return; // just a safeguard, it should never happen.
}$user_id = bp_displayed_user_id();
$labels = buddydev_get_member_type_labels( bp_get_member_type( $user_id, false ) );echo join( ‘, ‘, $labels );
}add_action( ‘bp_member_header_actions’, ‘buddydev_show_member_type_for_displayed_user’ ); `
Hello Ashwin,
Try the following code I have checked it with the BuddyPress Nouveau template and it shows member type details.
add_filter( 'bp_after_member_type_list_parse_args', function ( $args ) { if ( bp_is_user() || bp_is_members_directory() ) { $args['show_all'] = true; } return $args; } ); add_action( 'bp_directory_members_item', function () { bp_member_type_list( bp_get_member_user_id(), array( 'label' => array( 'plural' => __( 'Member Types', 'buddypress' ), 'singular' => __( 'Member Type', 'buddypress' ), ), 'list_element' => 'span', ) ); } );
Please let me know if it helps or not.
Regards
RaviHey Ravi, thank you for the message. I placed the code in the functions.php (child theme) but it did not reflect the member type under the user name neither on members directory or user profile page. Is there something I am doing wrong?
Site URL is : https://youtooart.com
Hello Ashwin,
Please check whether members-loop.php has been overridden by the theme. You can locate this file under Active Theme Directory > buddyPress > members > members-loop.php. If found please check whether the following section is there in the theme template or not.
<?php if ( bp_nouveau_member_has_extra_content() ) : ?> <div class="item-extra-content"> <?php bp_nouveau_member_extra_content() ; ?> </div><!-- .item-extra-content --> <?php endif ; ?>
Regards
RaviRavi, The code is not present in the members-loop.php
Hi Ashwin,
It seems you are using beehive theme. It has very limited number of hooks avaible.I will suggest connecting with the author for the proper hook.
Regards
BrajeshHey Brajesh and Ravi,
Thank you for your help. I contacted the author and got the file to get proper hooks and the code Ravi shared worked like a charm. Thanks again.
I would request an additional code so that the member types can also be seen on the user profile page under the profile name just as the code you shared allows me to see member type under the name on the members page.
Thanks in advance.
Hi Ashwin,
Thank you for the reply. I am glad that they helped.Please contact the theme author and ask them if there is any hook for the specific place you want to add the member type on user profile. If they provide any, Please share that. We will need a hook from the theme to show the member type on profile(we could use bp_profile_header_meta or similar hook but it is better if your theme author confirms it).
Regards
Brajesh
You must be logged in to reply to this topic.