[wp-trac] [WordPress Trac] #50972: media_handle_sideload() does not allow $post_data to override the post_date that gets used by wp_upload_dir
WordPress Trac
noreply at wordpress.org
Mon Feb 8 21:24:52 UTC 2021
#50972: media_handle_sideload() does not allow $post_data to override the post_date
that gets used by wp_upload_dir
--------------------------+-----------------------------
Reporter: jamesgol | Owner: SergeyBiryukov
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 5.7
Component: Media | Version: 5.3
Severity: minor | Resolution:
Keywords: has-patch | Focuses:
--------------------------+-----------------------------
Comment (by hellofromTonya):
Testing strategy:
Used this code in a must-use script:
{{{#!php
<?php
add_action( 'admin_init', function() {
if ( ! isset( $_GET['test50972'] ) ) {
return;
}
$url = 'https://s.w.org/about/images/logos/wordpress-logo-stacked-
rgb.png';
$tmp = download_url( $url );
if ( is_wp_error( $tmp ) ) {
return;
}
$file_array = array(
'name' => basename( $url ),
'tmp_name' => $tmp
);
$post_id = 0;
$post_data = array(); //array( 'post_date' => '2019-01-01
00:00:00' );
media_handle_sideload( $file_array, $post_id, null, $post_data );
} );
}}}
Test an unattached file without passing post date:
1. Go to the Media Library in the backend
2. Append `?test50972=` to the end of the URL in your browser
3. Press enter/return to load that URL
4. The logo image should now appear in the library
5. The image's path should be `wp-
content/uploads/currentYear/currentMonth/ /Users/hellofromtonya/Dev
/wordpress-develop/src/wp-content/uploads/2021/02/wordpress-logo-stacked-
rgb.png` and the other versions of it
This is the previous expected behavior.
Test when attached to the default "Hello World" post 1 without passing
post date:
1. Change the date of the "Hello World" post to a different year such as
"2020"
2. In the test code above, change the `$post_id = 1;`
3. Repeat the above test
4. The new image's path should be in `wp-content/uploads/currentYear/2020/
This is the previous expected behavior.
Test when passing the post's date:
1. In the test code above, change the `$post_data` to use the commented
out array: ` $post_data = array( 'post_date' => '2019-01-01 00:00:00'
);`
2. Repeat the above test
3. The new image's path should be in `wp-content/uploads/currentYear/2019/
This is the new change.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50972#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list