/** * @group friends_get_friendship_request_user_ids * @group friends_add_friend * @group friends_reject_friendship */ public function test_requests_on_reject() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); // request friendship friends_add_friend($u2, $u1); // get request count for user 1 and assert $requests = friends_get_friendship_request_user_ids($u1); $this->assertEquals(array($u2), $requests); // user 1 rejects friendship $old_user = get_current_user_id(); $this->set_current_user($u1); friends_reject_friendship(friends_get_friendship_id($u2, $u1)); // refetch request count for user 1 and assert $requests = friends_get_friendship_request_user_ids($u1); $this->assertEquals(array(), $requests); $this->set_current_user($old_user); }
/** * Get a user's friendship requests. * * Note that we return a 0 if no pending requests are found. This is necessary * because of the structure of the $include parameter in bp_has_members(). * * @param int $user_id ID of the user whose requests are being retrieved. * Defaults to displayed user. * @return array|int An array of user IDs if found, or a 0 if none are found. */ function bp_get_friendship_requests($user_id = 0) { if (!$user_id) { $user_id = bp_displayed_user_id(); } if (!$user_id) { return 0; } $requests = friends_get_friendship_request_user_ids($user_id); if (!empty($requests)) { $requests = implode(',', (array) $requests); } else { $requests = 0; } /** * Filters the total pending friendship requests for a user. * * @since 1.2.0 * * @param array|int An array of user IDs if found, or a 0 if none are found. */ return apply_filters('bp_get_friendship_requests', $requests); }
/** * Get a user's friendship requests * * Note that we return a 0 if no pending requests are found. This is necessary because of the * structure of the $include parameter in bp_has_members(). * * @param int $user_id Defaults to displayed user * @return mixed Returns an array of users if found, or a 0 if none are found */ function bp_get_friendship_requests($user_id = 0) { if (!$user_id) { $user_id = bp_displayed_user_id(); } if (!$user_id) { return 0; } $requests = friends_get_friendship_request_user_ids($user_id); if (!empty($requests)) { $requests = implode(',', (array) $requests); } else { $requests = 0; } return apply_filters('bp_get_friendship_requests', $requests); }
/** * Set up the admin bar * * @global obj $bp */ function setup_admin_bar() { global $bp; // Prevent debug notices $nxt_admin_nav = array(); // Menus for logged in user if (is_user_logged_in()) { // Setup the logged in user variables $user_domain = $bp->loggedin_user->domain; $friends_link = trailingslashit($user_domain . $this->slug); // Pending friend requests if ($count = count(friends_get_friendship_request_user_ids($bp->loggedin_user->id))) { $title = sprintf(__('Friends <span class="count">%s</span>', 'buddypress'), $count); $pending = sprintf(__('Pending Requests <span class="count">%s</span>', 'buddypress'), $count); } else { $title = __('Friends', 'buddypress'); $pending = __('No Pending Requests', 'buddypress'); } // Add the "My Account" sub menus $nxt_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => trailingslashit($friends_link)); // My Groups $nxt_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-friendships', 'title' => __('Friendships', 'buddypress'), 'href' => trailingslashit($friends_link)); // Requests $nxt_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-requests', 'title' => $pending, 'href' => trailingslashit($friends_link . 'requests')); } parent::setup_admin_bar($nxt_admin_nav); }
/** * Set up bp-friends integration with the WordPress admin bar. * * @since 1.5.0 * * @see BP_Component::setup_admin_bar() for a description of arguments. * * @param array $wp_admin_nav See BP_Component::setup_admin_bar() * for description. */ public function setup_admin_bar($wp_admin_nav = array()) { // Menus for logged in user. if (is_user_logged_in()) { // Setup the logged in user variables. $friends_link = trailingslashit(bp_loggedin_user_domain() . bp_get_friends_slug()); // Pending friend requests. $count = count(friends_get_friendship_request_user_ids(bp_loggedin_user_id())); if (!empty($count)) { $title = sprintf(_x('Friends <span class="count">%s</span>', 'My Account Friends menu', 'buddypress'), bp_core_number_format($count)); $pending = sprintf(_x('Pending Requests <span class="count">%s</span>', 'My Account Friends menu sub nav', 'buddypress'), bp_core_number_format($count)); } else { $title = _x('Friends', 'My Account Friends menu', 'buddypress'); $pending = _x('No Pending Requests', 'My Account Friends menu sub nav', 'buddypress'); } // Add the "My Account" sub menus. $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => $friends_link); // My Friends. $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-friendships', 'title' => _x('Friendships', 'My Account Friends menu sub nav', 'buddypress'), 'href' => $friends_link, 'position' => 10); // Requests. $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-requests', 'title' => $pending, 'href' => trailingslashit($friends_link . 'requests'), 'position' => 20); } parent::setup_admin_bar($wp_admin_nav); }
function bp_get_friendship_requests() { global $bp; return apply_filters('bp_get_friendship_requests', implode(',', (array) friends_get_friendship_request_user_ids($bp->loggedin_user->id))); }
/** * Set up bp-friends integration with the WordPress admin bar. * * @since BuddyPress (1.5.0) * * @see BP_Component::setup_admin_bar() for a description of arguments. * * @param array $wp_admin_nav See BP_Component::setup_admin_bar() * for description. */ public function setup_admin_bar($wp_admin_nav = array()) { $bp = buddypress(); // Menus for logged in user if (is_user_logged_in()) { // Setup the logged in user variables $user_domain = bp_loggedin_user_domain(); $friends_link = trailingslashit($user_domain . $this->slug); // Pending friend requests $count = count(friends_get_friendship_request_user_ids(bp_loggedin_user_id())); if (!empty($count)) { $title = sprintf(__('Friends <span class="count">%s</span>', 'buddypress'), number_format_i18n($count)); $pending = sprintf(__('Pending Requests <span class="count">%s</span>', 'buddypress'), number_format_i18n($count)); } else { $title = __('Friends', 'buddypress'); $pending = __('No Pending Requests', 'buddypress'); } // Add the "My Account" sub menus $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => trailingslashit($friends_link)); // My Groups $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-friendships', 'title' => __('Friendships', 'buddypress'), 'href' => trailingslashit($friends_link)); // Requests $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-requests', 'title' => $pending, 'href' => trailingslashit($friends_link . 'requests')); } parent::setup_admin_bar($wp_admin_nav); }