function friends_notification_new_request($friendship_id, $initiator_id, $friend_id) { $initiator_name = bp_core_get_user_displayname($initiator_id); if ('no' == bp_get_user_meta((int) $friend_id, 'notification_friends_friendship_request', true)) { return false; } $ud = get_userdata($friend_id); $all_requests_link = bp_core_get_user_domain($friend_id) . bp_get_friends_slug() . '/requests/'; $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = trailingslashit(bp_core_get_user_domain($friend_id) . $settings_slug . '/notifications'); $initiator_link = bp_core_get_user_domain($initiator_id); // Set up and send the message $to = $ud->user_email; $subject = bp_get_email_subject(array('text' => sprintf(__('New friendship request from %s', 'buddypress'), $initiator_name))); $message = sprintf(__('%1$s wants to add you as a friend. To view all of your pending friendship requests: %2$s To view %3$s\'s profile: %4$s --------------------- ', 'buddypress'), $initiator_name, $all_requests_link, $initiator_name, $initiator_link); // Only show the disable notifications line if the settings component is enabled if (bp_is_active('settings')) { $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); } /* Send the message */ $to = apply_filters('friends_notification_new_request_to', $to); $subject = apply_filters('friends_notification_new_request_subject', $subject, $initiator_name); $message = apply_filters('friends_notification_new_request_message', $message, $initiator_name, $initiator_link, $all_requests_link, $settings_link); wp_mail($to, $subject, $message); do_action('bp_friends_sent_request_email', $friend_id, $subject, $message, $friendship_id, $initiator_id); }
function friends_notification_new_request($friendship_id, $initiator_id, $friend_id) { global $bp; $initiator_name = bp_core_get_user_displayname($initiator_id); if ('no' == bp_get_user_meta((int) $friend_id, 'notification_friends_friendship_request', true)) { return false; } $ud = get_userdata($friend_id); $initiator_ud = get_userdata($initiator_id); $all_requests_link = bp_core_get_user_domain($friend_id) . bp_get_friends_slug() . '/requests/'; $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($friend_id) . $settings_slug . '/notifications'; $initiator_link = bp_core_get_user_domain($initiator_id); // Set up and send the message $to = $ud->user_email; $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES); $subject = '[' . $sitename . '] ' . sprintf(__('New friendship request from %s', 'buddypress'), $initiator_name); $message = sprintf(__('%1$s wants to add you as a friend. To view all of your pending friendship requests: %2$s To view %3$s\'s profile: %4$s --------------------- ', 'buddypress'), $initiator_name, $all_requests_link, $initiator_name, $initiator_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); /* Send the message */ $to = apply_filters('friends_notification_new_request_to', $to); $subject = apply_filters('friends_notification_new_request_subject', $subject, $initiator_name); $message = apply_filters('friends_notification_new_request_message', $message, $initiator_name, $initiator_link, $all_requests_link, $settings_link); nxt_mail($to, $subject, $message); do_action('bp_friends_sent_request_email', $friend_id, $subject, $message, $friendship_id, $initiator_id); }
/** * Format the BuddyBar/Toolbar notifications for the Friends component * * @package BuddyPress * * @param string $action The kind of notification being rendered * @param int $item_id The primary item id * @param int $secondary_item_id The secondary item id * @param int $total_items The total number of messaging-related notifications waiting for the user * @param string $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar */ function friends_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string') { switch ($action) { case 'friendship_accepted': $link = trailingslashit(bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends'); // Set up the string and the filter if ((int) $total_items > 1) { $text = sprintf(__('%d friends accepted your friendship requests', 'buddypress'), (int) $total_items); $filter = 'bp_friends_multiple_friendship_accepted_notification'; } else { $text = sprintf(__('%s accepted your friendship request', 'buddypress'), bp_core_get_user_displayname($item_id)); $filter = 'bp_friends_single_friendship_accepted_notification'; } break; case 'friendship_request': $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/?new'; // Set up the string and the filter if ((int) $total_items > 1) { $text = sprintf(__('You have %d pending friendship requests', 'buddypress'), (int) $total_items); $filter = 'bp_friends_multiple_friendship_request_notification'; } else { $text = sprintf(__('You have a friendship request from %s', 'buddypress'), bp_core_get_user_displayname($item_id)); $filter = 'bp_friends_single_friendship_request_notification'; } break; } // Return either an HTML link or an array, depending on the requested format if ('string' == $format) { $return = apply_filters($filter, '<a href="' . $link . '">' . $text . '</a>', (int) $total_items); } else { $return = apply_filters($filter, array('link' => $link, 'text' => $text), (int) $total_items); } do_action('friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return); return $return; }
/** * Setup BuddyBar navigation * * @global obj $bp */ function setup_nav() { global $bp; // Add 'Friends' to the main navigation $main_nav = array('name' => sprintf(__('Friends <span>%d</span>', 'buddypress'), friends_get_total_friend_count()), 'slug' => $this->slug, 'position' => 60, 'screen_function' => 'friends_screen_my_friends', 'default_subnav_slug' => 'my-friends', 'item_css_id' => $bp->friends->id); $friends_link = trailingslashit($bp->loggedin_user->domain . bp_get_friends_slug()); // Add the subnav items to the friends nav item $sub_nav[] = array('name' => __('Friendships', 'buddypress'), 'slug' => 'my-friends', 'parent_url' => $friends_link, 'parent_slug' => bp_get_friends_slug(), 'screen_function' => 'friends_screen_my_friends', 'position' => 10, 'item_css_id' => 'friends-my-friends'); $sub_nav[] = array('name' => __('Requests', 'buddypress'), 'slug' => 'requests', 'parent_url' => $friends_link, 'parent_slug' => bp_get_friends_slug(), 'screen_function' => 'friends_screen_requests', 'position' => 20, 'user_has_access' => bp_is_my_profile()); parent::setup_nav($main_nav, $sub_nav); }
/** * @group bp_has_members * @group friends * @ticket BP5071 */ public function test_bp_has_members_friendship_requests_with_no_requests() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $old_user = get_current_user_id(); $this->set_current_user($u2); // For some reason, in all the user switching, the cache gets // confused. Never comes up when BP runs normally, because the // loggedin_user doesn't change on a pageload. @todo Fix for // real in BP wp_cache_delete('bp_user_domain_' . $u2, 'bp'); $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(array(), $request_ids); $this->set_current_user($old_user); }
/** * Setup BuddyBar navigation * * @global BuddyPress $bp The one true BuddyPress instance */ public function setup_nav($main_nav = array(), $sub_nav = array()) { global $bp; $sub_nav = array(); // Add 'Friends' to the main navigation $main_nav = array('name' => sprintf(__('Friends <span>%d</span>', 'buddypress'), friends_get_total_friend_count()), 'slug' => $this->slug, 'position' => 60, 'screen_function' => 'friends_screen_my_friends', 'default_subnav_slug' => 'my-friends', 'item_css_id' => $bp->friends->id); // Determine user to use if (bp_displayed_user_domain()) { $user_domain = bp_displayed_user_domain(); } elseif (bp_loggedin_user_domain()) { $user_domain = bp_loggedin_user_domain(); } else { return; } $friends_link = trailingslashit($user_domain . bp_get_friends_slug()); // Add the subnav items to the friends nav item $sub_nav[] = array('name' => __('Friendships', 'buddypress'), 'slug' => 'my-friends', 'parent_url' => $friends_link, 'parent_slug' => bp_get_friends_slug(), 'screen_function' => 'friends_screen_my_friends', 'position' => 10, 'item_css_id' => 'friends-my-friends'); $sub_nav[] = array('name' => __('Requests', 'buddypress'), 'slug' => 'requests', 'parent_url' => $friends_link, 'parent_slug' => bp_get_friends_slug(), 'screen_function' => 'friends_screen_requests', 'position' => 20, 'user_has_access' => bp_core_can_edit_settings()); parent::setup_nav($main_nav, $sub_nav); }
/** * Display the widget. * * @param array $args Widget arguments. * @param array $instance The widget settings, as saved by the user. */ function widget($args, $instance) { extract($args); if (!bp_displayed_user_id()) { return; } $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('bp_core_widget_friends-js', buddypress()->plugin_url . "bp-friends/js/widget-friends{$min}.js", array('jquery'), bp_get_version()); $user_id = bp_displayed_user_id(); $link = trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug()); $instance['title'] = sprintf(__('%s’s Friends', 'buddypress'), bp_get_displayed_user_fullname()); if (empty($instance['friend_default'])) { $instance['friend_default'] = 'active'; } $title = apply_filters('widget_title', $instance['title']); echo $before_widget; $title = $instance['link_title'] ? '<a href="' . esc_url($link) . '">' . esc_html($title) . '</a>' : esc_html($title); echo $before_title . $title . $after_title; $members_args = array('user_id' => absint($user_id), 'type' => sanitize_text_field($instance['friend_default']), 'max' => absint($instance['max_friends']), 'populate_extras' => 1); ?> <?php if (bp_has_members($members_args)) { ?> <div class="item-options" id="friends-list-options"> <a href="<?php bp_members_directory_permalink(); ?> " id="newest-friends" <?php if ($instance['friend_default'] == 'newest') { ?> class="selected"<?php } ?> ><?php _e('Newest', 'buddypress'); ?> </a> | <a href="<?php bp_members_directory_permalink(); ?> " id="recently-active-friends" <?php if ($instance['friend_default'] == 'active') { ?> class="selected"<?php } ?> ><?php _e('Active', 'buddypress'); ?> </a> | <a href="<?php bp_members_directory_permalink(); ?> " id="popular-friends" <?php if ($instance['friend_default'] == 'popular') { ?> class="selected"<?php } ?> ><?php _e('Popular', 'buddypress'); ?> </a> </div> <ul id="friends-list" class="item-list"> <?php while (bp_members()) { bp_the_member(); ?> <li class="vcard"> <div class="item-avatar"> <a href="<?php bp_member_permalink(); ?> " title="<?php bp_member_name(); ?> "><?php bp_member_avatar(); ?> </a> </div> <div class="item"> <div class="item-title fn"><a href="<?php bp_member_permalink(); ?> " title="<?php bp_member_name(); ?> "><?php bp_member_name(); ?> </a></div> <div class="item-meta"> <span class="activity"> <?php if ('newest' == $instance['friend_default']) { bp_member_registered(); } if ('active' == $instance['friend_default']) { bp_member_last_active(); } if ('popular' == $instance['friend_default']) { bp_member_total_friend_count(); } ?> </span> </div> </div> </li> <?php } ?> </ul> <?php wp_nonce_field('bp_core_widget_friends', '_wpnonce-friends'); ?> <input type="hidden" name="friends_widget_max" id="friends_widget_max" value="<?php echo absint($instance['max_friends']); ?> " /> <?php } else { ?> <div class="widget-error"> <?php _e('Sorry, no members were found.', 'buddypress'); ?> </div> <?php } ?> <?php echo $after_widget; ?> <?php }
function bp_get_friend_reject_request_link() { global $members_template; if (!($friendship_id = wp_cache_get('friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id()))) { $friendship_id = friends_get_friendship_id($members_template->member->id, bp_loggedin_user_id()); wp_cache_set('friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp'); } return apply_filters('bp_get_friend_reject_request_link', wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship')); }
/** * Is the current page a user's Friends activity stream? * * Eg http://example.com/members/joe/friends/ * * @since 1.1.0 * * @return bool True if the current page is a user's Friends activity stream. */ function bp_is_user_friends_activity() { if (!bp_is_active('friends')) { return false; } $slug = bp_get_friends_slug(); if (empty($slug)) { $slug = 'friends'; } if (bp_is_user_activity() && bp_is_current_action($slug)) { return true; } return false; }
?> " role="navigation"> <ul> <li class="selected" id="members-all"><a href="<?php bp_members_directory_permalink(); ?> "><?php printf(__('All Members %s', 'buddypress'), '<span>' . bp_get_total_member_count() . '</span>'); ?> </a></li> <?php if (is_user_logged_in() && bp_is_active('friends') && bp_get_total_friend_count(bp_loggedin_user_id())) { ?> <li id="members-personal"><a href="<?php echo esc_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends/'); ?> "><?php printf(__('My Friends %s', 'buddypress'), '<span>' . bp_get_total_friend_count(bp_loggedin_user_id()) . '</span>'); ?> </a></li> <?php } ?> <?php /** * Fires inside the members directory member types. * * @since 1.2.0 */
<title><?php bp_site_name(); ?> | <?php bp_displayed_user_fullname(); ?> | <?php _e('Friends Activity', 'buddypress'); ?> </title> <atom:link href="<?php self_link(); ?> " rel="self" type="application/rss+xml" /> <link><?php echo bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed'; ?> </link> <description><?php printf(__('%s - Friends Activity Feed', 'buddypress'), bp_get_displayed_user_fullname()); ?> </description> <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?> </pubDate> <generator>http://buddypress.org/?v=<?php echo BP_VERSION; ?> </generator> <language><?php
/** * Load a user's friends feed. * * @since BuddyPress (1.0) * * @global object $wp_query * @uses bp_is_active() * @uses bp_is_user_activity() * @uses bp_is_current_action() * @uses bp_get_friends_slug() * @uses bp_is_action_variable() * @uses status_header() * * @return bool False on failure */ function bp_activity_action_friends_feed() { global $wp_query; if (!bp_is_active('friends') || !bp_is_user_activity() || !bp_is_current_action(bp_get_friends_slug()) || !bp_is_action_variable('feed', 0)) { return false; } $wp_query->is_404 = false; status_header(200); include_once 'feeds/bp-activity-friends-feed.php'; die; }
/** * Notification formatting callback for bp-friends notifications. * * @param string $action The kind of notification being rendered. * @param int $item_id The primary item ID. * @param int $secondary_item_id The secondary item ID. * @param int $total_items The total number of messaging-related notifications * waiting for the user. * @param string $format 'string' for BuddyBar-compatible notifications; * 'array' for WP Toolbar. Default: 'string'. * @return array|string */ function friends_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string') { switch ($action) { case 'friendship_accepted': $link = trailingslashit(bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends'); // $action and $amount are used to generate dynamic filter names. $action = 'accepted'; // Set up the string and the filter. if ((int) $total_items > 1) { $text = sprintf(__('%d friends accepted your friendship requests', 'buddypress'), (int) $total_items); $amount = 'multiple'; } else { $text = sprintf(__('%s accepted your friendship request', 'buddypress'), bp_core_get_user_displayname($item_id)); $amount = 'single'; } break; case 'friendship_request': $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/?new'; $action = 'request'; // Set up the string and the filter. if ((int) $total_items > 1) { $text = sprintf(__('You have %d pending friendship requests', 'buddypress'), (int) $total_items); $amount = 'multiple'; } else { $text = sprintf(__('You have a friendship request from %s', 'buddypress'), bp_core_get_user_displayname($item_id)); $amount = 'single'; } break; } // Return either an HTML link or an array, depending on the requested format. if ('string' == $format) { /** * Filters the format of friendship notifications based on type and amount * of notifications pending. * * This is a variable filter that has four possible versions. * The four possible versions are: * - bp_friends_single_friendship_accepted_notification * - bp_friends_multiple_friendship_accepted_notification * - bp_friends_single_friendship_request_notification * - bp_friends_multiple_friendship_request_notification * * @since 1.0.0 * * @param string|array $value Depending on format, an HTML link to new requests profile * tab or array with link and text. * @param int $total_items The total number of messaging-related notifications * waiting for the user. * @param int $item_id The primary item ID. */ $return = apply_filters('bp_friends_' . $amount . '_friendship_' . $action . '_notification', '<a href="' . esc_url($link) . '">' . esc_html($text) . '</a>', (int) $total_items, $item_id); } else { /** This filter is documented in bp-friends/bp-friends-notifications.php */ $return = apply_filters('bp_friends_' . $amount . '_friendship_' . $action . '_notification', array('link' => $link, 'text' => $text), (int) $total_items, $item_id); } /** * Fires at the end of the bp-friends notification format callback. * * @since 1.0.0 * * @param string $action The kind of notification being rendered. * @param int $item_id The primary item ID. * @param int $secondary_item_id The secondary item ID. * @param int $total_items The total number of messaging-related notifications * waiting for the user. * @param array|string $return Notification text string or array of link and text. */ do_action('friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return); return $return; }
/** * Send notifications related to a new friendship request. * * When a friendship is requested, an email and a BP notification are sent to * the user of whom friendship has been requested ($friend_id). * * @since 1.0.0 * * @param int $friendship_id ID of the friendship object. * @param int $initiator_id ID of the user who initiated the request. * @param int $friend_id ID of the request recipient. */ function friends_notification_new_request($friendship_id, $initiator_id, $friend_id) { if ('no' == bp_get_user_meta((int) $friend_id, 'notification_friends_friendship_request', true)) { return; } $unsubscribe_args = array('user_id' => $friend_id, 'notification_type' => 'friends-request'); $args = array('tokens' => array('friend-requests.url' => esc_url(bp_core_get_user_domain($friend_id) . bp_get_friends_slug() . '/requests/'), 'friend.id' => $friend_id, 'friendship.id' => $friendship_id, 'initiator.id' => $initiator_id, 'initiator.url' => esc_url(bp_core_get_user_domain($initiator_id)), 'initiator.name' => bp_core_get_user_displayname($initiator_id), 'unsubscribe' => esc_url(bp_email_get_unsubscribe_link($unsubscribe_args)))); bp_send_email('friends-request', $friend_id, $args); }
/** * Return the URL for rejecting the current friendship request in the loop. * * @return string reject-friendship URL. */ function bp_get_friend_reject_request_link() { global $members_template; if (!($friendship_id = wp_cache_get('friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id()))) { $friendship_id = friends_get_friendship_id($members_template->member->id, bp_loggedin_user_id()); wp_cache_set('friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp'); } /** * Filters the URL for rejecting the current friendship request in the loop. * * @since 1.0.0 * * @param string $value Reject-friendship URL. */ return apply_filters('bp_get_friend_reject_request_link', wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship')); }
/** * @group friends */ function test_member_activity_friends() { $this->go_to(bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_activity_slug() . '/' . bp_get_friends_slug()); $this->assertTrue(bp_is_user_friends_activity()); }
/** * Load a user's friends' activity feed. * * @since 1.0.0 * * @uses bp_is_active() * @uses bp_is_user_activity() * @uses bp_is_current_action() * @uses bp_get_friends_slug() * @uses bp_is_action_variable() * @uses status_header() * * @return bool False on failure. */ function bp_activity_action_friends_feed() { if (!bp_is_active('friends') || !bp_is_user_activity() || !bp_is_current_action(bp_get_friends_slug()) || !bp_is_action_variable('feed', 0)) { return false; } // Setup the feed. buddypress()->activity->feed = new BP_Activity_Feed(array('id' => 'friends', 'title' => sprintf(__('%1$s | %2$s | Friends Activity', 'buddypress'), bp_get_site_name(), bp_get_displayed_user_fullname()), 'link' => trailingslashit(bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug()), 'description' => sprintf(__("Activity feed for %s's friends.", 'buddypress'), bp_get_displayed_user_fullname()), 'activity_args' => 'scope=friends')); }
/** * 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 test_member_friends_requests() { $this->go_to(bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_friends_slug() . '/requests'); $this->assertTrue(bp_is_user_friend_requests()); }
/** * Returns the member activity feed link * * @since 1.2.0 * * @uses bp_is_profile_component() * @uses bp_is_current_action() * @uses bp_displayed_user_domain() * @uses bp_get_activity_slug() * @uses bp_is_active() * @uses bp_get_friends_slug() * @uses bp_get_groups_slug() * @uses apply_filters() To call the 'bp_get_activities_member_rss_link' hook * * @return string $link The member activity feed link */ function bp_get_member_activity_feed_link() { global $bp; if (bp_is_profile_component() || bp_is_current_action('just-me')) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/'; } elseif (bp_is_active('friends') && bp_is_current_action(bp_get_friends_slug())) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/'; } elseif (bp_is_active('groups') && bp_is_current_action(bp_get_groups_slug())) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/'; } elseif ('favorites' == $bp->current_action) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/'; } elseif ('mentions' == $bp->current_action) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/'; } else { $link = ''; } return apply_filters('bp_get_activities_member_rss_link', $link); }
/** * 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; }
?> <?php do_action('bp_before_activity_type_tab_friends'); ?> <?php if (bp_is_active('friends')) { ?> <?php if (bp_get_total_friend_count(bp_loggedin_user_id())) { ?> <li id="activity-friends"><a href="<?php echo bp_loggedin_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/'; ?> " title="<?php _e('The activity of my friends only.', 'buddypress'); ?> "><?php printf(__('My Friends <span>%s</span>', 'buddypress'), bp_get_total_friend_count(bp_loggedin_user_id())); ?> </a></li> <?php } ?> <?php }
/** * Displays Friends header tabs * * @deprecated 1.6.0 * @deprecated No longer used */ function bp_friends_header_tabs() { _deprecated_function(__FUNCTION__, '1.6', 'Since BuddyPress 1.2, BP has not supported ordering of friend lists by URL parameters.'); ?> <li<?php if (!bp_action_variable(0) || bp_is_action_variable('recently-active', 0)) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/recently-active'); ?> "><?php _e('Recently Active', 'buddypress'); ?> </a></li> <li<?php if (bp_is_action_variable('newest', 0)) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/newest'); ?> "><?php _e('Newest', 'buddypress'); ?> </a></li> <li<?php if (bp_is_action_variable('alphabetically', 0)) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/alphabetically'); ?> "><?php _e('Alphabetically', 'buddypress'); ?> </a></li> <?php do_action('friends_header_tabs'); }
/** * Display the widget. * * @since 1.9.0 * * @param array $args Widget arguments. * @param array $instance The widget settings, as saved by the user. */ function widget($args, $instance) { global $members_template; extract($args); if (!bp_displayed_user_id()) { return; } $user_id = bp_displayed_user_id(); $link = trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug()); $instance['title'] = sprintf(__("%s's Friends", 'buddypress'), bp_get_displayed_user_fullname()); if (empty($instance['friend_default'])) { $instance['friend_default'] = 'active'; } /** * Filters the Friends widget title. * * @since 1.8.0 * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. * * @param string $title The widget title. * @param array $instance The settings for the particular instance of the widget. * @param string $id_base Root ID for all widgets of this type. */ $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); echo $before_widget; $title = $instance['link_title'] ? '<a href="' . esc_url($link) . '">' . esc_html($title) . '</a>' : esc_html($title); echo $before_title . $title . $after_title; $members_args = array('user_id' => absint($user_id), 'type' => sanitize_text_field($instance['friend_default']), 'max' => absint($instance['max_friends']), 'populate_extras' => 1); // Back up the global. $old_members_template = $members_template; ?> <?php if (bp_has_members($members_args)) { ?> <div class="item-options" id="friends-list-options"> <a href="<?php bp_members_directory_permalink(); ?> " id="newest-friends" <?php if ($instance['friend_default'] == 'newest') { ?> class="selected"<?php } ?> ><?php _e('Newest', 'buddypress'); ?> </a> | <a href="<?php bp_members_directory_permalink(); ?> " id="recently-active-friends" <?php if ($instance['friend_default'] == 'active') { ?> class="selected"<?php } ?> ><?php _e('Active', 'buddypress'); ?> </a> | <a href="<?php bp_members_directory_permalink(); ?> " id="popular-friends" <?php if ($instance['friend_default'] == 'popular') { ?> class="selected"<?php } ?> ><?php _e('Popular', 'buddypress'); ?> </a> </div> <ul id="friends-list" class="item-list"> <?php while (bp_members()) { bp_the_member(); ?> <li class="vcard"> <div class="item-avatar"> <a href="<?php bp_member_permalink(); ?> " title="<?php bp_member_name(); ?> "><?php bp_member_avatar(); ?> </a> </div> <div class="item"> <div class="item-title fn"><a href="<?php bp_member_permalink(); ?> " title="<?php bp_member_name(); ?> "><?php bp_member_name(); ?> </a></div> <div class="item-meta"> <?php if ('newest' == $instance['friend_default']) { ?> <span class="activity" data-livestamp="<?php bp_core_iso8601_date(bp_get_member_registered(array('relative' => false))); ?> "><?php bp_member_registered(); ?> </span> <?php } elseif ('active' == $instance['friend_default']) { ?> <span class="activity" data-livestamp="<?php bp_core_iso8601_date(bp_get_member_last_active(array('relative' => false))); ?> "><?php bp_member_last_active(); ?> </span> <?php } else { ?> <span class="activity"><?php bp_member_total_friend_count(); ?> </span> <?php } ?> </div> </div> </li> <?php } ?> </ul> <?php wp_nonce_field('bp_core_widget_friends', '_wpnonce-friends'); ?> <input type="hidden" name="friends_widget_max" id="friends_widget_max" value="<?php echo absint($instance['max_friends']); ?> " /> <?php } else { ?> <div class="widget-error"> <?php _e('Sorry, no members were found.', 'buddypress'); ?> </div> <?php } ?> <?php echo $after_widget; // Restore the global. $members_template = $old_members_template; }
/** * 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; }
/** * Return the member activity feed link. * * @since BuddyPress (1.2.0) * * @uses bp_is_profile_component() * @uses bp_is_current_action() * @uses bp_displayed_user_domain() * @uses bp_get_activity_slug() * @uses bp_is_active() * @uses bp_get_friends_slug() * @uses bp_get_groups_slug() * @uses apply_filters() To call the 'bp_get_activities_member_rss_link' hook. * * @return string $link The member activity feed link. */ function bp_get_member_activity_feed_link() { // Single member activity feed link if (bp_is_profile_component() || bp_is_current_action('just-me')) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/'; // Friend feed link } elseif (bp_is_active('friends') && bp_is_current_action(bp_get_friends_slug())) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/'; // Group feed link } elseif (bp_is_active('groups') && bp_is_current_action(bp_get_groups_slug())) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/'; // Favorites activity feed link } elseif ('favorites' === bp_current_action()) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/'; // Mentions activity feed link } elseif ('mentions' === bp_current_action() && bp_activity_do_mentions()) { $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/'; // No feed link } else { $link = ''; } /** * Filters the member activity feed link. * * @since BuddyPress (1.0.0) * * @param string $link URL for the member activity feed. */ return apply_filters('bp_get_activities_member_rss_link', $link); }
<div class="item-list-tabs" role="navigation"> <ul> <li class="selected" id="members-all"><a href="<?php echo trailingslashit(bp_get_root_domain() . '/' . bp_get_members_root_slug()); ?> "><?php printf(__('All %1s <span>%2s</span>', 'buddypress'), ucfirst(buatp_get_dir_name()), bp_get_total_member_count()); ?> </a></li> <?php if (is_user_logged_in() && bp_is_active('friends') && bp_get_total_friend_count(bp_loggedin_user_id())) { ?> <li id="members-personal"><a href="<?php echo bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends/'; ?> "><?php printf(__('My Friends <span>%s</span>', 'buddypress'), bp_get_total_friend_count(bp_loggedin_user_id())); ?> </a></li> <?php } ?> <?php do_action('bp_members_directory_member_types'); ?> </ul>
/** * Set up the component entries in the WordPress Admin Bar. * * @since 1.5.0 * * @see BP_Component::setup_nav() for a description of the $wp_admin_nav * parameter array. * @uses is_user_logged_in() * @uses trailingslashit() * @uses bp_get_total_mention_count_for_user() * @uses bp_loggedin_user_id() * @uses bp_is_active() * @uses bp_get_friends_slug() * @uses bp_get_groups_slug() * * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a * 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. $activity_link = trailingslashit(bp_loggedin_user_domain() . bp_get_activity_slug()); // Unread message count. if (bp_activity_do_mentions()) { $count = bp_get_total_mention_count_for_user(bp_loggedin_user_id()); if (!empty($count)) { $title = sprintf(_x('Mentions <span class="count">%s</span>', 'Toolbar Mention logged in user', 'buddypress'), bp_core_number_format($count)); } else { $title = _x('Mentions', 'Toolbar Mention logged in user', 'buddypress'); } } // Add the "Activity" sub menu. $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => _x('Activity', 'My Account Activity sub nav', 'buddypress'), 'href' => $activity_link); // Personal. $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-personal', 'title' => _x('Personal', 'My Account Activity sub nav', 'buddypress'), 'href' => $activity_link); // Mentions. if (bp_activity_do_mentions()) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-mentions', 'title' => $title, 'href' => trailingslashit($activity_link . 'mentions')); } // Favorite activity items. if (bp_activity_can_favorite()) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-favorites', 'title' => _x('Favorites', 'My Account Activity sub nav', 'buddypress'), 'href' => trailingslashit($activity_link . 'favorites')); } // Friends? if (bp_is_active('friends')) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-friends', 'title' => _x('Friends', 'My Account Activity sub nav', 'buddypress'), 'href' => trailingslashit($activity_link . bp_get_friends_slug())); } // Groups? if (bp_is_active('groups')) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-groups', 'title' => _x('Groups', 'My Account Activity sub nav', 'buddypress'), 'href' => trailingslashit($activity_link . bp_get_groups_slug())); } } parent::setup_admin_bar($wp_admin_nav); }
function bp_dtheme_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_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; }
/** * Set up the component entries in the WordPress Admin Bar. * * @since BuddyPress (1.5) * * @see BP_Component::setup_nav() for a description of the $wp_admin_nav * parameter array. * @uses is_user_logged_in() * @uses trailingslashit() * @uses bp_get_total_mention_count_for_user() * @uses bp_loggedin_user_id() * @uses bp_is_active() * @uses bp_get_friends_slug() * @uses bp_get_groups_slug() * * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a * 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(); $activity_link = trailingslashit($user_domain . $this->slug); // Unread message count if (bp_activity_do_mentions()) { $count = bp_get_total_mention_count_for_user(bp_loggedin_user_id()); if (!empty($count)) { $title = sprintf(__('Mentions <span class="count">%s</span>', 'buddypress'), number_format_i18n($count)); } else { $title = __('Mentions', 'buddypress'); } } // Add the "Activity" sub menu $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __('Activity', 'buddypress'), 'href' => trailingslashit($activity_link)); // Personal $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-personal', 'title' => __('Personal', 'buddypress'), 'href' => trailingslashit($activity_link)); // Mentions if (bp_activity_do_mentions()) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-mentions', 'title' => $title, 'href' => trailingslashit($activity_link . 'mentions')); } // Favorites $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-favorites', 'title' => __('Favorites', 'buddypress'), 'href' => trailingslashit($activity_link . 'favorites')); // Friends? if (bp_is_active('friends')) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-friends', 'title' => __('Friends', 'buddypress'), 'href' => trailingslashit($activity_link . bp_get_friends_slug())); } // Groups? if (bp_is_active('groups')) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-groups', 'title' => __('Groups', 'buddypress'), 'href' => trailingslashit($activity_link . bp_get_groups_slug())); } } parent::setup_admin_bar($wp_admin_nav); }