本文整理汇总了PHP中friends_add_friend函数的典型用法代码示例。如果您正苦于以下问题:PHP friends_add_friend函数的具体用法?PHP friends_add_friend怎么用?PHP friends_add_friend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了friends_add_friend函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: friends_action_add_friend
/**
* Catch and process friendship requests.
*
* @since 1.0.1
*/
function friends_action_add_friend()
{
if (!bp_is_friends_component() || !bp_is_current_action('add-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 ('not_friends' == $friendship_status) {
if (!check_admin_referer('friends_add_friend')) {
return false;
}
if (!friends_add_friend(bp_loggedin_user_id(), $potential_friend_id)) {
bp_core_add_message(__('Friendship could not be requested.', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Friendship requested', 'buddypress'));
}
} elseif ('is_friend' == $friendship_status) {
bp_core_add_message(__('You are already friends with this user', 'buddypress'), 'error');
} else {
bp_core_add_message(__('You already have a pending friendship request with this user', 'buddypress'), 'error');
}
bp_core_redirect(wp_get_referer());
return false;
}
示例2: test_get_hidden_field_types_for_user_friends
public function test_get_hidden_field_types_for_user_friends()
{
$duser = $this->factory->user->create();
$cuser = $this->factory->user->create();
friends_add_friend($duser, $cuser, true);
$old_current_user = bp_loggedin_user_id();
$this->set_current_user($cuser);
$this->assertEquals(array('adminsonly'), bp_xprofile_get_hidden_field_types_for_user($duser, bp_loggedin_user_id()));
$this->set_current_user($old_current_user);
}
示例3: test_bp_user_query_friends_with_include
/**
* @ticket BP4938
*/
public function test_bp_user_query_friends_with_include()
{
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
$u3 = $this->factory->user->create();
$u4 = $this->factory->user->create();
friends_add_friend($u1, $u2, true);
friends_add_friend($u1, $u3, true);
$q = new BP_User_Query(array('user_id' => $u1, 'include' => array($u2, $u4)));
$friends = is_array($q->results) ? array_values($q->results) : array();
$friend_ids = wp_list_pluck($friends, 'ID');
$this->assertEquals($friend_ids, array($u2));
}
示例4: test_bp_has_members_friendship_requests
public function test_bp_has_members_friendship_requests()
{
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
friends_add_friend($u1, $u2);
$old_user = get_current_user_id();
$this->set_current_user($u2);
$this->go_to(bp_core_get_user_domain($u2) . bp_get_friends_slug() . '/requests/');
$this->restore_admins();
global $members_template;
bp_has_members(array('include' => bp_get_friendship_requests($u2)));
$requests = is_array($members_template->members) ? array_values($members_template->members) : array();
$request_ids = wp_list_pluck($requests, 'ID');
$this->assertEquals($request_ids, array($u1));
$this->set_current_user($old_user);
}
示例5: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$factory = new BP_UnitTest_Factory();
self::$old_user_id = get_current_user_id();
self::$current_user = $factory->user->create(array('display_name' => 'Katie Parker', 'user_login' => 'katie', 'user_email' => 'test-katie@example.com'));
$users = array(array('aardvark', 'Bob Smith'), array('alpaca red', 'William Quinn'), array('cat', 'Lauren Curtis'), array('caterpillar', 'Eldon Burrows'), array('dog green', 'Reece Thornton'), array('pig', 'Joshua Barton'), array('rabbit blue', 'Amber Hooper'), array('smith', 'Robert Bar'), array('snake', 'Eleanor Moore'), array('xylo', 'Silver McFadden'), array('zoom', 'Lisa Smithy'));
// Create some dummy users.
foreach ($users as $user_index => $user) {
$new_user = $factory->user->create(array('display_name' => $user[1], 'user_login' => $user[0], 'user_email' => "test-{$user_index}@example.com"));
self::$user_ids[$user[0]] = $new_user;
}
// Create some dummy friendships (but not the corresponding activity items).
remove_action('friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10);
friends_add_friend(self::$current_user, self::$user_ids['aardvark'], true);
friends_add_friend(self::$current_user, self::$user_ids['cat'], true);
friends_add_friend(self::$current_user, self::$user_ids['caterpillar'], true);
friends_add_friend(self::$current_user, self::$user_ids['pig'], true);
add_action('friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4);
self::$group_slugs['hidden'] = 'the-maw';
self::$group_slugs['public'] = 'the-great-journey';
self::$group_slugs['private'] = 'tsavo-highway';
// Create dummy groups.
self::$group_ids['hidden'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['hidden'], 'status' => 'hidden'));
self::$group_ids['public'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['public'], 'status' => 'public'));
self::$group_ids['private'] = $factory->group->create(array('creator_id' => self::$user_ids['xylo'], 'slug' => self::$group_slugs['private'], 'status' => 'private'));
// Add dummy users to dummy hidden groups.
groups_join_group(self::$group_ids['hidden'], self::$user_ids['pig']);
groups_join_group(self::$group_ids['hidden'], self::$user_ids['alpaca red']);
// Add dummy users to dummy public groups.
groups_join_group(self::$group_ids['public'], self::$current_user);
groups_join_group(self::$group_ids['public'], self::$user_ids['aardvark']);
groups_join_group(self::$group_ids['public'], self::$user_ids['alpaca red']);
groups_join_group(self::$group_ids['public'], self::$user_ids['cat']);
groups_join_group(self::$group_ids['public'], self::$user_ids['smith']);
// Add dummy users to dummy private groups.
groups_join_group(self::$group_ids['private'], self::$user_ids['cat']);
groups_join_group(self::$group_ids['private'], self::$user_ids['caterpillar']);
self::commit_transaction();
}
示例6: example_friends_ajax_addremove_friend
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;
}
示例7: friends_ajax_addremove_friend
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;
}
示例8: invite_anyone_activate_user
function invite_anyone_activate_user($user_id, $key, $user)
{
global $bp;
$email = bp_core_get_user_email($user_id);
$inviters = array();
// Fire the query
$invites = invite_anyone_get_invitations_by_invited_email($email);
if ($invites->have_posts()) {
// From the posts returned by the query, get a list of unique inviters
$groups = array();
while ($invites->have_posts()) {
$invites->the_post();
$inviter_id = get_the_author_meta('ID');
$inviters[] = $inviter_id;
$groups_data = wp_get_post_terms(get_the_ID(), invite_anyone_get_invited_groups_tax_name());
foreach ($groups_data as $group_data) {
if (!isset($groups[$group_data->name])) {
// Keyed by inviter, which means they'll only get one invite per group
$groups[$group_data->name] = $inviter_id;
}
}
// Mark as accepted
update_post_meta(get_the_ID(), 'bp_ia_accepted', date('Y-m-d H:i:s'));
}
$inviters = array_unique($inviters);
// Friendship requests
if (bp_is_active('friends') && apply_filters('invite_anyone_send_friend_requests_on_acceptance', true)) {
if (function_exists('friends_add_friend')) {
foreach ($inviters as $inviter) {
friends_add_friend($inviter, $user_id);
}
}
}
// BuddyPress Followers support
if (function_exists('bp_follow_start_following') && apply_filters('invite_anyone_send_follow_requests_on_acceptance', true)) {
foreach ($inviters as $inviter) {
bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter));
bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id));
}
}
// Group invitations
if (bp_is_active('groups')) {
foreach ($groups as $group_id => $inviter_id) {
$args = array('user_id' => $user_id, 'group_id' => $group_id, 'inviter_id' => $inviter_id);
groups_invite_user($args);
groups_send_invites($inviter_id, $group_id);
}
}
}
do_action('accepted_email_invite', $user_id, $inviters);
}
示例9: test_bp_has_activities_groups_and_friends_scope
/**
* @group scope
* @group filter_query
* @group BP_Activity_Query
*/
function test_bp_has_activities_groups_and_friends_scope()
{
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
$u3 = $this->factory->user->create();
// user 1 becomes friends with user 2
friends_add_friend($u1, $u2, true);
// user 1 joins a group
$g1 = $this->factory->group->create(array('creator_id' => $u1));
$g2 = $this->factory->group->create(array('creator_id' => $u1));
$now = time();
// friend status update
$a1 = $this->factory->activity->create(array('user_id' => $u2, 'type' => 'activity_update', 'recorded_time' => date('Y-m-d H:i:s', $now)));
// group activity
$a2 = $this->factory->activity->create(array('user_id' => $u3, 'component' => 'groups', 'item_id' => $g1, 'type' => 'joined_group', 'recorded_time' => date('Y-m-d H:i:s', $now - 100)));
// misc activity items
$this->factory->activity->create(array('user_id' => $u3, 'component' => 'blogs', 'item_id' => 1, 'type' => 'new_blog_post', 'recorded_time' => date('Y-m-d H:i:s', $now - 100)));
$this->factory->activity->create(array('user_id' => $u3, 'component' => 'activity', 'type' => 'activity_update', 'recorded_time' => date('Y-m-d H:i:s', $now - 100)));
// Make sure we get a fake group ID.
global $wpdb, $bp;
$max_group_id = $wpdb->get_var("SELECT id FROM {$bp->groups->table_name} ORDER BY id DESC LIMIT 1");
$this->factory->activity->create(array('user_id' => $u3, 'component' => 'groups', 'item_id' => $max_group_id + 1, 'type' => 'activity_update', 'recorded_time' => date('Y-m-d H:i:s', $now - 100)));
global $activities_template;
// grab activities from multiple scopes
bp_has_activities(array('user_id' => $u1, 'scope' => 'groups,friends'));
// assert!
$this->assertEqualSets(array($a1, $a2), wp_list_pluck($activities_template->activities, 'id'));
// clean up!
$activities_template = null;
}
示例10: friends_action_add_friend
function friends_action_add_friend() {
global $bp;
if ( $bp->current_component != $bp->friends->slug || $bp->current_action != 'add-friend' )
return false;
$potential_friend_id = $bp->action_variables[0];
if ( !is_numeric( $potential_friend_id ) || !isset( $potential_friend_id ) )
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 ( 'not_friends' == $friendship_status ) {
if ( !check_admin_referer( 'friends_add_friend' ) )
return false;
if ( !friends_add_friend( $bp->loggedin_user->id, $potential_friend_id ) ) {
bp_core_add_message( __( 'Friendship could not be requested.', 'buddypress' ), 'error' );
} else {
bp_core_add_message( __( 'Friendship requested', 'buddypress' ) );
}
} else if ( 'is_friend' == $friendship_status ) {
bp_core_add_message( __( 'You are already friends with this user', 'buddypress' ), 'error' );
} else {
bp_core_add_message( __( 'You already have a pending friendship request with this user', 'buddypress' ), 'error' );
}
bp_core_redirect( wp_get_referer() );
return false;
}
示例11: invite_anyone_activate_user
function invite_anyone_activate_user($user_id, $key, $user)
{
global $bp;
$email = bp_core_get_user_email($user_id);
if ($invites = invite_anyone_get_invitations_by_invited_email($email)) {
// Mark as "is_joined"
invite_anyone_mark_as_joined($email);
// Friendship requests
if (bp_is_active('friends')) {
$inviters = array();
foreach ($invites as $invite) {
if (!in_array($invite->inviter_id, $inviters)) {
$inviters[] = $invite->inviter_id;
}
}
if (function_exists('friends_add_friend')) {
foreach ($inviters as $inviter) {
friends_add_friend($inviter, $user_id);
}
}
}
// BuddyPress Followers support
if (function_exists('bp_follow_start_following')) {
$inviters = array();
foreach ($invites as $invite) {
if (!in_array($invite->inviter_id, $inviters)) {
$inviters[] = $invite->inviter_id;
}
}
foreach ($inviters as $inviter) {
bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter));
bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id));
}
}
// BuddyPress Followers support
if (function_exists('bp_follow_start_following')) {
$inviters = array();
foreach ($invites as $invite) {
if (!in_array($invite->inviter_id, $inviters)) {
$inviters[] = $invite->inviter_id;
}
}
foreach ($inviters as $inviter) {
bp_follow_start_following(array('leader_id' => $user_id, 'follower_id' => $inviter));
bp_follow_start_following(array('leader_id' => $inviter, 'follower_id' => $user_id));
}
}
// Group invitations
if (bp_is_active('groups')) {
$groups = array();
foreach ($invites as $invite) {
if (!$invite->group_invitations[0]) {
continue;
} else {
$group_invitations = unserialize($invite->group_invitations);
}
foreach ($group_invitations as $group) {
if (!in_array($group, array_keys($groups))) {
$groups[$group] = $invite->inviter_id;
}
}
}
foreach ($groups as $group_id => $inviter_id) {
$args = array('user_id' => $user_id, 'group_id' => $group_id, 'inviter_id' => $inviter_id);
groups_invite_user($args);
groups_send_invites($inviter_id, $group_id);
}
}
}
do_action('accepted_email_invite', $user_id, $inviters);
}
示例12: bp_dtheme_ajax_addremove_friend
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;
}
示例13: bp_legacy_theme_ajax_addremove_friend
/**
* 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;
}
示例14: test_new_bp_friends_friendship_object_should_hit_friendship_object_cache
/**
* @group friendship_caching
*/
public function test_new_bp_friends_friendship_object_should_hit_friendship_object_cache()
{
global $wpdb;
$now = time();
$u1 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now)));
$u2 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 100)));
friends_add_friend($u1, $u2, true);
$fid = friends_get_friendship_id($u1, $u2);
$friendship_obj = new BP_Friends_Friendship($fid, false, false);
$first_query_count = $wpdb->num_queries;
// Create it again.
$friendship_obj = new BP_Friends_Friendship($fid, false, false);
$this->assertEquals($first_query_count, $wpdb->num_queries);
}
示例15: demodata_create_friendship
function demodata_create_friendship($userid)
{
return friends_add_friend($userid, demodata_random_user_id($userid), true);
}