function messages_notification_new_message($args = array())
{
// These should be extracted below
$recipients = array();
$email_subject = $email_content = '';
extract($args);
$sender_name = bp_core_get_user_displayname($sender_id);
// Bail if no recipients
if (!empty($recipients)) {
foreach ($recipients as $recipient) {
if ($sender_id == $recipient->user_id || 'no' == bp_get_user_meta($recipient->user_id, 'notification_messages_new_message', true)) {
continue;
}
// User data and links
$ud = get_userdata($recipient->user_id);
// Bail if user cannot be found
if (empty($ud)) {
continue;
}
$message_link = bp_core_get_user_domain($recipient->user_id) . bp_get_messages_slug() . '/';
$settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
$settings_link = bp_core_get_user_domain($recipient->user_id) . $settings_slug . '/notifications/';
// Sender info
$sender_name = stripslashes($sender_name);
$subject = stripslashes(wp_filter_kses($subject));
$content = stripslashes(wp_filter_kses($content));
// Set up and send the message
$email_to = $ud->user_email;
$email_subject = bp_get_email_subject(array('text' => sprintf(__('New message from %s', 'buddypress'), $sender_name)));
$email_content = sprintf(__('%1$s sent you a new message:
Subject: %2$s
"%3$s"
To view and read your messages please log in and visit: %4$s
---------------------
', 'buddypress'), $sender_name, $subject, $content, $message_link);
// Only show the disable notifications line if the settings component is enabled
if (bp_is_active('settings')) {
$email_content .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
}
// Send the message
$email_to = apply_filters('messages_notification_new_message_to', $email_to);
$email_subject = apply_filters('messages_notification_new_message_subject', $email_subject, $sender_name);
$email_content = apply_filters('messages_notification_new_message_message', $email_content, $sender_name, $subject, $content, $message_link, $settings_link);
wp_mail($email_to, $email_subject, $email_content);
}
}
do_action('bp_messages_sent_notification_email', $recipients, $email_subject, $email_content, $args);
}
function messages_screen_notices()
{
global $notice_id;
if (!is_super_admin()) {
return false;
}
$notice_id = (int) bp_action_variable(1);
if (!empty($notice_id) && is_numeric($notice_id)) {
$notice = new BP_Messages_Notice($notice_id);
if (bp_is_action_variable('deactivate', 0)) {
if (!$notice->deactivate()) {
bp_core_add_message(__('There was a problem deactivating that notice.', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Notice deactivated.', 'buddypress'));
}
} else {
if (bp_is_action_variable('activate', 0)) {
if (!$notice->activate()) {
bp_core_add_message(__('There was a problem activating that notice.', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Notice activated.', 'buddypress'));
}
} else {
if (bp_is_action_variable('delete')) {
if (!$notice->delete()) {
bp_core_add_message(__('There was a problem deleting that notice.', 'buddypress'), 'buddypress');
} else {
bp_core_add_message(__('Notice deleted.', 'buddypress'));
}
}
}
}
bp_core_redirect(bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices');
}
if (bp_action_variables()) {
bp_do_404();
return;
}
do_action('messages_screen_notices');
bp_core_load_template(apply_filters('messages_template_notices', 'members/single/home'));
}
/**
* Format notifications for the Messages component.
*
* @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 string $format Return value format. 'string' for BuddyBar-compatible
* notifications; 'array' for WP Toolbar. Default: 'string'.
* @return string|array Formatted notifications.
*/
function messages_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string')
{
$total_items = (int) $total_items;
$text = '';
$link = trailingslashit(bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox');
$title = __('Inbox', 'buddypress');
$amount = 'single';
if ('new_message' === $action) {
if ($total_items > 1) {
$amount = 'multiple';
$text = sprintf(__('You have %d new messages', 'buddypress'), $total_items);
} else {
// Get message thread ID.
$message = new BP_Messages_Message($item_id);
$thread_id = $message->thread_id;
$link = !empty($thread_id) ? bp_get_message_thread_view_link($thread_id) : false;
if (!empty($secondary_item_id)) {
$text = sprintf(__('%s sent you a new private message', 'buddypress'), bp_core_get_user_displayname($secondary_item_id));
} else {
$text = sprintf(_n('You have %s new private message', 'You have %s new private messages', $total_items, 'buddypress'), bp_core_number_format($total_items));
}
}
if ('string' === $format) {
if (!empty($link)) {
$return = '<a href="' . esc_url($link) . '" title="' . esc_attr($title) . '">' . esc_html($text) . '</a>';
} else {
$return = esc_html($text);
}
/**
* Filters the new message notification text before the notification is created.
*
* This is a dynamic filter. Possible filter names are:
* - 'bp_messages_multiple_new_message_notification'.
* - 'bp_messages_single_new_message_notification'.
*
* @param string $return Notification text.
* @param int $total_items Number of messages referred to by the notification.
* @param string $text The raw notification test (ie, not wrapped in a link).
* @param int $item_id ID of the associated item.
* @param int $secondary_item_id ID of the secondary associated item.
*/
$return = apply_filters('bp_messages_' . $amount . '_new_message_notification', $return, (int) $total_items, $text, $link, $item_id, $secondary_item_id);
} else {
/** This filter is documented in bp-messages/bp-messages-notifications.php */
$return = apply_filters('bp_messages_' . $amount . '_new_message_notification', array('text' => $text, 'link' => $link), $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id);
}
// Custom notification action for the Messages component
} else {
if ('string' === $format) {
$return = $text;
} else {
$return = array('text' => $text, 'link' => $link);
}
/**
* Backcompat for plugins that used to filter bp_messages_single_new_message_notification
* for their custom actions. These plugins should now use 'bp_messages_' . $action . '_notification'
*/
if (has_filter('bp_messages_single_new_message_notification')) {
if ('string' === $format) {
/** This filter is documented in bp-messages/bp-messages-notifications.php */
$return = apply_filters('bp_messages_single_new_message_notification', $return, (int) $total_items, $text, $link, $item_id, $secondary_item_id);
// Notice that there are seven parameters instead of six? Ugh...
} else {
/** This filter is documented in bp-messages/bp-messages-notifications.php */
$return = apply_filters('bp_messages_single_new_message_notification', $return, $link, (int) $total_items, $text, $link, $item_id, $secondary_item_id);
}
}
/**
* Filters the custom action notification before the notification is created.
*
* This is a dynamic filter based on the message notification action.
*
* @since 2.6.0
*
* @param array $value An associative array containing the text and the link of the notification
* @param int $item_id ID of the associated item.
* @param int $secondary_item_id ID of the secondary associated item.
* @param int $total_items Number of messages referred to by the notification.
* @param string $format Return value format. 'string' for BuddyBar-compatible
* notifications; 'array' for WP Toolbar. Default: 'string'.
*/
$return = apply_filters("bp_messages_{$action}_notification", $return, $item_id, $secondary_item_id, $total_items, $format);
}
/**
* Fires right before returning the formatted message notifications.
*
//.........这里部分代码省略.........
/**
* Load the Messages > Notices screen.
*
* @return false|null False on failure.
*/
function messages_screen_notices()
{
global $notice_id;
if (!bp_current_user_can('bp_moderate')) {
return false;
}
$notice_id = (int) bp_action_variable(1);
if (!empty($notice_id) && is_numeric($notice_id)) {
$notice = new BP_Messages_Notice($notice_id);
if (bp_is_action_variable('deactivate', 0)) {
if (!$notice->deactivate()) {
bp_core_add_message(__('There was a problem deactivating that notice.', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Notice deactivated.', 'buddypress'));
}
} elseif (bp_is_action_variable('activate', 0)) {
if (!$notice->activate()) {
bp_core_add_message(__('There was a problem activating that notice.', 'buddypress'), 'error');
} else {
bp_core_add_message(__('Notice activated.', 'buddypress'));
}
} elseif (bp_is_action_variable('delete')) {
if (!$notice->delete()) {
bp_core_add_message(__('There was a problem deleting that notice.', 'buddypress'), 'buddypress');
} else {
bp_core_add_message(__('Notice deleted.', 'buddypress'));
}
}
bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices'));
}
if (bp_action_variables()) {
bp_do_404();
return;
}
/**
* Fires right before the loading of the Messages notices screen template file.
*
* @since BuddyPress (1.0.0)
*/
do_action('messages_screen_notices');
/**
* Filters the template to load for the Messages notices screen.
*
* @since BuddyPress (1.0.0)
*
* @param string $template Path to the messages template to load.
*/
bp_core_load_template(apply_filters('messages_template_notices', 'members/single/home'));
}
请发表评论