Changeset 10286
- Timestamp:
- 10/19/2015 07:47:01 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/bp-messages-actions.php
r10139 r10286 85 85 86 86 // Attempt to send the message 87 $ thread_id= messages_new_message( array(87 $send = messages_new_message( array( 88 88 'recipients' => $recipients, 89 89 'subject' => $_POST['subject'], 90 'content' => $_POST['content'] 90 'content' => $_POST['content'], 91 'error_type' => 'wp_error' 91 92 ) ); 92 93 93 94 // Send the message and redirect to it 94 if ( ! empty( $thread_id ) ) {95 if ( true === is_int( $send ) ) { 95 96 $success = true; 96 97 $feedback = __( 'Message successfully sent.', 'buddypress' ); 97 98 $view = trailingslashit( $member_messages . 'view' ); 98 $redirect_to = trailingslashit( $view . $ thread_id );99 $redirect_to = trailingslashit( $view . $send ); 99 100 100 101 // Message could not be sent 101 102 } else { 102 103 $success = false; 103 $feedback = __( 'Message was not sent. Please try again.', 'buddypress');104 $feedback = $send->get_error_message(); 104 105 } 105 106 } -
trunk/src/bp-messages/bp-messages-functions.php
r10139 r10286 17 17 /** 18 18 * Create a new message. 19 * 20 * @since 2.4.0 Added 'error_type' as an additional $args parameter. 19 21 * 20 22 * @param array|string $args { … … 32 34 * @type string $content Content of the message. Cannot be empty. 33 35 * @type string $date_sent Date sent, in 'Y-m-d H:i:s' format. Default: current date/time. 36 * @type string $error_type Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'. 34 37 * } 35 38 * @return int|bool ID of the message thread on success, false on failure. … … 44 47 'subject' => false, 45 48 'content' => false, 46 'date_sent' => bp_core_current_time() 49 'date_sent' => bp_core_current_time(), 50 'error_type' => 'bool' 47 51 ), 'messages_new_message' ); 48 52 49 53 // Bail if no sender or no content 50 54 if ( empty( $r['sender_id'] ) || empty( $r['content'] ) ) { 51 return false; 55 if ( 'wp_error' === $r['error_type'] ) { 56 if ( empty( $r['sender_id'] ) ) { 57 $error_code = 'messages_empty_sender'; 58 $feedback = __( 'Your message was not sent. Please use a valid sender.', 'buddypress' ); 59 } else { 60 $error_code = 'messages_empty_content'; 61 $feedback = __( 'Your message was not sent. Please enter some content.', 'buddypress' ); 62 } 63 64 return new WP_Error( $error_code, $feedback ); 65 66 } else { 67 return false; 68 } 52 69 } 53 70 … … 83 100 // Bail if no recipients 84 101 if ( empty( $r['recipients'] ) ) { 85 return false; 102 if ( 'wp_error' === $r['error_type'] ) { 103 return new WP_Error( 'message_empty_recipients', __( 'Message could not be sent. Please enter a recipient.', 'buddypress' ) ); 104 } else { 105 return false; 106 } 86 107 } 87 108 … … 139 160 $recipient_ids = array_unique( $recipient_ids ); 140 161 if ( empty( $recipient_ids ) ) { 141 return false; 162 if ( 'wp_error' === $r['error_type'] ) { 163 return new WP_Error( 'message_invalid_recipients', __( 'Message could not be sent because you have entered an invalid username. Please try again.', 'buddypress' ) ); 164 } else { 165 return false; 166 } 142 167 } 143 168 -
trunk/tests/phpunit/testcases/messages/functions.php
r9819 r10286 42 42 } 43 43 44 /** 45 * @group messages_new_message 46 */ 47 public function test_messages_new_message_invalid_recipient_error_message() { 48 $u1 = $this->factory->user->create(); 49 50 // attempt to send a private message to an invalid username 51 $t1 = messages_new_message( array( 52 'sender_id' => $u1, 53 'recipients' => array( 'homerglumpkin' ), 54 'subject' => 'A new message', 55 'content' => 'Hey there!', 56 'error_type' => 'wp_error' 57 ) ); 58 59 $this->assertSame( 'Message could not be sent because you have entered an invalid username. Please try again.', $t1->get_error_message() ); 60 } 44 61 }
Note: See TracChangeset
for help on using the changeset viewer.