Ticket #6535: 6535.01.patch
File 6535.01.patch, 3.8 KB (added by , 10 years ago) |
---|
-
src/bp-messages/bp-messages-actions.php
85 85 $recipients = apply_filters( 'bp_messages_recipients', $recipients ); 86 86 87 87 // Attempt to send the message 88 $ thread_id= messages_new_message( array(88 $send = messages_new_message( array( 89 89 'recipients' => $recipients, 90 90 'subject' => $_POST['subject'], 91 'content' => $_POST['content'] 91 'content' => $_POST['content'], 92 'error_type' => 'wp_error' 92 93 ) ); 93 94 94 95 // Send the message and redirect to it 95 if ( ! empty( $thread_id ) ) {96 if ( true === is_int( $send ) ) { 96 97 $success = true; 97 98 $feedback = __( 'Message successfully sent.', 'buddypress' ); 98 99 $view = trailingslashit( $member_messages . 'view' ); 99 $redirect_to = trailingslashit( $view . $ thread_id );100 $redirect_to = trailingslashit( $view . $send ); 100 101 101 102 // Message could not be sent 102 103 } else { 103 104 $success = false; 104 $feedback = __( 'Message was not sent. Please try again.', 'buddypress');105 $feedback = $send->get_error_message(); 105 106 } 106 107 } 107 108 } -
src/bp-messages/bp-messages-functions.php
32 32 * threads, 'No Subject' will be used if no $subject is provided. 33 33 * @type string $content Content of the message. Cannot be empty. 34 34 * @type string $date_sent Date sent, in 'Y-m-d H:i:s' format. Default: current date/time. 35 * @type string $error_type Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'. 35 36 * } 36 37 * @return int|bool ID of the message thread on success, false on failure. 37 38 */ … … 44 45 'recipients' => array(), // Can be an array of usernames, user_ids or mixed. 45 46 'subject' => false, 46 47 'content' => false, 47 'date_sent' => bp_core_current_time() 48 'date_sent' => bp_core_current_time(), 49 'error_type' => 'bool' 48 50 ), 'messages_new_message' ); 49 51 50 52 // Bail if no sender or no content 51 53 if ( empty( $r['sender_id'] ) || empty( $r['content'] ) ) { 52 return false; 54 if ( 'wp_error' === $r['error_type'] ) { 55 if ( empty( $r['sender_id'] ) ) { 56 $error_code = 'messages_empty_sender'; 57 $feedback = __( 'Your message was not sent. Please use a valid sender.', 'buddypress' ); 58 } else { 59 $error_code = 'messages_empty_content'; 60 $feedback = __( 'Your message was not sent. Please enter some content.', 'buddypress' ); 61 } 62 63 return new WP_Error( $error_code, $feedback ); 64 65 } else { 66 return false; 67 } 53 68 } 54 69 55 70 // Create a new message object … … 83 98 84 99 // Bail if no recipients 85 100 if ( empty( $r['recipients'] ) ) { 86 return false; 101 if ( 'wp_error' === $r['error_type'] ) { 102 return new WP_Error( 'message_empty_recipients', __( 'Message could not be sent. Please enter a recipient.', 'buddypress' ) ); 103 } else { 104 return false; 105 } 87 106 } 88 107 89 108 // Set a default subject if none exists … … 139 158 // Remove duplicates & bail if no recipients 140 159 $recipient_ids = array_unique( $recipient_ids ); 141 160 if ( empty( $recipient_ids ) ) { 142 return false; 161 if ( 'wp_error' === $r['error_type'] ) { 162 return new WP_Error( 'message_invalid_recipients', __( 'Message could not be sent because you have entered an invalid username. Please try again.', 'buddypress' ) ); 163 } else { 164 return false; 165 } 143 166 } 144 167 145 168 // Format this to match existing recipients … … 150 173 } 151 174 152 175 // Bail if message failed to send 176 // @todo Should we use WP_Error higher up the stack in BP_Messages_Message::save()? 153 177 if ( ! $message->send() ) { 154 178 return false; 155 179 }