当前位置: 首页>>代码示例>>PHP>>正文


PHP BP_Messages_Thread::get_recipients方法代码示例

本文整理汇总了PHP中BP_Messages_Thread::get_recipients方法的典型用法代码示例。如果您正苦于以下问题:PHP BP_Messages_Thread::get_recipients方法的具体用法?PHP BP_Messages_Thread::get_recipients怎么用?PHP BP_Messages_Thread::get_recipients使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BP_Messages_Thread的用法示例。


在下文中一共展示了BP_Messages_Thread::get_recipients方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bp_messages_message_delete_notifications

/**
 * When a message is deleted, delete corresponding notifications.
 *
 * @since BuddyPress (2.0.0)
 *
 * @param int   $thread_id   ID of the thread.
 * @param array $message_ids IDs of the messages.
 */
function bp_messages_message_delete_notifications($thread_id, $message_ids)
{
    if (!bp_is_active('notifications')) {
        return;
    }
    // For each recipient, delete notifications corresponding to each message.
    $thread = new BP_Messages_Thread($thread_id);
    foreach ($thread->get_recipients() as $recipient) {
        foreach ($message_ids as $message_id) {
            bp_notifications_delete_notifications_by_item_id($recipient->user_id, (int) $message_id, buddypress()->messages->id, 'new_message');
        }
    }
}
开发者ID:kosir,项目名称:thatcamp-org,代码行数:21,代码来源:bp-messages-notifications.php

示例2: messages_new_message

function messages_new_message( $args = '' ) {
	global $bp;

	$defaults = array(
		'thread_id' => false, // false for a new message, thread id for a reply to a thread.
		'sender_id' => $bp->loggedin_user->id,
		'recipients' => false, // Can be an array of usernames, user_ids or mixed.
		'subject' => false,
		'content' => false,
		'date_sent' => bp_core_current_time()
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	if ( !$sender_id || !$content )
		return false;

	/* Create a new message object */
	$message = new BP_Messages_Message;
	$message->thread_id = $thread_id;
	$message->sender_id = $sender_id;
	$message->subject = $subject;
	$message->message = $content;
	$message->date_sent = $date_sent;

	// If we have a thread ID, use the existing recipients, otherwise use the recipients passed
	if ( $thread_id ) {
		$thread = new BP_Messages_Thread( $thread_id );
		$message->recipients = $thread->get_recipients();

		// Strip the sender from the recipient list if they exist
		if ( isset( $message->recipients[$sender_id] ) )
			unset( $message->recipients[$sender_id] );

		if ( empty( $message->subject ) )
			$message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject );

	// No thread ID, so make some adjustments
	} else {
		if ( empty( $recipients ) )
			return false;

		if ( empty( $message->subject ) )
			$message->subject = __( 'No Subject', 'buddypress' );

		/* Loop the recipients and convert all usernames to user_ids where needed */
		foreach( (array) $recipients as $recipient ) {
			if ( is_numeric( trim( $recipient ) ) )
				$recipient_ids[] = (int)trim( $recipient );

			if ( $recipient_id = bp_core_get_userid( trim( $recipient ) ) )
				$recipient_ids[] = (int)$recipient_id;
		}

		/* Strip the sender from the recipient list if they exist */
		if ( $key = array_search( $sender_id, (array)$recipient_ids ) )
			unset( $recipient_ids[$key] );

		/* Remove duplicates */
		$recipient_ids = array_unique( (array)$recipient_ids );

		if ( empty( $recipient_ids ) )
			return false;

		/* Format this to match existing recipients */
		foreach( (array)$recipient_ids as $i => $recipient_id ) {
			$message->recipients[$i] = new stdClass;
			$message->recipients[$i]->user_id = $recipient_id;
		}
	}

	if ( $message->send() ) {
		require_once( BP_PLUGIN_DIR . '/bp-messages/bp-messages-notifications.php' );

		// Send screen notifications to the recipients
		foreach ( (array)$message->recipients as $recipient )
			bp_core_add_notification( $message->id, $recipient->user_id, 'messages', 'new_message' );

		// Send email notifications to the recipients
		messages_notification_new_message( array( 'message_id' => $message->id, 'sender_id' => $message->sender_id, 'subject' => $message->subject, 'content' => $message->message, 'recipients' => $message->recipients, 'thread_id' => $message->thread_id) );

		do_action( 'messages_message_sent', &$message );

		return $message->thread_id;
	}

	return false;
}
开发者ID:n-sane,项目名称:zaroka,代码行数:89,代码来源:bp-messages.php

