Tagged: BuddyPress Limit Friendship
Hi Richard,
Sorry for the delayed example.here is an example code to limit based on role
/** * Limit BuddyPress friendship based on WordPress roles * * @param int $count how many * @param int $user_id for the given user. * * @return int allowed no. of friends */ function buddydev_limit_friendship_count_based_on_role( $count, $user_id ) { if ( user_can( $user_id, 'manage_options' ) ) { //site admin $count = 100; // 100 friends allowed } elseif ( user_can( $user_id, 'moderate_comments' ) ) { //editor } elseif ( user_can( $user_id, 'edit_published_posts' ) ) { //authors } elseif ( user_can( $user_id, 'read' ) ) { //subscriber $count = 3; // only 3 allowed for subscribers } return $count; } add_filter( 'bp_limit_friendship_count', 'buddydev_limit_friendship_count_based_on_role', 10, 2 );
Hope it helps.
Regards
BrajeshHi Richard,
if there is no bp-custom.php, Please create on in the wp-content/plugins directory.Please see this for more details
https://buddydev.com/docs/guides/guides/buddypress-guides/what-is-bp-custom-php/Regards
BrajeshHi Richard,
No problem. I am glad I am able to assist you.Please avoid using closing php tag. It helps you avoid some notices in future(Output already send error).
Regards
BrajeshHi Brajesh,
I tried putting the above code in bp-custom.php. I could not use echo [example: echo “<script>console.log( ‘Working’ );</script>”;] to check the function step by step.
Due to this reason, I moved the code to functions.php
Is it possible to use the above code in functions.php?
Hi Preethi,
Please open a new topic with more details(version of wp/bp/theme) and I will assist promptly.Thank you
Brajesh
You must be logged in to reply to this topic.