本文整理汇总了PHP中bp_core_add_notification函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_core_add_notification函数的具体用法?PHP bp_core_add_notification怎么用?PHP bp_core_add_notification使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bp_core_add_notification函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xprofile_record_wire_post_notification
/**
* 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);
}
}
}
示例2: bp_activity_at_message_notification
/**
* Sends an email notification and a BP notification when someone mentions you in an update
*
* @since BuddyPress (1.2)
*
* @param int $activity_id The id of the activity update
* @param int $receiver_user_id The unique user_id of the user who is receiving the update
*
* @uses bp_core_add_notification()
* @uses bp_get_user_meta()
* @uses bp_core_get_user_displayname()
* @uses bp_activity_get_permalink()
* @uses bp_core_get_user_domain()
* @uses bp_get_settings_slug()
* @uses bp_activity_filter_kses()
* @uses bp_core_get_core_userdata()
* @uses wp_specialchars_decode()
* @uses get_blog_option()
* @uses bp_is_active()
* @uses bp_is_group()
* @uses bp_get_current_group_name()
* @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook
* @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook
* @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook
* @uses wp_mail()
* @uses do_action() To call the 'bp_activity_sent_mention_email' hook
*/
function bp_activity_at_message_notification($activity_id, $receiver_user_id)
{
// Don't leave multiple notifications for the same activity item
$notifications = BP_Core_Notification::get_all_for_user($receiver_user_id, 'all');
foreach ($notifications as $notification) {
if ($activity_id == $notification->item_id) {
return;
}
}
$activity = new BP_Activity_Activity($activity_id);
$subject = '';
$message = '';
$content = '';
// Add the BP notification
bp_core_add_notification($activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id);
// Now email the user with the contents of the message (if they have enabled email notifications)
if ('no' != bp_get_user_meta($receiver_user_id, 'notification_activity_new_mention', true)) {
$poster_name = bp_core_get_user_displayname($activity->user_id);
$message_link = bp_activity_get_permalink($activity_id);
$settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
$settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
$poster_name = stripslashes($poster_name);
$content = bp_activity_filter_kses(strip_tags(stripslashes($activity->content)));
// Set up and send the message
$ud = bp_core_get_core_userdata($receiver_user_id);
$to = $ud->user_email;
$subject = bp_get_email_subject(array('text' => sprintf(__('%s mentioned you in an update', 'buddypress'), $poster_name)));
if (bp_is_active('groups') && bp_is_group()) {
$message = sprintf(__('%1$s mentioned you in the group "%2$s":
"%3$s"
To view and respond to the message, log in and visit: %4$s
---------------------
', 'buddypress'), $poster_name, bp_get_current_group_name(), $content, $message_link);
} else {
$message = sprintf(__('%1$s mentioned you in an update:
"%2$s"
To view and respond to the message, log in and visit: %3$s
---------------------
', 'buddypress'), $poster_name, $content, $message_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('bp_activity_at_message_notification_to', $to);
$subject = apply_filters('bp_activity_at_message_notification_subject', $subject, $poster_name);
$message = apply_filters('bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link);
wp_mail($to, $subject, $message);
}
do_action('bp_activity_sent_mention_email', $activity, $subject, $message, $content);
}
示例3: social_articles_send_notification
function social_articles_send_notification($id)
{
global $bp, $socialArticles;
$savedPost = get_post($id);
$notification_already_sent = get_post_meta($id, 'notification_already_sent', true);
if (empty($notification_already_sent) && function_exists("friends_get_friend_user_ids") && $savedPost->post_status == "publish" && $savedPost->post_type == "post" && !wp_is_post_revision($id) && $socialArticles->options['bp_notifications'] == "true") {
$friends = friends_get_friend_user_ids($savedPost->post_author);
foreach ($friends as $friend) {
bp_core_add_notification($savedPost->ID, $friend, $bp->social_articles->id, 'new_article' . $savedPost->ID, $savedPost->post_author);
}
bp_core_add_notification($savedPost->ID, $savedPost->post_author, $bp->social_articles->id, 'new_article' . $savedPost->ID, -1);
update_post_meta($id, 'notification_already_sent', true);
}
}
示例4: bp_activity_at_message_notification
/**
* Sends an email notification and a BP notification when someone mentions you in an update
*
* @since 1.2.0
*
* @param int $activity_id The id of the activity update
* @param int $receiver_user_id The unique user_id of the user who is receiving the update
*
* @global object $bp BuddyPress global settings
* @uses bp_core_add_notification()
* @uses bp_get_user_meta()
* @uses bp_core_get_user_displayname()
* @uses bp_activity_get_permalink()
* @uses bp_core_get_user_domain()
* @uses bp_get_settings_slug()
* @uses bp_activity_filter_kses()
* @uses bp_core_get_core_userdata()
* @uses nxt_specialchars_decode()
* @uses get_blog_option()
* @uses bp_is_active()
* @uses bp_is_group()
* @uses bp_get_current_group_name()
* @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook
* @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook
* @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook
* @uses nxt_mail()
* @uses do_action() To call the 'bp_activity_sent_mention_email' hook
*/
function bp_activity_at_message_notification($activity_id, $receiver_user_id)
{
global $bp;
$activity = new BP_Activity_Activity($activity_id);
$subject = '';
$message = '';
// Add the BP notification
bp_core_add_notification($activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id);
// Now email the user with the contents of the message (if they have enabled email notifications)
if ('no' != bp_get_user_meta($receiver_user_id, 'notification_activity_new_mention', true)) {
$poster_name = bp_core_get_user_displayname($activity->user_id);
$message_link = bp_activity_get_permalink($activity_id);
$settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
$settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
$poster_name = stripslashes($poster_name);
$content = bp_activity_filter_kses(strip_tags(stripslashes($activity->content)));
// Set up and send the message
$ud = bp_core_get_core_userdata($receiver_user_id);
$to = $ud->user_email;
$sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
$subject = '[' . $sitename . '] ' . sprintf(__('%s mentioned you in an update', 'buddypress'), $poster_name);
if (bp_is_active('groups') && bp_is_group()) {
$message = sprintf(__('%1$s mentioned you in the group "%2$s":
"%3$s"
To view and respond to the message, log in and visit: %4$s
---------------------
', 'buddypress'), $poster_name, bp_get_current_group_name(), $content, $message_link);
} else {
$message = sprintf(__('%1$s mentioned you in an update:
"%2$s"
To view and respond to the message, log in and visit: %3$s
---------------------
', 'buddypress'), $poster_name, $content, $message_link);
}
$message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
/* Send the message */
$to = apply_filters('bp_activity_at_message_notification_to', $to);
$subject = apply_filters('bp_activity_at_message_notification_subject', $subject, $poster_name);
$message = apply_filters('bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link);
nxt_mail($to, $subject, $message);
}
do_action('bp_activity_sent_mention_email', $activity, $subject, $message, $content);
}
示例5: bp_em_add_booking_notification
/**
* Catch booking saves and add a BP notification.
* @param boolean $result
* @param EM_Booking $EM_Booking
* @return boolean
*/
function bp_em_add_booking_notification($result, $EM_Booking)
{
global $bp;
if (get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
$action = 'pending_booking';
} elseif ($EM_Booking->get_status() == 1 || get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
$action = 'confirmed_booking';
} elseif ($EM_Booking->get_status() == 3) {
$action = 'cancelled_booking';
}
if (!empty($action)) {
bp_core_add_notification($EM_Booking->booking_id, $EM_Booking->get_event()->get_contact()->ID, 'events', $action);
}
return $result;
}
示例6: bp_follow_notifications_add_on_follow
/**
* Adds notification when a user follows another user.
*
* @since 1.2.1
*
* @param object $follow The BP_Follow object.
*/
function bp_follow_notifications_add_on_follow(BP_Follow $follow)
{
// this only applies to users
if (!empty($follow->follow_type)) {
return;
}
// Add a screen notification
//
// BP 1.9+
if (bp_is_active('notifications')) {
bp_notifications_add_notification(array('item_id' => $follow->follower_id, 'user_id' => $follow->leader_id, 'component_name' => buddypress()->follow->id, 'component_action' => 'new_follow'));
// BP < 1.9 - add notifications the old way
} elseif (!class_exists('BP_Core_Login_Widget')) {
global $bp;
bp_core_add_notification($follow->follower_id, $follow->leader_id, $bp->follow->id, 'new_follow');
}
// Add an email notification
bp_follow_new_follow_email_notification(array('leader_id' => $follow->leader_id, 'follower_id' => $follow->follower_id));
}
示例7: ac_notifier_notify
/**
* storing notification for users
* notify all the users who have commented, or who was the original poster of the update, when someone comments
* hook to activity_comment_posted action
*/
function ac_notifier_notify($comment_id, $params)
{
global $bp;
extract($params);
$users = ac_notifier_find_involved_persons($activity_id);
$activity = new BP_Activity_Activity($activity_id);
//since there is a bug in bp 1.2.9 and causes trouble with private notificatin, so let us not notify for any of the private activities
if ($activity->hide_sitewide) {
return;
}
//push the original poster user_id, if the original poster has not commented on his/her status yet
if (!in_array($activity->user_id, $users) && $bp->loggedin_user->id != $activity->user_id) {
//if someone else is commenting
array_push($users, $activity->user_id);
}
foreach ((array) $users as $user_id) {
//create a notification
bp_core_add_notification($activity_id, $user_id, $bp->ac_notifier->id, 'new_activity_comment_' . $activity_id);
//a hack to not allow grouping by component,action, rather group by component and individual action item
}
}
示例8: friends_accept_friendship
function friends_accept_friendship($friendship_id)
{
global $bp;
$friendship = new BP_Friends_Friendship($friendship_id, true, false);
if (!$friendship->is_confirmed && BP_Friends_Friendship::accept($friendship_id)) {
friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id);
// Remove the friend request notice
bp_core_delete_notifications_by_item_id($friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request');
// Add a friend accepted notice for the initiating user
bp_core_add_notification($friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted');
$initiator_link = bp_core_get_userlink($friendship->initiator_user_id);
$friend_link = bp_core_get_userlink($friendship->friend_user_id);
// Record in activity streams for the initiator
friends_record_activity(array('user_id' => $friendship->initiator_user_id, 'type' => 'friendship_created', 'action' => apply_filters('friends_activity_friendship_accepted_action', sprintf(__('%1$s and %2$s are now friends', 'buddypress'), $initiator_link, $friend_link), $friendship), 'item_id' => $friendship_id, 'secondary_item_id' => $friendship->friend_user_id));
// Record in activity streams for the friend
friends_record_activity(array('user_id' => $friendship->friend_user_id, 'type' => 'friendship_created', 'action' => apply_filters('friends_activity_friendship_accepted_action', sprintf(__('%1$s and %2$s are now friends', 'buddypress'), $friend_link, $initiator_link), $friendship), 'item_id' => $friendship_id, 'secondary_item_id' => $friendship->initiator_user_id, 'hide_sitewide' => true));
// Send the email notification
friends_notification_accepted_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
return true;
}
return false;
}
示例9: bp_zoneideas_send_highfive
/**
* bp_zoneideas_send_high_five()
*
* Sends a high five message to a user. Registers an notification to the user
* via their notifications menu, as well as sends an email to the user.
*
* Also records an activity stream item saying "User 1 high-fived User 2".
*/
function bp_zoneideas_send_highfive($to_user_id, $from_user_id)
{
global $bp;
if (!check_admin_referer('bp_zoneideas_send_high_five')) {
return false;
}
/**
* We'll store high-fives as usermeta, so we don't actually need
* to do any database querying. If we did, and we were storing them
* in a custom DB table, we'd want to reference a function in
* bp-zoneideas-classes.php that would run the SQL query.
*/
/* Get existing fives */
$existing_fives = maybe_unserialize(get_usermeta($to_user_id, 'high-fives'));
/* Check to see if the user has already high-fived. That's okay, but lets not
* store duplicate high-fives in the database. What's the point, right?
*/
if (!in_array($from_user_id, (array) $existing_fives)) {
$existing_fives[] = (int) $from_user_id;
/* Now wrap it up and fire it back to the database overlords. */
update_usermeta($to_user_id, 'high-fives', serialize($existing_fives));
}
/***
* Now we've registered the new high-five, lets work on some notification and activity
* stream magic.
*/
/***
* Post a screen notification to the user's notifications menu.
* Remember, like activity streams we need to tell the activity stream component how to format
* this notification in bp_zoneideas_format_notifications() using the 'new_high_five' action.
*/
bp_core_add_notification($from_user_id, $to_user_id, $bp->zoneideas->slug, 'new_high_five');
/* Now record the new 'new_high_five' activity item */
bp_zoneideas_record_activity(array('item_id' => $to_user_id, 'user_id' => $from_user_id, 'component_name' => $bp->zoneideas->slug, 'component_action' => 'new_high_five', 'is_private' => 0));
/* We'll use this do_action call to send the email notification. See bp-zoneideas-notifications.php */
do_action('bp_zoneideas_send_high_five', $to_user_id, $from_user_id);
return true;
}
示例10: groups_notification_group_invites
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
global $bp;
$inviter_ud = bp_core_get_core_userdata($inviter_user_id);
$inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
$inviter_link = bp_core_get_user_domain($inviter_user_id);
$group_link = bp_get_group_permalink($group);
if (!$member->invite_sent) {
$invited_user_id = $member->user_id;
// Post a screen notification first.
bp_core_add_notification($group->id, $invited_user_id, 'groups', 'group_invite');
if ('no' == bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
return false;
}
$invited_ud = bp_core_get_core_userdata($invited_user_id);
$settings_link = bp_core_get_user_domain($invited_user_id) . bp_get_settings_slug() . '/notifications/';
$invited_link = bp_core_get_user_domain($invited_user_id);
$invites_link = $invited_link . bp_get_groups_slug() . '/invites';
// Set up and send the message
$to = $invited_ud->user_email;
$sitename = wp_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
$subject = '[' . $sitename . '] ' . sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name);
$message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".
To view your group invites visit: %3$s
To view the group visit: %4$s
To view %5$s\'s profile visit: %6$s
---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link);
$message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
/* Send the message */
$to = apply_filters('groups_notification_group_invites_to', $to);
$subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
$message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
wp_mail($to, $subject, $message);
do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
}
}
示例11: bp_compliments_notifications_add_on_compliment
/**
* Add a notification when a compliment get submitted.
*
* @since 0.0.2
* @package BuddyPress_Compliments
*
* @global object $bp BuddyPress instance.
* @param BP_Compliments $compliment The compliment object.
*/
function bp_compliments_notifications_add_on_compliment(BP_Compliments $compliment)
{
// Add a screen notification
// BP 1.9+
if (bp_is_active('notifications')) {
bp_notifications_add_notification(array('item_id' => $compliment->sender_id, 'user_id' => $compliment->receiver_id, 'secondary_item_id' => $compliment->id, 'component_name' => buddypress()->compliments->id, 'component_action' => 'new_compliment'));
// BP < 1.9 - add notifications the old way
} elseif (!class_exists('BP_Core_Login_Widget')) {
global $bp;
bp_core_add_notification($compliment->sender_id, $compliment->receiver_id, $bp->compliments->id, 'new_compliment');
}
// Add an email notification
bp_compliments_new_compliment_email_notification(array('receiver_id' => $compliment->receiver_id, 'sender_id' => $compliment->sender_id));
}
示例12: friends_accept_friendship
function friends_accept_friendship($friendship_id)
{
/* Check the nonce */
if (!check_admin_referer('friends_accept_friendship')) {
return false;
}
$friendship = new BP_Friends_Friendship($friendship_id, true, false);
if (!$friendship->is_confirmed && BP_Friends_Friendship::accept($friendship_id)) {
friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id);
// Remove the friend request notice
bp_core_delete_notifications_for_user_by_item_id($friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_request');
// Add a friend accepted notice for the initiating user
bp_core_add_notification($friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_accepted');
// Record in activity streams
friends_record_activity(array('item_id' => $friendship_id, 'component_name' => $bp->friends->slug, 'component_action' => 'friendship_accepted', 'is_private' => 0, 'user_id' => $friendship->initiator_user_id, 'secondary_user_id' => $friendship->friend_user_id));
// Send the email notification
require_once BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php';
friends_notification_accepted_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
return true;
}
return false;
}
示例13: groups_notification_group_invites
function groups_notification_group_invites(&$group, &$member, $inviter_user_id)
{
// @todo $inviter_up may be used for caching, test without it
$inviter_ud = bp_core_get_core_userdata($inviter_user_id);
$inviter_name = bp_core_get_userlink($inviter_user_id, true, false, true);
$inviter_link = bp_core_get_user_domain($inviter_user_id);
$group_link = bp_get_group_permalink($group);
if (!$member->invite_sent) {
$invited_user_id = $member->user_id;
// Post a screen notification first.
bp_core_add_notification($group->id, $invited_user_id, 'groups', 'group_invite');
if ('no' == bp_get_user_meta($invited_user_id, 'notification_groups_invite', true)) {
return false;
}
$invited_ud = bp_core_get_core_userdata($invited_user_id);
$settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
$settings_link = bp_core_get_user_domain($invited_user_id) . $settings_slug . '/notifications/';
$invited_link = bp_core_get_user_domain($invited_user_id);
$invites_link = trailingslashit($invited_link . bp_get_groups_slug() . '/invites');
// Set up and send the message
$to = $invited_ud->user_email;
$subject = bp_get_email_subject(array('text' => sprintf(__('You have an invitation to the group: "%s"', 'buddypress'), $group->name)));
$message = sprintf(__('One of your friends %1$s has invited you to the group: "%2$s".
To view your group invites visit: %3$s
To view the group visit: %4$s
To view %5$s\'s profile visit: %6$s
---------------------
', 'buddypress'), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_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('groups_notification_group_invites_to', $to);
$subject = apply_filters_ref_array('groups_notification_group_invites_subject', array($subject, &$group));
$message = apply_filters_ref_array('groups_notification_group_invites_message', array($message, &$group, $inviter_name, $inviter_link, $invites_link, $group_link, $settings_link));
wp_mail($to, $subject, $message);
do_action('bp_groups_sent_invited_email', $invited_user_id, $subject, $message, $group);
}
}
示例14: xprofile_action_new_wire_post
/**
* xprofile_action_new_wire_post()
*
* Posts a new wire post to the users profile wire.
*
* @package BuddyPress XProfile
* @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
* @uses bp_wire_new_post() Adds a new wire post to a specific wire using the ID of the item passed and the table name.
* @uses bp_core_add_message() Adds an error/success message to the session to be displayed on the next page load.
* @uses bp_core_redirect() Safe redirects to a new page using the wp_redirect() function
*/
function xprofile_action_new_wire_post()
{
global $bp;
if ($bp->current_component != $bp->wire->slug) {
return false;
}
if ('post' != $bp->current_action) {
return false;
}
/* Check the nonce */
if (!check_admin_referer('bp_wire_post')) {
return false;
}
if (!($wire_post_id = bp_wire_new_post($bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire))) {
bp_core_add_message(__('Wire message could not be posted. Please try again.', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Wire message successfully posted.', 'buddypress'));
if (!bp_is_home()) {
/* Record the notification for the user */
bp_core_add_notification($bp->loggedin_user->id, $bp->displayed_user->id, 'profile', 'new_wire_post');
}
do_action('xprofile_new_wire_post', $wire_post_id);
}
if (!strpos($_SERVER['HTTP_REFERER'], $bp->wire->slug)) {
bp_core_redirect($bp->displayed_user->domain);
} else {
bp_core_redirect($bp->displayed_user->domain . $bp->wire->slug);
}
}
示例15: add_notification
/**
* Adds a new post notification
* @uses publish_post action
* @param int $post_id
* @param obj $post
* @return void
*/
public function add_notification($post_id, $post)
{
// Bail early if post_type isn't post or if post has already been published
if (get_post_type($post) !== 'post' || $_POST['original_post_status'] == 'publish') {
return;
}
// Get all subscribers
$subscribers = get_option('bp_site_subscriber_subscribers', array());
// Bail early if no subscribers
if (empty($subscribers)) {
return;
}
$subscribers = array_values($subscribers);
$subscribers = array_unique($subscribers);
$link = get_permalink($post_id);
$title = get_the_title($post_id);
$site_name = get_option('blogname');
foreach ($subscribers as $subscriber) {
if ($subscriber != $post->post_author && !in_array($subscriber, $sent)) {
// Notify
bp_core_add_notification($post_id, $subscriber, $this->id, 'new_post_' . $post_id, get_current_blog_id());
// Mail
if ('no' != bp_get_user_meta($subscriber, 'bp-site-subscriber-send-email', true)) {
$user = get_userdata($subscriber);
$email = $user->user_email;
$profile_link = bp_core_get_user_domain($subscriber);
$subject = sprintf(__('New post on the site %s', 'bp-site-subscriber'), $site_name);
$message = sprintf(__("New post %s (%s) on the site %s \n\n--------------------\n\n Go to your profile to disable these emails: %s", 'bp-site-subscriber'), $title, $link, $site_name, $profile_link);
wp_mail($email, $subject, $message);
}
}
}
}