BuddyDev

Search

[Resolved] BuddyPress Limit Friendship Issue

  • Participant
    Level: Initiated
    Posts: 7
    FreeSpy on #8567

    Hi Brajesh,

    Did you post any example yet?

    Thanks and Regards,
    Richard

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #8581

    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
    Brajesh

  • Participant
    Level: Initiated
    Posts: 7
    FreeSpy on #8620

    Hi Brajesh,

    Thank you for your updates. But where do I put those code? I only see two php file under bp-limit-friendship folder, I did not see one php file called “bp-custom.php”. Any thoughts?

    Thank you!

    Regards,
    Richard

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #8626

    Hi 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
    Brajesh

  • Participant
    Level: Initiated
    Posts: 7
    FreeSpy on #8630
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #8632
    This reply has been marked as private.
  • Participant
    Level: Initiated
    Posts: 7
    FreeSpy on #8634

    Hi Brajesh,

    I am so sorry that I missed that open tag and close tag.

    Thank you very much! I appreciate your time and consideration for me!

    Regards,
    Richard

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #8636

    Hi 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
    Brajesh

  • Participant
    Level: Initiated
    Posts: 1
    Preethi Nagarajan on #11055

    Hi 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?

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #11059

    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.

This topic is: resolved