Make WordPress Core

Changeset 29745


Ignore:
Timestamp:
09/15/2014 02:23:31 PM (10 years ago)
Author:
SergeyBiryukov
Message:

Make sure the $parent argument of wp_insert_attachment() still works as expected after [28579].

prop jesin, dikiy_forester.
fixes #29646 for trunk.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r29468 r29745  
    47204720    $defaults = array(
    47214721        'file'        => $file,
    4722         'post_parent' => $parent
     4722        'post_parent' => 0
    47234723    );
     4724
    47244725    $data = wp_parse_args( $args, $defaults );
     4726
     4727    if ( ! empty( $parent ) ) {
     4728        $data['post_parent'] = $parent;
     4729    }
    47254730
    47264731    $data['post_type'] = 'attachment';
  • trunk/tests/phpunit/tests/post/attachments.php

    r29120 r29745  
    255255    }
    256256
     257    /**
     258     * @ticket 29646
     259     */
     260    function test_update_orphan_attachment_parent() {
     261        $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
     262        $contents = file_get_contents( $filename );
     263
     264        $upload = wp_upload_bits( basename( $filename ), null, $contents );
     265        $this->assertTrue( empty( $upload['error'] ) );
     266
     267        $attachment_id = $this->_make_attachment( $upload );
     268
     269        // Assert that the attachment is an orphan
     270        $attachment = get_post( $attachment_id );
     271        $this->assertEquals( $attachment->post_parent, 0 );
     272
     273        $post_id = wp_insert_post( array( 'post_content' => rand_str(), 'post_title' => rand_str() ) );
     274
     275        // Assert that the attachment has a parent
     276        wp_insert_attachment( $attachment, '', $post_id );
     277        $attachment = get_post( $attachment_id );
     278        $this->assertEquals( $attachment->post_parent, $post_id );
     279    }
     280
    257281}
Note: See TracChangeset for help on using the changeset viewer.