/**
 * Catch and process Remove Friendship requests.
 *
 * @since 1.0.1
 */
function friends_action_remove_friend()
{
    if (!bp_is_friends_component() || !bp_is_current_action('remove-friend')) {
        return false;
    }
    if (!($potential_friend_id = (int) bp_action_variable(0))) {
        return false;
    }
    if ($potential_friend_id == bp_loggedin_user_id()) {
        return false;
    }
    $friendship_status = BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $potential_friend_id);
    if ('is_friend' == $friendship_status) {
        if (!check_admin_referer('friends_remove_friend')) {
            return false;
        }
        if (!friends_remove_friend(bp_loggedin_user_id(), $potential_friend_id)) {
            bp_core_add_message(__('Friendship could not be canceled.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Friendship canceled', 'buddypress'));
        }
    } elseif ('is_friends' == $friendship_status) {
        bp_core_add_message(__('You are not yet friends with this user', 'buddypress'), 'error');
    } else {
        bp_core_add_message(__('You have a pending friendship request with this user', 'buddypress'), 'error');
    }
    bp_core_redirect(wp_get_referer());
    return false;
}
/**
 * Filter BP_User_Query::populate_extras to add confirmed friendship status.
 *
 * Each member in the user query is checked for confirmed friendship status
 * against the logged-in user.
 *
 * @since 1.7.0
 *
 * @global WPDB $wpdb WordPress database access object.
 *
 * @param BP_User_Query $user_query   The BP_User_Query object.
 * @param string        $user_ids_sql Comma-separated list of user IDs to fetch extra
 *                                    data for, as determined by BP_User_Query.
 */
