function groups_notification_new_membership_request($requesting_user_id, $admin_id, $group_id, $membership_id) { global $bp; bp_core_add_notification($requesting_user_id, $admin_id, 'groups', 'new_membership_request', $group_id); if ('no' == get_usermeta($admin_id, 'notification_groups_membership_request')) { return false; } $requesting_user_name = bp_fetch_user_fullname($requesting_user_id, false); $group = new BP_Groups_Group($group_id, false, false); $ud = get_userdata($admin_id); $requesting_ud = get_userdata($requesting_user_id); $group_request_accept = wp_nonce_url(bp_get_group_permalink($group) . '/admin/membership-requests/accept/' . $membership_id, 'groups_accept_membership_request'); $group_request_reject = wp_nonce_url(bp_get_group_permalink($group) . '/admin/membership-requests/reject/' . $membership_id, 'groups_reject_membership_request'); $profile_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $requesting_ud->user_login . '/profile'; $settings_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login . '/settings/notifications'; // Set up and send the message $to = $ud->user_email; $subject = '[' . get_blog_option(1, 'blogname') . '] ' . sprintf(__('Membership request for group: %s', 'buddypress'), stripslashes($group->name)); $message = sprintf(__('%s wants to join the group "%s". Because you are the administrator of this group, you must either accept or reject the membership request. To accept the membership request: %s To reject the membership request: %s To view %s\'s profile: %s --------------------- ', 'buddypress'), $requesting_user_name, stripslashes($group->name), $group_request_accept, $group_request_reject, $requesting_user_name, $profile_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); // Send it wp_mail($to, $subject, $message); }
/** * xprofile_record_wire_post_notification() * * Records a notification for a new profile wire post to the database and sends out a notification * email if the user has this setting enabled. * * @package BuddyPress XProfile * @param $wire_post_id The ID of the wire post * @param $user_id The id of the user that the wire post was sent to * @param $poster_id The id of the user who wrote the wire post * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() * @global $current_user WordPress global variable containing current logged in user information * @uses bp_is_home() Returns true if the current user being viewed is equal the logged in user * @uses get_usermeta() Get a user meta value based on meta key from wp_usermeta * @uses BP_Wire_Post Class Creates a new wire post object based on ID. * @uses site_url Returns the site URL * @uses wp_mail Sends an email */ function xprofile_record_wire_post_notification($wire_post_id, $user_id, $poster_id) { global $bp, $current_user; if ($bp->current_component == $bp->wire->slug && !bp_is_home()) { bp_core_add_notification($poster_id, $user_id, 'xprofile', 'new_wire_post'); if (!get_usermeta($bp->loggedin_user->id, 'notification_profile_wire_post') || 'yes' == get_usermeta($bp->loggedin_user->id, 'notification_profile_wire_post')) { $poster_name = bp_fetch_user_fullname($poster_id, false); $wire_post = new BP_Wire_Post($bp->profile->table_name_wire, $wire_post_id, true); $ud = get_userdata($user_id); $wire_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login . '/wire'; $settings_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login . '/settings/notifications'; // Set up and send the message $to = $ud->user_email; $subject = '[' . get_blog_option(1, 'blogname') . '] ' . sprintf(__('%s posted on your wire.', 'buddypress'), stripslashes($poster_name)); $message = sprintf(__('%s posted on your wire: "%s" To view your wire: %s --------------------- ', 'buddypress'), $poster_name, stripslashes($wire_post->content), $wire_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); // Send it wp_mail($to, $subject, $message); } } }
function friends_notification_accepted_request($friendship_id, $initiator_id, $friend_id) { global $bp; $friendship = new BP_Friends_Friendship($friendship_id, false, false); $friend_name = bp_fetch_user_fullname($friend_id, false); if ('no' == get_usermeta((int) $initiator_id, 'notification_friends_friendship_accepted')) { return false; } $ud = get_userdata($initiator_id); $friend_ud = get_userdata($friend_id); $friend_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $friend_ud->user_login; $settings_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login . '/settings/notifications'; // Set up and send the message $to = $ud->user_email; $subject = '[' . get_blog_option(1, 'blogname') . '] ' . sprintf(__('%s accepted your friendship request', 'buddypress'), $friend_name); $message = sprintf(__('%s accepted your friend request. To view %s\'s profile: %s --------------------- ', 'buddypress'), $friend_name, $friend_name, $friend_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); // Send it wp_mail($to, $subject, $message); }
function messages_notification_new_message($args) { global $bp; extract($args); $message = new BP_Messages_Message($item_id); $sender_name = bp_fetch_user_fullname($message->sender_id, false); for ($i = 0; $i < count($recipient_ids); $i++) { if ($message->sender_id == $recipient_ids[$i] || 'no' == get_userdata($recipient_ids[$i], 'notification-messages-new-message')) { continue; } $ud = get_userdata($recipient_ids[$i]); $message_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login . '/messages/view/' . $message->id; $settings_link = site_url() . '/' . BP_MEMBERS_SLUG . '/' . $ud->user_login . '/settings/notifications'; // Set up and send the message $to = $ud->user_email; $subject = '[' . get_blog_option(1, 'blogname') . '] ' . sprintf(__('New message from %s', 'buddypress'), stripslashes($sender_name)); $content = sprintf(__('%s sent you a new message: Subject: %s "%s" To view the message: %s --------------------- ', 'buddypress'), $sender_name, stripslashes(wp_filter_kses($message->subject)), stripslashes(wp_filter_kses($message->message)), $message_link); $content .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); // Send it wp_mail($to, $subject, $content); } }
/** * populate() * * Populate the instantiated class with data based on the User ID provided. * * @package BuddyPress Core * @global $userdata WordPress user data for the current logged in user. * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text * @uses bp_core_get_user_email() Returns the email address for the user based on user ID * @uses get_usermeta() WordPress function returns the value of passed usermeta name from usermeta table * @uses bp_core_get_avatar() Returns HTML formatted avatar for a user * @uses bp_profile_last_updated_date() Returns the last updated date for a user. */ function populate() { $this->user_url = bp_core_get_userurl($this->id); $this->user_link = bp_core_get_userlink($this->id); $this->fullname = bp_fetch_user_fullname($this->id, false); $this->email = bp_core_get_user_email($this->id); $this->last_active = bp_core_get_last_activity(get_usermeta($this->id, 'last_activity'), __('active %s ago', 'buddypress')); $this->avatar = bp_core_get_avatar($this->id, 2); $this->avatar_thumb = bp_core_get_avatar($this->id, 1); $this->avatar_mini = bp_core_get_avatar($this->id, 1, 25, 25, false); }
/** * bp_zoneideas_format_notifications() * * Formatting notifications works in very much the same way as formatting activity items. * * These notifications are "screen" notifications, that is, they appear on the notifications menu * in the site wide navigation bar. They are not for email notifications. * * You do not need to make a specific notification recording function for your component because the * notification recorded functions are bundled in the core, which is required. * * The recording is done by using bp_core_add_notification() which you can search for in this file for * zoneideass of usage. */ function bp_zoneideas_format_notifications($action, $item_id, $secondary_item_id, $total_items) { global $bp; switch ($action) { case 'new_high_five': /* In this case, $item_id is the user ID of the user who sent the high five. */ /*** * We don't want a whole list of similar notifications in a users list, so we group them. * If the user has more than one action from the same component, they are counted and the * notification is rendered differently. */ if ((int) $total_items > 1) { return apply_filters('bp_zoneideas_multiple_new_high_five_notification', '<a href="' . $bp->loggedin_user->domain . $bp->zoneideas->slug . '/screen-one/" title="' . __('Multiple high-fives', 'bp-zoneideas') . '">' . sprintf(__('%d new high-fives, multi-five!'), (int) $total_items) . '</a>', $total_items); } else { $user_fullname = bp_fetch_user_fullname($item_id, false); $user_url = bp_core_get_userurl($item_id); return apply_filters('bp_zoneideas_single_new_high_five_notification', '<a href="' . $user_url . '?new" title="' . $user_fullname . '\'s profile">' . sprintf(__('%s sent you a high-five!', 'bp-zoneideas'), $user_fullname) . '</a>', $user_fullname); } break; } do_action('bp_zoneideas_format_notifications', $action, $item_id, $secondary_item_id, $total_items); return false; }
function friends_get_friends_invite_list($user_id = false, $group_id) { global $bp; if (!$user_id) { $user_id = $bp->loggedin_user->id; } $friend_ids = friends_get_alphabetically($user_id); if ((int) $friend_ids['total'] < 1) { return false; } for ($i = 0; $i < count($friend_ids['friends']); $i++) { if (groups_check_user_has_invite($friend_ids['friends'][$i]->user_id, $group_id) || groups_is_user_member($friend_ids['friends'][$i]->user_id, $group_id)) { continue; } $display_name = bp_fetch_user_fullname($friend_ids['friends'][$i]->user_id, false); if ($display_name != ' ') { $friends[] = array('id' => $friend_ids['friends'][$i]->user_id, 'full_name' => $display_name); } } if (!$friends) { return false; } return $friends; }
/** * bp_core_global_user_fullname() * * Returns the full name for the user, or the display name if Xprofile component is not installed. * * @package BuddyPress Core * @param $user_id string The user ID of the user. * @param * @uses bp_fetch_user_fullname() Returns the full name for a user based on user ID. * @uses get_userdata() Fetches a new userdata object for the user ID passed. * @return Either the users full name, or the display name. */ function bp_core_global_user_fullname($user_id) { if (function_exists('bp_fetch_user_fullname')) { return bp_fetch_user_fullname($user_id, false); } else { $ud = get_userdata($user_id); return $current_user->display_name; } }
<?php /* Load the WP environment */ require_once preg_replace('%(.*)[/\\\\]wp-content[/\\\\].*%', '\\1', dirname(__FILE__)) . '/wp-load.php'; require_once BP_PLUGIN_DIR . '/bp-core.php'; require_once BP_PLUGIN_DIR . '/bp-friends.php'; // Setup the $bp global array as it's not auto set outside of the normal WP enviro. bp_core_setup_globals(); friends_setup_globals(); // Get the friend ids based on the search terms $friends = friends_search_friends($_GET['q'], $bp->loggedin_user->id, $_GET['limit'], 1); if ($friends['friends']) { foreach ($friends['friends'] as $user_id) { $ud = get_userdata($user_id); $username = $ud->user_login; echo bp_core_get_avatar($user_id, 1, 15, 15) . ' ' . bp_fetch_user_fullname($user_id, false) . ' (' . $username . ') '; } }
function bp_get_group_member_name() { global $members_template; return apply_filters('bp_get_group_member_name', bp_fetch_user_fullname($members_template->member->user_id, false)); }
function bp_core_widget_whos_online($args) { global $current_blog; extract($args); $options = get_blog_option($current_blog->blog_id, 'bp_core_widget_whos_online'); ?> <?php echo $before_widget; ?> <?php echo $before_title . $widget_name . $after_title; ?> <?php if (!($users = wp_cache_get('online_users', 'bp'))) { $users = BP_Core_User::get_online_users($options['max_members']); wp_cache_set('online_users', $users, 'bp'); } ?> <?php $users = BP_Core_User::get_online_users($options['max_members']); ?> <?php if ($users['users']) { ?> <div class="avatar-block"> <?php foreach ((array) $users['users'] as $user) { ?> <div class="item-avatar"> <a href="<?php echo bp_core_get_userurl($user->user_id); ?> " title="<?php bp_fetch_user_fullname($user->user_id, true); ?> "><?php echo bp_core_get_avatar($user->user_id, 1); ?> </a> </div> <?php } ?> </div> <?php if (function_exists('wp_nonce_field')) { wp_nonce_field('bp_core_widget_members', '_wpnonce-members'); } ?> <input type="hidden" name="bp_core_widget_members_max" id="bp_core_widget_members_max" value="<?php echo attribute_escape($options['max_members']); ?> " /> <?php } else { ?> <div class="widget-error"> <?php _e('There are no users currently online.', 'buddypress'); ?> </div> <?php } ?> <?php echo $after_widget; ?> <div class="clear" style="margin-bottom: 25px"></div> <?php }
/** * Notification functions are used to send email notifications to users on specific events * They will check to see the users notification settings first, if the user has the notifications * turned on, they will be sent a formatted email notification. * * You should use your own custom actions to determine when an email notification should be sent. */ function bp_zoneideas_send_high_five_notification($to_user_id, $from_user_id) { global $bp; /* Let's grab both user's names to use in the email. */ $sender_name = bp_fetch_user_fullname($from_user_id, false); $reciever_name = bp_fetch_user_fullname($to_user_id, false); /* We need to check to see if the recipient has opted not to recieve high-five emails */ if ('no' == get_usermeta((int) $to_user_id, 'notification_zoneideas_new_high_five')) { return false; } /* Get the userdata for the reciever and sender, this will include usernames and emails that we need. */ $reciever_ud = get_userdata($to_user_id); $sender_ud = get_userdata($from_user_id); if (!$bp->profile->slug) { $bp->profile->slug = 'profile'; } /* Now we need to construct the URL's that we are going to use in the email */ $sender_profile_link = site_url(MEMBERS_SLUG . '/' . $sender_ud->user_login . '/' . $bp->profile->slug); $sender_highfive_link = site_url(MEMBERS_SLUG . '/' . $sender_ud->user_login . '/' . $bp->zoneideas->slug . '/screen-one'); $reciever_settings_link = site_url(MEMBERS_SLUG . '/' . $reciever_ud->user_login . '/settings/notifications'); /* Set up and send the message */ $to = $reciever_ud->user_email; $subject = sprintf(__('%s high-fived you!', 'bp-zoneideas'), $sender_name); $message = sprintf(__('%s sent you a high-five! Why not send one back? To see %s\'s profile: %s To send %s a high five: %s --------------------- ', 'bp-zoneideas'), $sender_name, $sender_name, $sender_profile_link, $sender_name, $sender_highfive_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'bp-zoneideas'), $reciever_settings_link); // Send it! wp_mail($to, $subject, $message); }