BuddyDev

Search

[Resolved] limit friendship

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #19868

    Please share the complete modified code.

    Also, make sure you did not copy it from the email as the email gets entity encoded.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 285
    evillizard on #19872
     /**
     * Restrict sending request.
     *
     * @param bool $is_valid is valid request.
     * @param int $user_id sender user.
     *
     * @return bool
     */
    function buddydev_custom_restrict_sending_friendship_request( $is_valid, $user_id ) {
    
            // If a user has these many friends, they won't be able to send new request.
            $limit_on_friends_count = 1;
    
            // If a user has specified number of friends, can not send new request.
            if ( friends_get_friend_count_for_user( $user_id ) >= $limit_on_friends_count ) {
                    return false;
            }
    
            // for sent request count.
            global $wpdb;
            $bp = buddypress();
    
            $sent_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT('*') FROM {$bp->friends->table_name} WHERE initiator_user_id = %d", $user_id ) );
    
            // this is the maximum number of request a user can send
            // it includes accepted friendship(sent by the user too).
            $allowed_request_count = 1;// change it if you need.
            if ( $sent_count >= $allowed_request_count ) {
                    return false;
            }
    
            return $is_valid;
    }
    
    add_filter( 'bpf_restrictions_user_is_valid_sender', 'buddydev_custom_restrict_sending_friendship_request', 10, 2 );
    
    

    Yes i copied from the email you sent me

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #19874

    Please copy it from this post instead

    https://buddydev.com/support/forums/topic/limit-friendship/page/5/#post-19838

    And let me know if you still get the error.

    Thank you
    Brajesh

  • Participant
    Level: Master
    Posts: 285
    evillizard on #19893

    Thank you boss, it worked ..

    Should i close this thread as resolved? ..when i have another trouble/question ild open another thread??

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #19895

    Thank you. Yes, we should mark it as resolved.

    Also, for any new assistance, Please open new topic.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 285
    evillizard on #19896

    Aiit thanks boss

The topic ‘ [Resolved] limit friendship’ is closed to new replies.

This topic is: resolved