function bp_friends_filter_user_query_populate_extras(BP_User_Query $user_query, $user_ids_sql)
{
    global $wpdb;
    // Stop if user isn't logged in.
    if (!($user_id = bp_loggedin_user_id())) {
        return;
    }
    $maybe_friend_ids = wp_parse_id_list($user_ids_sql);
    foreach ($maybe_friend_ids as $friend_id) {
        $status = BP_Friends_Friendship::check_is_friend($user_id, $friend_id);
        $user_query->results[$friend_id]->friendship_status = $status;
        if ('is_friend' == $status) {
            $user_query->results[$friend_id]->is_friend = 1;
        }
    }
}
function example_friends_ajax_addremove_friend()
{
    global $bp;
    if ('is_friend' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
        if (!friends_remove_friend($bp->loggedin_user->id, $_POST['fid'])) {
            echo __('Friendship could not be canceled.', 'bp-component');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'bp-component') . '" href="' . $bp->loggedin_user->domain . $bp['friends']['slug'] . '/add-friend/' . $_POST['fid'] . '">' . __('Add Friend', 'bp-component') . '</a>';
        }
    } else {
        if ('not_friends' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
            if (!friends_add_friend($bp->loggedin_user->id, $_POST['fid'])) {
                echo __('Friendship could not be requested.', 'bp-component');
            } else {
                echo '<a href="' . $bp->loggedin_user->domain . $bp['friends']['slug'] . '" class="requested">' . __('Friendship Requested', 'bp-component') . '</a>';
            }
        } else {
            echo __('Request Pending', 'bp-component');
        }
    }
    return false;
}
function wpmudev_chat_buddypress_member_header_actions()
{
    global $bp, $members_template, $wpmudev_chat, $current_user;
    if ($bp->loggedin_user->id === bp_displayed_user_id()) {
        return;
    }
    //if (!is_object('BP_Friends_Friendship')) return;
    if (!bp_is_active('friends')) {
        return;
    }
    if (!class_exists('BP_Friends_Friendship')) {
        return $is_friend_ret = BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), bp_displayed_user_id());
    }
    //echo "is_friend_ret[". $is_friend_ret ."]<br />";
    // Set this so when we get to wp_footer it knows we need to load the JS/CSS for the Friends display.
    $wpmudev_chat->_chat_plugin_settings['blocked_urls']['front'] = false;
    if (BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), bp_displayed_user_id()) == 'is_friend' || $bp->loggedin_user->is_site_admin == true) {
        $content = '';
        $content .= '<div id="wpmudev-chat-now-button-' . bp_displayed_user_id() . '" class="generic-button wpmudev-chat-now-button">';
        $friends_status = wpmudev_chat_get_friends_status($bp->loggedin_user->id, bp_displayed_user_id());
        if (!empty($friends_status[0])) {
            $friends_status = $friends_status[0];
        } else {
            $friends_status = '';
        }
        $friend_data = wpmudev_chat_get_chat_status_data(bp_displayed_user_id(), $friends_status);
        //echo "friend_data<pre>"; print_r($friend_data); echo "</pre>";
        $friend_status_display = $friend_data['icon'] . $friend_data['label'];
        if (!empty($friend_data['href'])) {
            $content .= '<a class="button wpmudev-chat-button ' . $friend_data['href_class'] . '" title="' . $friend_data['href_title'] . '" href="#" rel="' . $friend_data['href'] . '">' . $friend_status_display . '</a>';
        } else {
            $content .= '<a onclick="return false;" disabled="disabled" class="wpmudev-chat-button ' . $friend_data['href_class'] . '" title="' . $friend_data['href_title'] . '" href="#">' . $friend_status_display . '</a>';
        }
        $content .= '</div>';
        echo $content;
    }
}
function friends_ajax_addremove_friend()
{
    global $bp;
    if ('is_friend' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
        check_ajax_referer('friends_remove_friend');
        if (!friends_remove_friend($bp->loggedin_user->id, $_POST['fid'])) {
            echo __("Friendship could not be canceled.", 'buddypress');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'buddypress') . '" href="' . wp_nonce_url($bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $_POST['fid'], 'friends_add_friend') . '">' . __('Add Friend', 'buddypress') . '</a>';
        }
    } else {
        if ('not_friends' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
            check_ajax_referer('friends_add_friend');
            if (!friends_add_friend($bp->loggedin_user->id, $_POST['fid'])) {
                echo __("Friendship could not be requested.", 'buddypress');
            } else {
                echo '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '" class="requested">' . __('Friendship Requested', 'buddypress') . '</a>';
            }
        } else {
            echo __('Request Pending', 'buddypress');
        }
    }
    return false;
}
Exemple #6
0
function bp_dtheme_ajax_addremove_friend()
{
    global $bp;
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if ('is_friend' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
        check_ajax_referer('friends_remove_friend');
        if (!friends_remove_friend($bp->loggedin_user->id, $_POST['fid'])) {
            echo __("Friendship could not be canceled.", 'buddypress');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'buddypress') . '" href="' . nxt_nonce_url($bp->loggedin_user->domain . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend') . '">' . __('Add Friend', 'buddypress') . '</a>';
        }
    } else {
        if ('not_friends' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
            check_ajax_referer('friends_add_friend');
            if (!friends_add_friend($bp->loggedin_user->id, $_POST['fid'])) {
                echo __("Friendship could not be requested.", 'buddypress');
            } else {
                echo '<a href="' . $bp->loggedin_user->domain . bp_get_friends_slug() . '/requests" class="requested">' . __('Friendship Requested', 'buddypress') . '</a>';
            }
        } else {
            echo __('Request Pending', 'buddypress');
        }
    }
    return false;
}
/**
 * Friend/un-friend a user via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_legacy_theme_ajax_addremove_friend()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Cast fid as an integer
    $friend_id = (int) $_POST['fid'];
    // Trying to cancel friendship
    if ('is_friend' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $friend_id)) {
        check_ajax_referer('friends_remove_friend');
        if (!friends_remove_friend(bp_loggedin_user_id(), $friend_id)) {
            echo __('Friendship could not be canceled.', 'buddypress');
        } else {
            echo '<a id="friend-' . esc_attr($friend_id) . '" class="add" rel="add" title="' . __('Add Friend', 'buddypress') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend') . '">' . __('Add Friend', 'buddypress') . '</a>';
        }
        // Trying to request friendship
    } elseif ('not_friends' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $friend_id)) {
        check_ajax_referer('friends_add_friend');
        if (!friends_add_friend(bp_loggedin_user_id(), $friend_id)) {
            echo __(' Friendship could not be requested.', 'buddypress');
        } else {
            echo '<a id="friend-' . esc_attr($friend_id) . '" class="remove" rel="remove" title="' . __('Cancel Friendship Request', 'buddypress') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $friend_id . '/', 'friends_withdraw_friendship') . '" class="requested">' . __('Cancel Friendship Request', 'buddypress') . '</a>';
        }
        // Trying to cancel pending request
    } elseif ('pending' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $friend_id)) {
        check_ajax_referer('friends_withdraw_friendship');
        if (friends_withdraw_friendship(bp_loggedin_user_id(), $friend_id)) {
            echo '<a id="friend-' . esc_attr($friend_id) . '" class="add" rel="add" title="' . __('Add Friend', 'buddypress') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend') . '">' . __('Add Friend', 'buddypress') . '</a>';
        } else {
            echo __("Friendship request could not be cancelled.", 'buddypress');
        }
        // Request already pending
    } else {
        echo __('Request Pending', 'buddypress');
    }
    exit;
}
Exemple #8
0
/**
 * Friend/un-friend a user via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_dtheme_ajax_addremove_friend()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if ('is_friend' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $_POST['fid'])) {
        check_ajax_referer('friends_remove_friend');
        if (!friends_remove_friend(bp_loggedin_user_id(), $_POST['fid'])) {
            echo __('Friendship could not be canceled.', 'logicalboneshug');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'logicalboneshug') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend') . '">' . __('Add Friend', 'logicalboneshug') . '</a>';
        }
    } elseif ('not_friends' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $_POST['fid'])) {
        check_ajax_referer('friends_add_friend');
        if (!friends_add_friend(bp_loggedin_user_id(), $_POST['fid'])) {
            echo __(' Friendship could not be requested.', 'logicalboneshug');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="remove" rel="remove" title="' . __('Cancel Friendship Request', 'logicalboneshug') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . (int) $_POST['fid'] . '/', 'friends_withdraw_friendship') . '" class="requested">' . __('Cancel Friendship Request', 'logicalboneshug') . '</a>';
        }
    } elseif ('pending' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), (int) $_POST['fid'])) {
        check_ajax_referer('friends_withdraw_friendship');
        if (friends_withdraw_friendship(bp_loggedin_user_id(), (int) $_POST['fid'])) {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'logicalboneshug') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend') . '">' . __('Add Friend', 'logicalboneshug') . '</a>';
        } else {
            echo __("Friendship request could not be cancelled.", 'logicalboneshug');
        }
    } else {
        echo __('Request Pending', 'logicalboneshug');
    }
    exit;
}
Exemple #9
0
/**
 * Get the friendship status of two friends.
 *
 * Will return 'is_friends', 'not_friends', 'pending' or 'awaiting_response'.
 *
 * @param int $user_id ID of the first user.
 * @param int $possible_friend_id ID of the other user.
 * @return string Friend status of the two users.
 */
