@iuriem
Active 1 month ago
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
This is what I use now. Try it:
/** * Show content only to group members * Author: Iurie Malai */ add_shortcode( 'group', 'group_check_shortcode' ); // usage: [group id = YOUR_GROUP_ID_HERE] content [/group] function group_check_shortcode( $atts, $content = null ) { extract(shortcode_atts(array( 'id' => '', ), $atts)); if( groups_is_user_member( bp_loggedin_user_id(), $id ) ) { return do_shortcode( $content ); } if( $id == 1 ) { return '<p>This will be seen only by logged in members of group with id = 1. In my case this is the group with all members of my site</p>'; } else { $group = groups_get_group( array( 'group_id' => $id ) ); //Put your User Groups Page Slug in the next code row. //Usually this is "groups", but in my case it is different. $url = home_url( $path = 'USER_GROUPS_PAGE_SLUG_HERE/' . $group->slug . '/', $scheme = relative ); return '<p>This will be seen only by logged in members of group with id that you specified by shortcode in your page or post. This will show the group name: <a href="' . $url . '">' . $group->name . '</a>.</p>' ; } } /*---------------------------------------------------------*/
I was inspired a bit from here: https://svn.buddypress.org/branches/1.6/bp-groups/bp-groups-functions.php.
I did it:
add_shortcode( 'group', 'group_check_shortcode' ); // usage: [group slug = 'group_slug_here'] content [/group] function group_check_shortcode( $atts, $content = null ) { extract(shortcode_atts(array( 'slug' => '', ), $atts)); if( groups_is_user_member( bp_loggedin_user_id(), BP_Groups_Group::get_id_from_slug( $slug ))){ return do_shortcode($content); } return 'Restricted content!'; }
OR
add_shortcode( 'group', 'group_check_shortcode' ); // usage: [group slug = 'group_slug_here'] content [/group] function group_check_shortcode( $atts, $content = null ) { extract(shortcode_atts(array( 'slug' => '', ), $atts)); if( groups_is_user_member( bp_loggedin_user_id(), groups_get_id( $slug ))){ return do_shortcode($content); } return 'Restricted content!'; }
Viewing 3 replies - 1 through 3 (of 3 total)