Media: Add a $wp_error parameter to wp_insert_attachment() to give it parity with wp_insert_post().

Fixes #37813
Props grapplerulrich, mrahmadawais


git-svn-id: https://develop.svn.wordpress.org/trunk@38408 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2016-08-27 17:24:58 +00:00
parent f59a3b54c8
commit 551fa31b5a
2 changed files with 28 additions and 7 deletions

View File

@@ -1796,6 +1796,25 @@ EOF;
);
return $data;
}
/**
* @ticket 37813
*/
public function test_return_type_when_inserting_attachment_with_error_in_data() {
$data = array(
'post_status' => 'public',
'post_content' => 'Attachment content',
'post_title' => 'Attachment Title',
'post_date' => '2012-02-30 00:00:00',
);
$attachment_id = wp_insert_attachment( $data, '', 0, true );
$this->assertWPError( $attachment_id );
$this->assertEquals( 'invalid_date', $attachment_id->get_error_code() );
$attachment_id = wp_insert_attachment( $data, '', 0 );
$this->assertSame( 0, $attachment_id );
}
}
/**