Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/19/2015 07:47:01 PM (11 years ago)
Author:
r-a-y
Message:

Messages: Return context-appropriate error messages for messages_new_message().

This commit introduces the error_type parameter in the
messages_new_message() function, which allows for us to return
descriptive error messages to the user when 'error_type' is set to
'wp_error'.

This most notably addresses an issue when entering an invalid username
when composing a new private message.

Commit also includes a unit test.

Fixes #6535.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-actions.php

    r10139 r10286  
    8585
    8686                        // Attempt to send the message
    87                         $thread_id = messages_new_message( array(
     87                        $send = messages_new_message( array(
    8888                                'recipients' => $recipients,
    8989                                'subject'    => $_POST['subject'],
    90                                 'content'    => $_POST['content']
     90                                'content'    => $_POST['content'],
     91                                'error_type' => 'wp_error'
    9192                        ) );
    9293
    9394                        // Send the message and redirect to it
    94                         if ( ! empty( $thread_id ) ) {
     95                        if ( true === is_int( $send ) ) {
    9596                                $success     = true;
    9697                                $feedback    = __( 'Message successfully sent.', 'buddypress' );
    9798                                $view        = trailingslashit( $member_messages . 'view' );
    98                                 $redirect_to = trailingslashit( $view . $thread_id );
     99                                $redirect_to = trailingslashit( $view . $send );
    99100
    100101                        // Message could not be sent
    101102                        } else {
    102103                                $success  = false;
    103                                 $feedback = __( 'Message was not sent. Please try again.', 'buddypress' );
     104                                $feedback = $send->get_error_message();
    104105                        }
    105106                }
Note: See TracChangeset for help on using the changeset viewer.