function friends_check_friendship_status($user_id, $possible_friend_id)
{
    global $members_template;
    // check the BP_User_Query first
    // @see bp_friends_filter_user_query_populate_extras()
    if (!empty($members_template->in_the_loop)) {
        if (isset($members_template->member->friendship_status)) {
            return $members_template->member->friendship_status;
            // make sure that the friends BP_User_Query was registered before assuming
            // status as 'not_friends'
        } elseif (has_filter('bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras')) {
            return 'not_friends';
        }
    }
    return BP_Friends_Friendship::check_is_friend($user_id, $possible_friend_id);
}
function bp_legacy_theme_ajax_my_get_friendship_status()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    error_log("og get friendship status " . groups_get_id("students"));
    $myretval = array();
    // Cast gid as integer
    $my_friend_ids = $_POST['fids'];
    error_log("og friend status:" . print_r($my_group_ids, true));
    for ($myidx = 0; $myidx < count($my_friend_ids); $myidx++) {
        $my_friend_id = (int) $my_friend_ids[$myidx];
        error_log("og friend id:" . $my_friend_id . " ");
        $bp_loggedin_user_id = bp_loggedin_user_id();
        $my_is_friend = 'is_friend' == BP_Friends_Friendship::check_is_friend($bp_loggedin_user_id, $my_friend_id);
        $htmlstrtoreturn = bp_get_add_friend_button($my_friend_id, $my_is_friend);
        $myretval[$my_friend_ids[$myidx]] = $htmlstrtoreturn;
    }
    echo json_encode($myretval);
    exit;
}
/**
 * Check if the current profile a user is on is a friend or not
 *
 * @since BuddyBoss 2.0
 */
function buddyboss_is_my_friend($id = null)
{
    global $bp;
    if ($id === null) {
        $id = $bp->displayed_user->id;
    }
    return 'is_friend' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $id);
}
/**
 * Get the friendship status of two friends.
 *
 * Will return 'is_friends', 'not_friends', 'pending' or 'awaiting_response'.
 *
 * @since 1.2.0
 *
 * @param int $user_id            ID of the first user.
 * @param int $possible_friend_id ID of the other user.
 * @return string Friend status of the two users.
 */
function friends_check_friendship_status($user_id, $possible_friend_id)
{
    global $members_template;
    // Check the BP_User_Query first
    // @see bp_friends_filter_user_query_populate_extras().
    if (!empty($members_template->in_the_loop)) {
        if (isset($members_template->member->friendship_status)) {
            return $members_template->member->friendship_status;
        }
    }
    return BP_Friends_Friendship::check_is_friend($user_id, $possible_friend_id);
}
Exemple #13
0
function bpdd_import_users_friends()
{
    $users = bpdd_get_random_users_ids(50);
    for ($con = 0, $i = 0; $i < 100; $i++) {
        $user_one = $users[array_rand($users)];
        $user_two = $users[array_rand($users)];
        if (BP_Friends_Friendship::check_is_friend($user_one, $user_two) == 'not_friends') {
            // make them friends
            if (friends_add_friend($user_one, $user_two, true)) {
                $con++;
            }
        }
    }
    return $con;
}
/**
 * Catch the 'to' email address of sent email notifications, and hook message filter if necessary
 *
 * This function is necessary because the groups_notification_group_invites_message
 * filter doesn't receive easily parsable info about the invitee.
 *
 * @since 1.0.22
 */
