本文整理汇总了PHP中messages_new_message函数的典型用法代码示例。如果您正苦于以下问题:PHP messages_new_message函数的具体用法?PHP messages_new_message怎么用?PHP messages_new_message使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了messages_new_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: messages_action_conversation
/**
* Process a request to view a single message thread.
*/
function messages_action_conversation()
{
// Bail if not viewing a single conversation
if (!bp_is_messages_component() || !bp_is_current_action('view')) {
return false;
}
// Get the thread ID from the action variable
$thread_id = (int) bp_action_variable(0);
if (!messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()));
}
// Check if a new reply has been submitted
if (isset($_POST['send'])) {
// Check the nonce
check_admin_referer('messages_send_message', 'send_message_nonce');
$new_reply = messages_new_message(array('thread_id' => $thread_id, 'subject' => !empty($_POST['subject']) ? $_POST['subject'] : false, 'content' => $_POST['content']));
// Send the reply
if (!empty($new_reply)) {
bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
} else {
bp_core_add_message(__('There was a problem sending your reply. Please try again.', 'buddypress'), 'error');
}
bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
}
// Mark message read
messages_mark_thread_read($thread_id);
/**
* Fires after processing a view request for a single message thread.
*
* @since BuddyPress (1.7.0)
*/
do_action('messages_action_conversation');
}
示例2: profile_screen_new_request
/**
* profile_screen_new_request()
*
* Action to notify site_admin that a new request has been sent
*/
function profile_screen_new_request($field_id, $field_value)
{
//required to search for superadmins
require_once ABSPATH . 'wp-admin/includes/user.php';
global $bp;
if ($field_value == __('Apply for Teacher', 'bpsp')) {
$users_search = new WP_User_Search(null, null, 'administrator');
$superadmins = $users_search->get_results();
$content = $this->request_message($bp->loggedin_user->userdata, true);
$subject = $this->request_message($bp->loggedin_user->userdata, false, true);
if (!is_super_admin()) {
messages_new_message(array('recipients' => $superadmins, 'subject' => $subject, 'content' => $content));
}
}
if ($field_value == __('Teacher', 'bpsp') && !is_super_admin()) {
wp_die(__('BuddyPress Courseware error, you are not allowed to assign Teachers.'));
}
// Add an action every time a new teacher is added
if ($field_value == __('Teacher', 'bpsp') && is_super_admin()) {
do_action('courseware_new_teacher_added', $bp->displayed_user->id);
}
// Add an action every time a teacher is removed
if ($field_value != __('Teacher', 'bpsp')) {
do_action('courseware_new_teacher_removed', $bp->displayed_user->id);
}
}
示例3: test_messages_new_message_invalid_recipient_error_message
/**
* @group messages_new_message
*/
public function test_messages_new_message_invalid_recipient_error_message()
{
$u1 = $this->factory->user->create();
// attempt to send a private message to an invalid username
$t1 = messages_new_message(array('sender_id' => $u1, 'recipients' => array('homerglumpkin'), 'subject' => 'A new message', 'content' => 'Hey there!', 'error_type' => 'wp_error'));
$this->assertSame('Message could not be sent because you have entered an invalid username. Please try again.', $t1->get_error_message());
}
示例4: create_item
/**
* Create a single message
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function create_item($request)
{
if (!empty($request['id'])) {
return new WP_Error('bp_json_message_exists', __('Cannot create existing message.', BP_API_PLUGIN_SLUG), array('status' => 400));
}
$message = $this->prepare_item_for_database($request);
$message_id = messages_new_message(array('sender_id' => $message->sender_id ? $message->sender_id : bp_loggedin_user_id(), 'thread_id' => $message->thread_id, 'recipients' => $message->recipients, 'subject' => $message->subject, 'content' => $message->content, 'date_sent' => $message->date_sent ? $message->date_sent : bp_core_current_time()));
if (!$message_id) {
return new WP_Error('bp_json_message_create', __('Error creating new message.', BP_API_PLUGIN_SLUG), array('status' => 500));
}
$this->update_additional_fields_for_object($message, $request);
/**
* Fires after a message is created via the REST API
*
* @param object $message Data used to create message
* @param WP_REST_Request $request Request object.
* @param bool $bool A boolean that is false.
*/
do_action('bp_json_insert_message', $message, $request, false);
$response = $this->get_item(array('id' => $message_id, 'context' => 'view'));
$response = rest_ensure_response($response);
$response->set_status(201);
$response->header('Location', rest_url('/users/' . $message_id));
return $response;
}
示例5: messages_action_conversation
function messages_action_conversation()
{
if (!bp_is_messages_component() || !bp_is_current_action('view')) {
return false;
}
$thread_id = (int) bp_action_variable(0);
if (!$thread_id || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()));
}
// Check if a new reply has been submitted
if (isset($_POST['send'])) {
// Check the nonce
check_admin_referer('messages_send_message', 'send_message_nonce');
// Send the reply
if (messages_new_message(array('thread_id' => $thread_id, 'subject' => !empty($_POST['subject']) ? $_POST['subject'] : false, 'content' => $_POST['content']))) {
bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
} else {
bp_core_add_message(__('There was a problem sending your reply, please try again', 'buddypress'), 'error');
}
bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
}
// Mark message read
messages_mark_thread_read($thread_id);
do_action('messages_action_conversation');
}
示例6: messages_action_view_message
function messages_action_view_message()
{
global $thread_id, $bp;
if (!bp_is_messages_component() || !bp_is_current_action('view')) {
return false;
}
$thread_id = (int) bp_action_variable(0);
if (!$thread_id || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !is_super_admin()) {
bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug());
}
// Check if a new reply has been submitted
if (isset($_POST['send'])) {
// Check the nonce
check_admin_referer('messages_send_message', 'send_message_nonce');
// Send the reply
if (messages_new_message(array('thread_id' => $thread_id, 'subject' => $_POST['subject'], 'content' => $_POST['content']))) {
bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
} else {
bp_core_add_message(__('There was a problem sending your reply, please try again', 'buddypress'), 'error');
}
bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
}
// Mark message read
messages_mark_thread_read($thread_id);
// Decrease the unread count in the nav before it's rendered
$name = sprintf(__('Messages <span>%s</span>', 'buddypress'), bp_get_total_unread_messages_count());
$bp->bp_nav[$bp->messages->slug]['name'] = $name;
do_action('messages_action_view_message');
bp_core_new_subnav_item(array('name' => sprintf(__('From: %s', 'buddypress'), BP_Messages_Thread::get_last_sender($thread_id)), 'slug' => 'view', 'parent_url' => trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()), 'parent_slug' => bp_get_messages_slug(), 'screen_function' => true, 'position' => 40, 'user_has_access' => bp_is_my_profile(), 'link' => bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . (int) $thread_id));
bp_core_load_template(apply_filters('messages_template_view_message', 'members/single/home'));
}
示例7: test_messages_new_message_wp_error_generic
/**
* @group messages_new_message
*/
public function test_messages_new_message_wp_error_generic()
{
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
// Emulate a plugin disabling messages.
add_action('messages_message_before_save', array($this, 'remove_recipients_before_save'));
// send a private message
$t1 = messages_new_message(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'A new message', 'content' => 'Hey there!', 'error_type' => 'wp_error'));
$this->assertNotEmpty($t1->get_error_code());
remove_action('messages_message_before_save', array($this, 'remove_recipients_before_save'));
}
示例8: bp_send_harmony_message
function bp_send_harmony_message($user1, $user2)
{
global $bp;
//check_admin_referer(message_check”); // adjust if needed
$sender_id = $user1;
// moderator id ?
$recip_id = $user2;
// denied image user id ?
$nameofreciept = bp_get_profile_field_data('field=Name&user_id=' . $user2);
if ($thread_id = messages_new_message(array('sender_id' => $sender_id, 'subject' => 'You have a match!', 'content' => 'Let me introduce you to ' . $nameofreciept, 'recipients' => $recip_id))) {
// bp_core_add_message( __( 'Image Denied Message was sent.', 'buddypress' ) );
} else {
// bp_core_add_message( __( 'There was an error sending that Private Message.', 'buddypress' ), 'error' );
}
}
示例9: send_message
/**
* send_message( $data )
*
* Generates a message about graded assignment and sends it to the student
* @param Mixed $data required to send the message etc...
*/
function send_message($data)
{
if (isset($data['grade'])) {
$content = $this->gradebook_update_message($data, true);
$subject = $this->gradebook_update_message($data, false, true);
$recipients = $data['grade']['uid'];
} elseif (isset($data['response'])) {
$content = $this->response_added_message($data, true);
$subject = $this->response_added_message($data, false, true);
$recipients = $data['assignment']->post_author;
}
// Hack: ob_*() - to get rid of nasy warnings on messages_new_message()
ob_start();
messages_new_message(array('recipients' => $recipients, 'subject' => $subject, 'content' => $content));
ob_clean();
}
示例10: test_get_unread_count
/**
* @group counts
*/
public function test_get_unread_count()
{
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
// send a private message
$t1 = messages_new_message(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'A new message', 'content' => 'Hey there!'));
// get unread count for $u2
$this->set_current_user($u2);
$this->assertEquals(1, messages_get_unread_count($u2));
// send another message and get recheck unread count
$t2 = messages_new_message(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'A new message', 'content' => 'Hey there!'));
$this->assertEquals(2, messages_get_unread_count($u2));
// mark one message as read
messages_mark_thread_read($t1);
// recheck unread count
$this->assertEquals(1, messages_get_unread_count($u2));
}
示例11: messages_screen_compose
function messages_screen_compose()
{
global $bp;
if (bp_action_variables()) {
bp_do_404();
return;
}
// Remove any saved message data from a previous session.
messages_remove_callback_values();
// Check if the message form has been submitted
if (isset($_POST['send'])) {
// Check the nonce
check_admin_referer('messages_send_message');
// Check we have what we need
if (empty($_POST['subject']) || empty($_POST['content'])) {
bp_core_add_message(__('There was an error sending that message, please try again', 'buddypress'), 'error');
} else {
// If this is a notice, send it
if (isset($_POST['send-notice'])) {
if (messages_send_notice($_POST['subject'], $_POST['content'])) {
bp_core_add_message(__('Notice sent successfully!', 'buddypress'));
bp_core_redirect($bp->loggedin_user->domain . $bp->messages->slug . '/inbox/');
} else {
bp_core_add_message(__('There was an error sending that notice, please try again', 'buddypress'), 'error');
}
} else {
// Filter recipients into the format we need - array( 'username/userid', 'username/userid' )
$autocomplete_recipients = explode(',', $_POST['send-to-input']);
$typed_recipients = explode(' ', $_POST['send_to_usernames']);
$recipients = array_merge((array) $autocomplete_recipients, (array) $typed_recipients);
$recipients = apply_filters('bp_messages_recipients', $recipients);
// Send the message
if ($thread_id = messages_new_message(array('recipients' => $recipients, 'subject' => $_POST['subject'], 'content' => $_POST['content']))) {
bp_core_add_message(__('Message sent successfully!', 'buddypress'));
bp_core_redirect($bp->loggedin_user->domain . $bp->messages->slug . '/view/' . $thread_id . '/');
} else {
bp_core_add_message(__('There was an error sending that message, please try again', 'buddypress'), 'error');
}
}
}
}
do_action('messages_screen_compose');
bp_core_load_template(apply_filters('messages_template_compose', 'members/single/home'));
}
示例12: profile_screen_new_request
/**
* profile_screen_new_request( $field_id, $field_value )
*
* Action to notify site_admin that a new request has been sent
* @param Int $field_id, the id of the xprofile field
* @param String $field_value, the value of the field
*/
function profile_screen_new_request($field_id, $field_value)
{
global $bp;
if ($field_value == __('Apply for Teacher', 'bpsp')) {
$superadmins = self::get_admins();
$content = $this->request_message($bp->loggedin_user->userdata, true);
$subject = $this->request_message($bp->loggedin_user->userdata, false, true);
if (!is_super_admin()) {
messages_new_message(array('recipients' => $superadmins, 'subject' => $subject, 'content' => $content));
}
}
if ($field_value == __('Teacher', 'bpsp') && !is_super_admin()) {
wp_die(__('BuddyPress Courseware error, you are not allowed to assign Teachers.', 'bpsp'));
}
// Add an action every time a new teacher is added
if ($field_value == __('Teacher', 'bpsp') && is_super_admin()) {
do_action('courseware_new_teacher_added', $bp->displayed_user->id);
}
// Add an action every time a teacher is removed
if ($field_value != __('Teacher', 'bpsp')) {
do_action('courseware_new_teacher_removed', $bp->displayed_user->id);
}
}
示例13: bp_legacy_theme_ajax_messages_send_reply
/**
* Send a private message reply to a thread via a POST request.
*
* @return string HTML
* @since BuddyPress (1.2)
*/
function bp_legacy_theme_ajax_messages_send_reply()
{
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
check_ajax_referer('messages_send_message');
$result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
if (!empty($result)) {
// Get the zebra line classes correct on ajax requests
global $thread_template;
bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id']));
if ($thread_template->message_count % 2 == 1) {
$class = 'odd';
} else {
$class = 'even alt';
}
?>
<div class="message-box new-message <?php
echo $class;
?>
">
<div class="message-metadata">
<?php
do_action('bp_before_message_meta');
?>
<?php
echo bp_loggedin_user_avatar('type=thumb&width=30&height=30');
?>
<strong><a href="<?php
echo bp_loggedin_user_domain();
?>
"><?php
bp_loggedin_user_fullname();
?>
</a> <span class="activity"><?php
printf(__('Sent %s', 'buddypress'), bp_core_time_since(bp_core_current_time()));
?>
</span></strong>
<?php
do_action('bp_after_message_meta');
?>
</div>
<?php
do_action('bp_before_message_content');
?>
<div class="message-content">
<?php
echo stripslashes(apply_filters('bp_get_the_thread_message_content', $_REQUEST['content']));
?>
</div>
<?php
do_action('bp_after_message_content');
?>
<div class="clear"></div>
</div>
<?php
} else {
echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>';
}
exit;
}
示例14: test_get_recipients_cache_should_be_busted_when_thread_message_is_sent
/**
* @group get_recipients
* @group cache
*/
public function test_get_recipients_cache_should_be_busted_when_thread_message_is_sent()
{
global $wpdb;
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
$t1 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'Foo'));
$thread = new BP_Messages_Thread($t1);
$recipients = $thread->get_recipients();
// Verify that the cache is populated.
$num_queries = $wpdb->num_queries;
$recipients_cached = $thread->get_recipients();
$this->assertEquals($num_queries, $wpdb->num_queries);
messages_new_message(array('sender_id' => $u2, 'thread_id' => $t1, 'recipients' => array($u1), 'subject' => 'Bar', 'content' => 'Baz'));
// Cache should be empty.
$num_queries = $wpdb->num_queries;
$recipients_uncached = $thread->get_recipients();
$this->assertEquals($num_queries + 1, $wpdb->num_queries);
}
示例15: wplms_instructor_reply_user_comment
function wplms_instructor_reply_user_comment()
{
$id = $_POST['id'];
$message = $_POST['message'];
if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'security') || !is_numeric($id)) {
_e('Security check Failed. Contact Administrator.', 'vibe');
die;
}
if (bp_is_active('messages')) {
$user_id = get_current_user_id();
$instructor_ids = apply_filters('wplms_course_instructors', get_post_field('post_author', $id), $id);
if (!is_array($instructor_ids)) {
$instructor_ids = array($instructor_ids);
}
$message .= ' <a href="' . get_permalink($id) . '">' . get_the_title($id) . '</a>';
foreach ($instructor_ids as $instructor_id) {
messages_new_message(array('sender_id' => $user_id, 'subject' => sprintf(__('Instructor reply requested for unit %s paragraph %s', 'vibe'), get_the_title($id), $_POST['section']), 'content' => $message, 'recipients' => $instructor_id));
echo 'balle';
}
}
die;
}