Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/12/2016 11:30:39 PM (10 years ago)
Author:
r-a-y
Message:

Messages: Return generic WP Error in messages_new_message() when necessary.

In #6535, we added an 'error_type' parameter in messages_new_message()
that supports returning a WP Error object if error type is set to
'wp_error'. However, we did not return a WP error further down in the
messages_new_message() function, which can result in a potential fatal
error to occur.

This commit rectifies this and includes a unit test.

Anti-props r-a-y.

Fixes #6894 (2.4-branch).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.4/tests/phpunit/testcases/messages/functions.php

    r10286 r10586  
    5959        $this->assertSame( 'Message could not be sent because you have entered an invalid username. Please try again.', $t1->get_error_message() );
    6060    }
     61
     62    /**
     63     * @group messages_new_message
     64     */
     65    public function test_messages_new_message_wp_error_generic() {
     66        $u1 = $this->factory->user->create();
     67        $u2 = $this->factory->user->create();
     68
     69        // Emulate a plugin disabling messages.
     70        add_action( 'messages_message_before_save', array( $this, 'remove_recipients_before_save' ) );
     71
     72        // send a private message
     73        $t1 = messages_new_message( array(
     74            'sender_id'  => $u1,
     75            'recipients' => array( $u2 ),
     76            'subject'    => 'A new message',
     77            'content'    => 'Hey there!',
     78            'error_type' => 'wp_error'
     79        ) );
     80
     81        $this->assertNotEmpty( $t1->get_error_code() );
     82
     83        remove_action( 'messages_message_before_save', array( $this, 'remove_recipients_before_save' ) );
     84    }
     85
     86    /**
     87     * Helper method for test_messages_new_message_wp_error_generic().
     88     */
     89    public function remove_recipients_before_save( $message ) {
     90        $message->recipients = array();
     91    }
    6192}
Note: See TracChangeset for help on using the changeset viewer.