示例3: test_get_recipients_cache_should_be_busted_when_thread_is_unread

 /**
  * @group get_recipients
  * @group cache
  */
 public function test_get_recipients_cache_should_be_busted_when_thread_is_unread()
 {
     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);
     // Mark thread as unread
     $current_user = get_current_user_id();
     $this->set_current_user($u2);
     messages_mark_thread_unread($t1);
     // Cache should be empty.
     $this->assertFalse(wp_cache_get('thread_recipients_' . $t1, 'bp_messages'));
     $this->set_current_user($current_user);
 }
开发者ID:AceMedia,项目名称:BuddyPress,代码行数:24,代码来源:class.bp-messages-thread.php

示例4: messages_send_message

function messages_send_message($recipients, $subject, $content, $thread_id, $from_ajax = false, $from_template = false, $is_reply = false)
{
    global $pmessage;
    global $message, $type;
    global $bp, $current_user;
    if (!check_admin_referer('messages_send_message')) {
        return false;
    }
    messages_add_callback_values($recipients, $subject, $content);
    if (isset($_POST['send-notice'])) {
        if (messages_send_notice($subject, $content, $from_template)) {
            bp_core_add_message(__('Notice posted successfully.', 'buddypress'));
        } else {
            bp_core_add_message(__('There was an error posting that notice.', 'buddypress'), 'error');
        }
        bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/notices');
        return true;
    }
    $recipients = explode(' ', $recipients);
    // If there are no recipients
    if (count($recipients) < 1) {
        if (!$from_ajax) {
            bp_core_add_message(__('Please enter at least one valid user to send this message to.', 'buddypress'), 'error');
            bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/compose');
        } else {
            return array('status' => 0, 'message' => __('There was an error sending the reply, please try again.', 'buddypress'));
        }
        // If there is only 1 recipient and it is the logged in user.
    } else {
        if (1 == count($recipients) && $recipients[0] == $current_user->user_login) {
            bp_core_add_message(__('You must send your message to one or more users not including yourself.', 'buddypress'), 'error');
            bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/compose');
            // If the subject or content boxes are empty.
        } else {
            if (empty($subject) || empty($content)) {
                if (!$from_ajax) {
                    bp_core_add_message(__('Please make sure you fill in all the fields.', 'buddypress'), 'error');
                    bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/compose');
                } else {
                    return array('status' => 0, 'message' => __('Please make sure you have typed a message before sending a reply.', 'buddypress'));
                }
                // Passed validation continue.
            } else {
                // Strip the logged in user from the recipient list if they exist
                if ($key = array_search($current_user->user_login, $recipients)) {
                    unset($recipients[$key]);
                }
                $pmessage = new BP_Messages_Message();
                $pmessage->sender_id = $bp->loggedin_user->id;
                $pmessage->subject = $subject;
                $pmessage->message = $content;
                $pmessage->thread_id = $thread_id;
                $pmessage->date_sent = time();
                $pmessage->message_order = 0;
                // TODO
                $pmessage->sender_is_group = 0;
                if ($is_reply) {
                    $thread = new BP_Messages_Thread($thread_id);
                    $pmessage->recipients = $thread->get_recipients();
                } else {
                    $pmessage->recipients = BP_Messages_Message::get_recipient_ids($recipients);
                }
                if (!is_null($pmessage->recipients)) {
                    if (!$pmessage->send()) {
                        $message = __('Message could not be sent, please try again.', 'buddypress');
                        $type = 'error';
                        if ($from_ajax) {
                            return array('status' => 0, 'message' => $message);
                        } else {
                            bp_core_add_message($message, $type);
                            bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/compose');
                        }
                    } else {
                        $message = __('Message sent successfully!', 'buddypress') . ' <a href="' . $bp->loggedin_user->domain . $bp->messages->slug . '/view/' . $pmessage->thread_id . '">' . __('View Message', 'buddypress') . '</a> &raquo;';
                        $type = 'success';
                        // Send screen notifications to the recipients
                        for ($i = 0; $i < count($pmessage->recipients); $i++) {
                            if ($pmessage->recipients[$i] != $bp->loggedin_user->id) {
                                bp_core_add_notification($pmessage->id, $pmessage->recipients[$i], 'messages', 'new_message');
                            }
                        }
                        // Send email notifications to the recipients
                        require_once BP_PLUGIN_DIR . '/bp-messages/bp-messages-notifications.php';
                        messages_notification_new_message(array('item_id' => $pmessage->id, 'recipient_ids' => $pmessage->recipients, 'thread_id' => $pmessage->thread_id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1));
                        do_action('messages_send_message', array('item_id' => $pmessage->id, 'recipient_ids' => $pmessage->recipients, 'thread_id' => $pmessage->thread_id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1));
                        if ($from_ajax) {
                            return array('status' => 1, 'message' => $message, 'reply' => $pmessage);
                        } else {
                            bp_core_add_message($message);
                            bp_core_redirect($bp->loggedin_user->domain . $bp->current_component . '/inbox');
                        }
                    }
                } else {
                    $message = __('Message could not be sent, please try again.', 'buddypress');
                    $type = 'error';
                    if ($from_ajax) {
                        return array('status' => 0, 'message' => $message);
                    } else {
                        bp_core_add_message($message, $type);
                        bp_core_redirect($bp->loggedin_user->domain . $bp->messages->slug . '/compose');
//.........这里部分代码省略.........
开发者ID:alvaropereyra,项目名称:shrekcms,代码行数:101,代码来源:bp-messages.php

示例5: messages_new_message

function messages_new_message($args = '')
{
    $defaults = array('sender_id' => bp_loggedin_user_id(), 'thread_id' => false, 'recipients' => false, 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time());
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if (empty($sender_id) || empty($content)) {
        return false;
    }
    // Create a new message object
    $message = new BP_Messages_Message();
    $message->thread_id = $thread_id;
    $message->sender_id = $sender_id;
    $message->subject = $subject;
    $message->message = $content;
    $message->date_sent = $date_sent;
    // If we have a thread ID, use the existing recipients, otherwise use the recipients passed
    if (!empty($thread_id)) {
        $thread = new BP_Messages_Thread($thread_id);
        $message->recipients = $thread->get_recipients();
        // Strip the sender from the recipient list if they exist
        if (isset($message->recipients[$sender_id])) {
            unset($message->recipients[$sender_id]);
        }
        if (empty($message->subject)) {
            $message->subject = sprintf(__('Re: %s', 'buddypress'), $thread->messages[0]->subject);
        }
        // No thread ID, so make some adjustments
    } else {
        if (empty($recipients)) {
            return false;
        }
        if (empty($message->subject)) {
            $message->subject = __('No Subject', 'buddypress');
        }
        $recipient_ids = array();
        // Invalid recipients are added to an array, for future enhancements
        $invalid_recipients = array();
        // Loop the recipients and convert all usernames to user_ids where needed
        foreach ((array) $recipients as $recipient) {
            $recipient = trim($recipient);
            if (empty($recipient)) {
                continue;
            }
            $recipient_id = false;
            // input was numeric
            if (is_numeric($recipient)) {
                // do a check against the user ID column first
                if (bp_core_get_core_userdata((int) $recipient)) {
                    $recipient_id = (int) $recipient;
                } else {
                    if (bp_is_username_compatibility_mode()) {
                        $recipient_id = bp_core_get_userid((int) $recipient);
                    } else {
                        $recipient_id = bp_core_get_userid_from_nicename((int) $recipient);
                    }
                }
            } else {
                if (bp_is_username_compatibility_mode()) {
                    $recipient_id = bp_core_get_userid($recipient);
                } else {
                    $recipient_id = bp_core_get_userid_from_nicename($recipient);
                }
            }
            if (!$recipient_id) {
                $invalid_recipients[] = $recipient;
            } else {
                $recipient_ids[] = (int) $recipient_id;
            }
        }
        // Strip the sender from the recipient list if they exist
        if ($key = array_search($sender_id, (array) $recipient_ids)) {
            unset($recipient_ids[$key]);
        }
        // Remove duplicates
        $recipient_ids = array_unique((array) $recipient_ids);
        if (empty($recipient_ids)) {
            return false;
        }
        // Format this to match existing recipients
        foreach ((array) $recipient_ids as $i => $recipient_id) {
            $message->recipients[$i] = new stdClass();
            $message->recipients[$i]->user_id = $recipient_id;
        }
    }
    if ($message->send()) {
        // Send screen notifications to the recipients
        foreach ((array) $message->recipients as $recipient) {
            bp_core_add_notification($message->id, $recipient->user_id, 'messages', 'new_message');
        }
        // Send email notifications to the recipients
        messages_notification_new_message(array('message_id' => $message->id, 'sender_id' => $message->sender_id, 'subject' => $message->subject, 'content' => $message->message, 'recipients' => $message->recipients, 'thread_id' => $message->thread_id));
        do_action_ref_array('messages_message_sent', array(&$message));
        return $message->thread_id;
    }
    return false;
}
开发者ID:pyropictures,项目名称:wordpress-plugins,代码行数:96,代码来源:bp-messages-functions.php

示例6: messages_new_message

/**
 * Create a new message.
 *
 * @since 2.4.0 Added 'error_type' as an additional $args parameter.
 *
 * @param array|string $args {
 *     Array of arguments.
 *     @type int    $sender_id  Optional. ID of the user who is sending the
 *                              message. Default: ID of the logged-in user.
 *     @type int    $thread_id  Optional. ID of the parent thread. Leave blank to
 *                              create a new thread for the message.
 *     @type array  $recipients IDs or usernames of message recipients. If this
 *                              is an existing thread, it is unnecessary to pass a $recipients
 *                              argument - existing thread recipients will be assumed.
 *     @type string $subject    Optional. Subject line for the message. For
 *                              existing threads, the existing subject will be used. For new
 *                              threads, 'No Subject' will be used if no $subject is provided.
 *     @type string $content    Content of the message. Cannot be empty.
 *     @type string $date_sent  Date sent, in 'Y-m-d H:i:s' format. Default: current date/time.
 *     @type string $error_type Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'.
 * }
 * @return int|bool ID of the message thread on success, false on failure.
 */
function messages_new_message($args = '')
{
    // Parse the default arguments.
    $r = bp_parse_args($args, array('sender_id' => bp_loggedin_user_id(), 'thread_id' => false, 'recipients' => array(), 'subject' => false, 'content' => false, 'date_sent' => bp_core_current_time(), 'error_type' => 'bool'), 'messages_new_message');
    // Bail if no sender or no content.
    if (empty($r['sender_id']) || empty($r['content'])) {
        if ('wp_error' === $r['error_type']) {
            if (empty($r['sender_id'])) {
                $error_code = 'messages_empty_sender';
                $feedback = __('Your message was not sent. Please use a valid sender.', 'buddypress');
            } else {
                $error_code = 'messages_empty_content';
                $feedback = __('Your message was not sent. Please enter some content.', 'buddypress');
            }
            return new WP_Error($error_code, $feedback);
        } else {
            return false;
        }
    }
    // Create a new message object.
    $message = new BP_Messages_Message();
    $message->thread_id = $r['thread_id'];
    $message->sender_id = $r['sender_id'];
    $message->subject = $r['subject'];
    $message->message = $r['content'];
    $message->date_sent = $r['date_sent'];
    // If we have a thread ID...
    if (!empty($r['thread_id'])) {
        // ...use the existing recipients
        $thread = new BP_Messages_Thread($r['thread_id']);
        $message->recipients = $thread->get_recipients();
        // Strip the sender from the recipient list, and unset them if they are
        // not alone. If they are alone, let them talk to themselves.
        if (isset($message->recipients[$r['sender_id']]) && count($message->recipients) > 1) {
            unset($message->recipients[$r['sender_id']]);
        }
        // Set a default reply subject if none was sent.
        if (empty($message->subject)) {
            $message->subject = sprintf(__('Re: %s', 'buddypress'), $thread->messages[0]->subject);
        }
        // ...otherwise use the recipients passed
    } else {
        // Bail if no recipients.
        if (empty($r['recipients'])) {
            if ('wp_error' === $r['error_type']) {
                return new WP_Error('message_empty_recipients', __('Message could not be sent. Please enter a recipient.', 'buddypress'));
            } else {
                return false;
            }
        }
        // Set a default subject if none exists.
        if (empty($message->subject)) {
            $message->subject = __('No Subject', 'buddypress');
        }
        // Setup the recipients array.
        $recipient_ids = array();
        // Invalid recipients are added to an array, for future enhancements.
        $invalid_recipients = array();
        // Loop the recipients and convert all usernames to user_ids where needed.
        foreach ((array) $r['recipients'] as $recipient) {
            // Trim spaces and skip if empty.
            $recipient = trim($recipient);
            if (empty($recipient)) {
                continue;
            }
            // Check user_login / nicename columns first
            // @see http://buddypress.trac.wordpress.org/ticket/5151.
            if (bp_is_username_compatibility_mode()) {
                $recipient_id = bp_core_get_userid(urldecode($recipient));
            } else {
                $recipient_id = bp_core_get_userid_from_nicename($recipient);
            }
            // Check against user ID column if no match and if passed recipient is numeric.
            if (empty($recipient_id) && is_numeric($recipient)) {
                if (bp_core_get_core_userdata((int) $recipient)) {
                    $recipient_id = (int) $recipient;
                }
//.........这里部分代码省略.........
开发者ID:CompositeUK,项目名称:clone.BuddyPress,代码行数:101,代码来源:bp-messages-functions.php

示例7: messages_new_message

/**
 * Create a new message.
 *
 * @param array $args {
 *     Array of arguments.
 *     @type int $sender_id Optional. ID of the user who is sending the
 *           message. Default: ID of the logged-in user.
 *     @type int $thread_id Optional. ID of the parent thread. Leave blank to
 *           create a new thread for the message.
 *     @type array $recipients IDs or usernames of message recipients. If this
 *           is an existing thread, it is unnecessary to pass a $recipients
 *           argument - existing thread recipients will be assumed.
 *     @type string $subject Optional. Subject line for the message. For
 *           existing threads, the existing subject will be used. For new
 *           threads, 'No Subject' will be used if no $subject is provided.
 *     @type string $content Content of the message. Cannot be empty.
 *     @type string $date_sent Date sent, in 'Y-m-d H:i:s' format. Default:
 *           current date/time.
 * }
 * @return int|bool ID of the message thread on success, false on failure.
 */
function messages_new_message( $args = '' ) {

	// Parse the default arguments
	$r = bp_parse_args( $args, array(
		'sender_id'  => bp_loggedin_user_id(),
		'thread_id'  => false,   // false for a new message, thread id for a reply to a thread.
		'recipients' => array(), // Can be an array of usernames, user_ids or mixed.
		'subject'    => false,
		'content'    => false,
		'date_sent'  => bp_core_current_time()
	), 'messages_new_message' );

	// Bail if no sender or no content
	if ( empty( $r['sender_id'] ) || empty( $r['content'] ) ) {
		return false;
	}

	// Create a new message object
	$message            = new BP_Messages_Message;
	$message->thread_id = $r['thread_id'];
	$message->sender_id = $r['sender_id'];
	$message->subject   = $r['subject'];
	$message->message   = $r['content'];
	$message->date_sent = $r['date_sent'];

	// If we have a thread ID...
	if ( ! empty( $r['thread_id'] ) ) {

		// ...use the existing recipients
		$thread              = new BP_Messages_Thread( $r['thread_id'] );
		$message->recipients = $thread->get_recipients();

		// Strip the sender from the recipient list, and unset them if they are
		// not alone. If they are alone, let them talk to themselves.
		if ( isset( $message->recipients[ $r['sender_id'] ] ) && ( count( $message->recipients ) > 1 ) ) {
			unset( $message->recipients[ $r['sender_id'] ] );
		}

		// Set a default reply subject if none was sent
		if ( empty( $message->subject ) ) {
			$message->subject = sprintf( __( 'Re: %s', 'buddypress' ), $thread->messages[0]->subject );
		}

	// ...otherwise use the recipients passed
	} else {

		// Bail if no recipients
		if ( empty( $r['recipients'] ) ) {
			return false;
		}

		// Set a default subject if none exists
		if ( empty( $message->subject ) ) {
			$message->subject = __( 'No Subject', 'buddypress' );
		}

		// Setup the recipients array
		$recipient_ids 	    = array();

		// Invalid recipients are added to an array, for future enhancements
		$invalid_recipients = array();

		// Loop the recipients and convert all usernames to user_ids where needed
		foreach( (array) $r['recipients'] as $recipient ) {

			// Trim spaces and skip if empty
			$recipient = trim( $recipient );
			if ( empty( $recipient ) ) {
				continue;
			}

			// Check user_login / nicename columns first
			// @see http://buddypress.trac.wordpress.org/ticket/5151
			if ( bp_is_username_compatibility_mode() ) {
				$recipient_id = bp_core_get_userid( urldecode( $recipient ) );
			} else {
				$recipient_id = bp_core_get_userid_from_nicename( $recipient );
			}

//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:101,代码来源:bp-messages-functions.php


注:本文中的BP_Messages_Thread::get_recipients方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。