mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-05 13:14:29 +00:00
Comments: Allow wp_update_comment() to return WP_Error().
The `wp_update_comment_data` filter introduced in 4.7 allows comment data to be filtered before it is updated in the database. The patch aims to handle `WP_Error` as the filter above return value in a similar manner as is done for `wp_new_comment()`. Fixes #39732. Props: enricosorcinelli, swissspidy, gkloveweb, jnylen0, jbpaul17, afercia, SergeyBiryukov, audrasjb, imath, davidbaumwald. git-svn-id: https://develop.svn.wordpress.org/trunk@48154 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -142,6 +142,31 @@ class Tests_Comment extends WP_UnitTestCase {
|
||||
$this->assertEquals( $updated_comment_text, $comment->comment_content );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39732
|
||||
*/
|
||||
public function test_wp_update_comment_is_wp_error() {
|
||||
$comment_id = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) );
|
||||
|
||||
add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 );
|
||||
$result = wp_update_comment(
|
||||
array(
|
||||
'comment_ID' => $comment_id,
|
||||
'comment_type' => 'pingback',
|
||||
),
|
||||
true
|
||||
);
|
||||
$this->assertWPError( $result );
|
||||
remove_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Block comments from being updated by returning WP_Error
|
||||
*/
|
||||
public function _wp_update_comment_data_filter( $data, $comment, $commentarr ) {
|
||||
return new WP_Error( 'comment_wrong', __( 'wp_update_comment_data filter fails for this comment.' ), 500 );
|
||||
}
|
||||
|
||||
public function test_get_approved_comments() {
|
||||
$ca1 = self::factory()->comment->create(
|
||||
array(
|
||||
|
||||
Reference in New Issue
Block a user