function invite_anyone_group_invite_maybe_filter_invite_message($to)
{
    if (!bp_is_active('friends')) {
        return $to;
    }
    $invited_user = get_user_by('email', $to);
    $friendship_status = BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $invited_user->ID);
    if ('is_friend' !== $friendship_status) {
        add_action('groups_notification_group_invites_message', 'invite_anyone_group_invite_email_message', 10, 7);
    }
    return $to;
}
 function bp_displayed_user_is_friend()
 {
     global $bp;
     $friend_privacy_enable = get_option('tn_wpmu_friend_privacy_status');
     $friend_privacy_redirect = get_option('tn_wpmu_friend_privacy_redirect');
     if ($friend_privacy_enable == "enable") {
         if (bp_is_user_activity() || bp_is_user_profile() || bp_is_user()) {
             if ('is_friend' != BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $bp->displayed_user->id) && bp_loggedin_user_id() != bp_displayed_user_id()) {
                 if (!is_super_admin(bp_loggedin_user_id())) {
                     if ($friend_privacy_redirect == '') {
                         bp_core_redirect($bp->root_domain);
                     } else {
                         bp_core_redirect($friend_privacy_redirect);
                     }
                 }
             }
         }
     }
     //enable
 }
 /**
  * @group check_is_friend
  */
 public function test_check_is_friend_is_friend()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     friends_add_friend($u1, $u2, true);
     $this->assertEquals('is_friend', BP_Friends_Friendship::check_is_friend($u1, $u2));
 }
Exemple #17
0
function friends_check_friendship($user_id, $possible_friend_id)
{
    global $bp;
    if ('is_friend' == BP_Friends_Friendship::check_is_friend($user_id, $possible_friend_id)) {
        return true;
    }
    return false;
}
function bp_add_friend_button($potential_friend_id = false)
{
    global $bp, $friends_template;
    if (is_user_logged_in()) {
        if (!$potential_friend_id && $friends_template->friendship->friend) {
            $potential_friend_id = $friends_template->friendship->friend->id;
        } else {
            if (!$potential_friend_id && !$friends_template->friendship->friend) {
                $potential_friend_id = $bp->displayed_user->id;
            }
        }
        if ($bp->loggedin_user->id == $potential_friend_id) {
            return false;
        }
        $friend_status = BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $potential_friend_id);
        echo '<div class="friendship-button ' . $friend_status . '" id="friendship-button-' . $potential_friend_id . '">';
        if ('pending' == $friend_status) {
            echo '<a class="requested" href="' . $bp->loggedin_user->domain . $bp->friends->slug . '">' . __('Friendship Requested', 'buddypress') . '</a>';
        } else {
            if ('is_friend' == $friend_status) {
                echo '<a href="' . wp_nonce_url($bp->loggedin_user->domain . $bp->friends->slug . '/remove-friend/' . $potential_friend_id, 'friends_remove_friend') . '" title="' . __('Cancel Friendship', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="remove" class="remove">' . __('Cancel Friendship', 'buddypress') . '</a>';
            } else {
                echo '<a href="' . wp_nonce_url($bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $potential_friend_id, 'friends_add_friend') . '" title="' . __('Add Friend', 'buddypress') . '" id="friend-' . $potential_friend_id . '" rel="add" class="add">' . __('Add Friend', 'buddypress') . '</a>';
            }
        }
        echo '</div>';
    }
}
/**
 * Check if the User Can access Friends only privacy
 * @param type $component_type
 * @param type $component_id
 * @param type $user_id
 * @return type
 */
function mpp_check_friends_access($component_type, $component_id, $user_id = null)
{
    $allow = false;
    if (is_super_admin() || $component_id == $user_id || bp_is_active('friends') && 'is_friend' == BP_Friends_Friendship::check_is_friend($user_id, $component_id)) {
        $allow = true;
    }
    return apply_filters('mpp_check_friends_access', $allow, $component_type, $component_id, $user_id);
}
function friends_check_friendship_status($user_id, $possible_friend_id)
{
    return BP_Friends_Friendship::check_is_friend($user_id, $possible_friend_id);
}
Exemple #21
0
function friends_check_friendship_status( $user_id, $possible_friend_id ) {
	/* Returns - 'is_friend', 'not_friends', 'pending' */
	return BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id );
}