本文整理汇总了PHP中BP_Friends_Friendship类的典型用法代码示例。如果您正苦于以下问题:PHP BP_Friends_Friendship类的具体用法?PHP BP_Friends_Friendship怎么用?PHP BP_Friends_Friendship使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BP_Friends_Friendship类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: friends_action_remove_friend
/**
* 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;
}
示例2: test_requests_on_request
/**
* @group friends_get_friendship_request_user_ids
* @group friends_add_friend
*/
public function test_requests_on_request()
{
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
$u3 = $this->factory->user->create();
// request friendship
friends_add_friend($u2, $u1);
// Set the time of the earlier friendship for reliable ordering of the results.
$fid = friends_get_friendship_id($u2, $u1);
$friendship = new BP_Friends_Friendship($fid, false, false);
$friendship->date_created = date('Y-m-d H:i:s', time() - 60);
$friendship->save();
// get request count for user 1 and assert
$requests = friends_get_friendship_request_user_ids($u1);
$this->assertEquals(array($u2), $requests);
// request another friendship
friends_add_friend($u3, $u1);
// refetch request count for user 1 and assert
$requests = friends_get_friendship_request_user_ids($u1);
$this->assertEquals(array($u3, $u2), $requests);
}
示例3: bp_friends_filter_user_query_populate_extras
/**
* 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;
}
}
}
示例4: 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;
}
示例5: wpmudev_chat_buddypress_member_header_actions
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;
}
}
示例6: 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;
}
示例7: populate_extras
function populate_extras()
{
global $bp;
if (function_exists('friends_install')) {
$this->total_friends = BP_Friends_Friendship::total_friend_count($this->id);
if ($this->total_friends) {
if (1 == $this->total_friends) {
$this->total_friends .= ' ' . __('friend', 'buddypress');
} else {
$this->total_friends .= ' ' . __('friends', 'buddypress');
}
$this->total_friends = '<a href="' . $this->user_url . $bp->friends->slug . '" title="' . sprintf(__("%s's friend list", 'buddypress'), $this->fullname) . '">' . $this->total_friends . '</a>';
}
}
if (function_exists('bp_blogs_install')) {
if ($this->total_blogs) {
if (1 == $this->total_blogs) {
$this->total_blogs .= ' ' . __('blog', 'buddypress');
} else {
$this->total_blogs .= ' ' . __('blogs', 'buddypress');
}
$this->total_blogs = '<a href="' . $this->user_url . $bp->blogs->slug . '" title="' . sprintf(__("%s's blog list", 'buddypress'), $this->fullname) . '">' . $this->total_blogs . '</a>';
}
}
if (function_exists('groups_install')) {
$this->total_groups = BP_Groups_Member::total_group_count($this->id);
if ($this->total_groups) {
if (1 == $this->total_groups) {
$this->total_groups .= ' ' . __('group', 'buddypress');
} else {
$this->total_groups .= ' ' . __('groups', 'buddypress');
}
$this->total_groups = '<a href="' . $this->user_url . $bp->groups->slug . '" title="' . sprintf(__("%s's group list", 'buddypress'), $this->fullname) . '">' . $this->total_groups . '</a>';
}
}
}
示例8: delete_all_for_user
function delete_all_for_user($user_id)
{
global $nxtdb, $bp;
// Get friends of $user_id
$friend_ids = BP_Friends_Friendship::get_friend_user_ids($user_id);
// Delete all friendships related to $user_id
$nxtdb->query($nxtdb->prepare("DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id));
// Delete friend request notifications for members who have a notification from this user.
$nxtdb->query($nxtdb->prepare("DELETE FROM {$bp->core->table_name_notifications} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id));
// Loop through friend_ids and update their counts
foreach ((array) $friend_ids as $friend_id) {
BP_Friends_Friendship::total_friend_count($friend_id);
}
}
示例9: friends_remove_data
/**
* Remove all friends-related data concerning a given user.
*
* Removes the following:
*
* - Friendships of which the user is a member
* - Cached friend count for the user
* - Notifications of friendship requests sent by the user
*
* @param int $user_id ID of the user whose friend data is being removed.
*/
function friends_remove_data($user_id)
{
do_action('friends_before_remove_data', $user_id);
BP_Friends_Friendship::delete_all_for_user($user_id);
// Remove usermeta
bp_delete_user_meta($user_id, 'total_friend_count');
do_action('friends_remove_data', $user_id);
}
示例10: bp_friends_random_friends
function bp_friends_random_friends()
{
global $bp;
if (!($friend_ids = wp_cache_get('friends_friend_ids_' . $bp->displayed_user->id, 'bp'))) {
$friend_ids = BP_Friends_Friendship::get_random_friends($bp->displayed_user->id);
wp_cache_set('friends_friend_ids_' . $bp->displayed_user->id, $friend_ids, 'bp');
}
?>
<div class="info-group">
<h4><?php
bp_word_or_name(__("My Friends", 'buddypress'), __("%s's Friends", 'buddypress'));
?>
(<?php
echo BP_Friends_Friendship::total_friend_count($bp->displayed_user->id);
?>
) <a href="<?php
echo $bp->displayed_user->domain . $bp->friends->slug;
?>
"><?php
_e('See All', 'buddypress');
?>
»</a></h4>
<?php
if ($friend_ids) {
?>
<ul class="horiz-gallery">
<?php
for ($i = 0; $i < count($friend_ids); $i++) {
?>
<li>
<a href="<?php
echo bp_core_get_userurl($friend_ids[$i]);
?>
"><?php
echo bp_core_get_avatar($friend_ids[$i], 1);
?>
</a>
<h5><?php
echo bp_core_get_userlink($friend_ids[$i]);
?>
</h5>
</li>
<?php
}
?>
</ul>
<?php
} else {
?>
<div id="message" class="info">
<p><?php
bp_word_or_name(__("You haven't added any friend connections yet.", 'buddypress'), __("%s hasn't created any friend connections yet.", 'buddypress'));
?>
</p>
</div>
<?php
}
?>
<div class="clear"></div>
</div>
<?php
}
示例11: bp_legacy_theme_ajax_messages_autocomplete_results
/**
* AJAX handler for autocomplete.
*
* Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.
*
* @since BuddyPress (1.2.0)
*
* @return string HTML.
*/
function bp_legacy_theme_ajax_messages_autocomplete_results()
{
// Include everyone in the autocomplete, or just friends?
if (bp_is_current_component(bp_get_messages_slug())) {
$autocomplete_all = buddypress()->messages->autocomplete_all;
}
$pag_page = 1;
$limit = (int) $_GET['limit'] ? $_GET['limit'] : apply_filters('bp_autocomplete_max_results', 10);
$search_terms = isset($_GET['q']) ? $_GET['q'] : '';
$user_query_args = array('search_terms' => $search_terms, 'page' => intval($pag_page), 'per_page' => intval($limit));
// If only matching against friends, get an $include param for
// BP_User_Query
if (!$autocomplete_all && bp_is_active('friends')) {
$include = BP_Friends_Friendship::get_friend_user_ids(bp_loggedin_user_id());
// Ensure zero matches if no friends are found
if (empty($include)) {
$include = array(0);
}
$user_query_args['include'] = $include;
}
$user_query = new BP_User_Query($user_query_args);
// Backward compatibility - if a plugin is expecting a legacy
// filter, pass the IDs through the filter and requery (groan)
if (has_filter('bp_core_autocomplete_ids') || has_filter('bp_friends_autocomplete_ids')) {
$found_user_ids = wp_list_pluck($user_query->results, 'ID');
if ($autocomplete_all) {
$found_user_ids = apply_filters('bp_core_autocomplete_ids', $found_user_ids);
} else {
$found_user_ids = apply_filters('bp_friends_autocomplete_ids', $found_user_ids);
}
if (empty($found_user_ids)) {
$found_user_ids = array(0);
}
// Repopulate the $user_query variable
$user_query = new BP_User_Query(array('include' => $found_user_ids));
}
if (!empty($user_query->results)) {
foreach ($user_query->results as $user) {
if (bp_is_username_compatibility_mode()) {
// Sanitize for spaces. Use urlencode() rather
// than rawurlencode() because %20 breaks JS
$username = urlencode($user->user_login);
} else {
$username = $user->user_nicename;
}
// Note that the final line break acts as a delimiter for the
// autocomplete javascript and thus should not be removed
echo '<span id="link-' . esc_attr($username) . '" href="' . bp_core_get_user_domain($user->ID) . '"></span>' . bp_core_fetch_avatar(array('item_id' => $user->ID, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $user->display_name)) . ' ' . bp_core_get_user_displayname($user->ID) . ' (' . esc_html($username) . ')' . "\n";
}
}
exit;
}
示例12: friends_remove_data
function friends_remove_data($user_id)
{
BP_Friends_Friendship::delete_all_for_user($user_id);
/* Remove usermeta */
delete_usermeta($user_id, 'total_friend_count');
/* Remove friendship requests FROM user */
bp_core_delete_notifications_from_user($user_id, $bp->friends->slug, 'friendship_request');
do_action('friends_remove_data', $user_id);
}
示例13: invite_anyone_group_invite_maybe_filter_invite_message
/**
* 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;
}
示例14: 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;
}
示例15: the_invite
function the_invite()
{
global $group_id;
$this->in_the_loop = true;
$user_id = $this->next_invite();
$this->invite = new stdClass();
$this->invite->user = $this->invite_data[$user_id];
// This method previously populated the user object with
// BP_Core_User. We manually configure BP_Core_User data for
// backward compatibility.
if (bp_is_active('xprofile')) {
$this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user($user_id);
}
$this->invite->user->avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname)));
$this->invite->user->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname)));
$this->invite->user->avatar_mini = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname), 'width' => 30, 'height' => 30));
$this->invite->user->email = $this->invite->user->user_email;
$this->invite->user->user_url = bp_core_get_user_domain($user_id, $this->invite->user->user_nicename, $this->invite->user->user_login);
$this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>";
$this->invite->user->last_active = bp_core_get_last_activity($this->invite->user->last_activity, __('active %s', 'buddypress'));
if (bp_is_active('groups')) {
$total_groups = BP_Groups_Member::total_group_count($user_id);
$this->invite->user->total_groups = sprintf(_n('%d group', '%d groups', $total_groups, 'buddypress'), $total_groups);
}
if (bp_is_active('friends')) {
$this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id);
}
if (bp_is_active('friends')) {
$this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id);
}
$this->invite->user->total_blogs = null;
$this->invite->group_id = $group_id;
// Globaled in bp_group_has_invites()
if (0 == $this->current_invite) {
// loop has just started
do_action('loop_start');
}
}