Changeset 38408
- Timestamp:
- 08/27/2016 05:24:58 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r38326 r38408 2867 2867 * @type array $meta_input Array of post meta values keyed by their post meta key. Default empty. 2868 2868 * } 2869 * @param bool $wp_error Optional. Whether to allow return ofWP_Error on failure. Default false.2869 * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. 2870 2870 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. 2871 2871 */ … … 4695 4695 * 4696 4696 * @since 2.0.0 4697 * @since 4.7.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure. 4697 4698 * 4698 4699 * @see wp_insert_post() 4699 4700 * 4700 * @param string|array $args Arguments for inserting an attachment. 4701 * @param string $file Optional. Filename. 4702 * @param int $parent Optional. Parent post ID. 4703 * @return int Attachment ID. 4704 */ 4705 function wp_insert_attachment( $args, $file = false, $parent = 0 ) { 4701 * @param string|array $args Arguments for inserting an attachment. 4702 * @param string $file Optional. Filename. 4703 * @param int $parent Optional. Parent post ID. 4704 * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. 4705 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. 4706 */ 4707 function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false ) { 4706 4708 $defaults = array( 4707 4709 'file' => $file, … … 4717 4719 $data['post_type'] = 'attachment'; 4718 4720 4719 return wp_insert_post( $data );4721 return wp_insert_post( $data, $wp_error ); 4720 4722 } 4721 4723 -
trunk/tests/phpunit/tests/media.php
r38398 r38408 1797 1797 return $data; 1798 1798 } 1799 1800 /** 1801 * @ticket 37813 1802 */ 1803 public function test_return_type_when_inserting_attachment_with_error_in_data() { 1804 $data = array( 1805 'post_status' => 'public', 1806 'post_content' => 'Attachment content', 1807 'post_title' => 'Attachment Title', 1808 'post_date' => '2012-02-30 00:00:00', 1809 ); 1810 1811 $attachment_id = wp_insert_attachment( $data, '', 0, true ); 1812 $this->assertWPError( $attachment_id ); 1813 $this->assertEquals( 'invalid_date', $attachment_id->get_error_code() ); 1814 1815 $attachment_id = wp_insert_attachment( $data, '', 0 ); 1816 $this->assertSame( 0, $attachment_id ); 1817 } 1799 1818 } 1800 1819
Note: See TracChangeset
for help on using the changeset viewer.