本文整理汇总了PHP中friends_add_friend函数的典型用法代码示例。如果您正苦于以下问题:PHP friends_add_friend函数的具体用法?PHP friends_add_friend怎么用?PHP friends_add_friend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了friends_add_friend函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:igniterealtime,项目名称:community-plugins,代码行数:34,代码来源:bp-friends-actions.php
示例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);
}
开发者ID:dcavins,项目名称:buddypress-svn,代码行数:10,代码来源:functions.php
示例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));
}
开发者ID:swissspidy,项目名称:BuddyPress,代码行数:16,代码来源:class-bp-user-query.php
示例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);
}
开发者ID:swissspidy,项目名称:BuddyPress,代码行数:16,代码来源:template.php
示例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' => '[email protected]'));
$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();
}
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:40,代码来源:suggestions.php
示例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;
}
开发者ID:natrio,项目名称:buddypress-skeleton-component,代码行数:22,代码来源:bp-example-ajax.php
示例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;
}
开发者ID:alvaropereyra,项目名称:shrekcms,代码行数:24,代码来源:bp-friends-ajax.php
示例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);
}
开发者ID:kd5ytx,项目名称:Empirical-Wordpress,代码行数:51,代码来源:by-email.php
示例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;
}
开发者ID:JeroenNouws,项目名称:BuddyPress,代码行数:35,代码来源:template.php
示例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;
}
开发者ID:n-sane,项目名称:zaroka,代码行数:36,代码来源:bp-friends.php
示例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);
}
开发者ID:hnla,项目名称:invite-anyone,代码行数:71,代码来源:by-email.php
示例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;
}
开发者ID:nxtclass,项目名称:NXTClass-Plugin,代码行数:28,代码来源:ajax.php
示例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;
}
开发者ID:kosir,项目名称:thatcamp-org,代码行数:44,代码来源:buddypress-functions.php
示例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);
}
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:17,代码来源:class-bp-friends-friendship.php
示例15: demodata_create_friendship
function demodata_create_friendship($userid)
{
return friends_add_friend($userid, demodata_random_user_id($userid), true);
}
开发者ID:jgacuca567,项目名称:jamesvanwaza,代码行数:4,代码来源:demodata.php
示例16: test_bp_has_activities_scope_friends_should_respect_id_order_when_record_dates_are_same
/**
* @group scope
* @ticket BP6720
*/
public function test_bp_has_activities_scope_friends_should_respect_id_order_when_record_dates_are_same()
{
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
friends_add_friend($u1, $u2, true);
// Friend's very fast status updates.
$a1 = $this->factory->activity->create(array('user_id' => $u2, 'type' => 'activity_update', 'recorded_time' => date('Y-m-d H:i:s', 1451944920)));
$a2 = $this->factory->activity->create(array('user_id' => $u2, 'type' => 'activity_update', 'recorded_time' => date('Y-m-d H:i:s', 1451944920)));
global $activities_template;
$reset_activities_template = $activities_template;
// Get activities in 'friends' scope
bp_has_activities(array('user_id' => $u1, 'scope' => 'friends'));
$found = $activities_template->activities;
// Clean up!
$activities_template = $reset_activities_template;
$this->assertEquals(array($a2, $a1), wp_list_pluck($found, 'id'));
}
开发者ID:boonebgorges,项目名称:BuddyPress-1,代码行数:21,代码来源:template.php
示例17: test_friends_check_friendship_should_hit_friendship_object_cache
/**
* @group friendship_caching
*/
public function test_friends_check_friendship_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);
friends_check_friendship_status($u1, $u2);
$first_query_count = $wpdb->num_queries;
/*
* We expect this to generate one query to find $u2's friendships,
* but the friendship object itself should come from cache.
*/
friends_check_friendship_status($u2, $u1);
$this->assertEquals($first_query_count + 1, $wpdb->num_queries);
}
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:19,代码来源:functions.php
示例18: bp_dtheme_ajax_addremove_friend
/**
* 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;
}
开发者ID:raminjan,项目名称:logicalbones_hug,代码行数:38,代码来源:ajax.php
示例19: test_delete_friendship_activity_on_user_delete
/**
* @group friends_delete_activity
*/
public function test_delete_friendship_activity_on_user_delete()
{
$old_user = get_current_user_id();
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
friends_add_friend($u2, $u1);
$friendship_id = friends_get_friendship_id($u2, $u1);
// Set current user to u1 to accept the friendship
$this->set_current_user($u1);
friends_accept_friendship($friendship_id);
// Reset the current user
$this->set_current_user($old_user);
// Delete $u1.
wp_delete_user($u1);
// 'friendship_created' activity item should not exist.
$friendship_activity = bp_activity_get(array('component' => buddypress()->friends->id, 'filter' => array('action' => array('friendship_created'), 'primary_id' => $friendship_id)));
$this->assertEmpty($friendship_activity['activities']);
}
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:21,代码来源:activity.php
示例20: bpdd_import_users_friends
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;
}
开发者ID:vsalx,项目名称:rattieinfo,代码行数:15,代码来源:bp-default-data.php
注:本文中的friends_add_friend函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论