Skip to:
Content

BuddyPress.org

Ticket #8578: 8578.patch

File 8578.patch, 3.3 KB (added by amitgrhr, 3 years ago)

patch for #8578

  • src/bp-messages/actions/compose.php

    diff --git src/bp-messages/actions/compose.php src/bp-messages/actions/compose.php
    index 01701d1fc..0c39ed2af 100644
    function bp_messages_action_create_message() {  
    2929        $feedback    = '';
    3030        $success     = false;
    3131
    32         // Missing subject or content.
    33         if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) {
    34                 $success  = false;
     32        // Setup the link to the logged-in user's messages.
     33        $path_chunks = array( bp_get_messages_slug() );
     34
     35        // Missing usernames or friend's name
     36        if ( empty( $_POST['send_to_usernames'] ) ) {
     37                $success = false;
     38
     39                $path_chunks[] = 'compose';
     40
     41                $feedback = __( 'Your message was not sent. Please enter a username or Friend\'s name.', 'buddypress' );
     42
     43                $redirect_to = bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) );
     44
     45                // Missing subject or content.
     46        } elseif ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) {
     47                $success = false;
     48
     49                $path_chunks[] = 'compose';
    3550
    3651                if ( empty( $_POST['subject'] ) ) {
    3752                        $feedback = __( 'Your message was not sent. Please enter a subject line.', 'buddypress' );
    function bp_messages_action_create_message() {  
    3954                        $feedback = __( 'Your message was not sent. Please enter some content.', 'buddypress' );
    4055                }
    4156
    42         // Subject and content present.
    43         } else {
     57                $redirect_to = add_query_arg(
     58                        array(
     59                                'r'        => $_POST['send_to_usernames'],
     60                                '_wpnonce' => wp_create_nonce( 'action' ),
     61                        ),
     62                        bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) )
     63                );
    4464
    45                 // Setup the link to the logged-in user's messages.
    46                 $path_chunks = array( bp_get_messages_slug() );
     65                // Subject and content present.
     66        } else {
    4767
    4868                // Site-wide notice.
    4969                if ( isset( $_POST['send-notice'] ) ) {
    function bp_messages_action_create_message() {  
    5575                                $path_chunks[] = 'notices';
    5676                                $redirect_to   = bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) );
    5777
    58                         // Notice could not be sent.
     78                                // Notice could not be sent.
    5979                        } else {
    6080                                $success  = false;
    6181                                $feedback = __( 'Notice was not created. Please try again.', 'buddypress' );
    6282                        }
    6383
    64                 // Private conversation.
     84                        // Private conversation.
    6585                } else {
    6686
    6787                        // Filter recipients into the format we need - array( 'username/userid', 'username/userid' ).
    function bp_messages_action_create_message() {  
    7999                        $recipients = apply_filters( 'bp_messages_recipients', $recipients );
    80100
    81101                        // Attempt to send the message.
    82                         $send = messages_new_message( array(
    83                                 'recipients' => $recipients,
    84                                 'subject'    => $_POST['subject'],
    85                                 'content'    => $_POST['content'],
    86                                 'error_type' => 'wp_error',
    87                         ) );
     102                        $send = messages_new_message(
     103                                array(
     104                                        'recipients' => $recipients,
     105                                        'subject'    => $_POST['subject'],
     106                                        'content'    => $_POST['content'],
     107                                        'error_type' => 'wp_error',
     108                                )
     109                        );
    88110
    89111                        // Send the message and redirect to it.
    90112                        if ( true === is_int( $send ) ) {
    function bp_messages_action_create_message() {  
    94116                                $path_chunks[] = array( $send );
    95117                                $redirect_to   = bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) );
    96118
    97                         // Message could not be sent.
     119                                // Message could not be sent.
    98120                        } else {
    99121                                $success  = false;
    100122                                $feedback = $send->get_error_message();