Media: Allow `post_date` to be respected in `media_handle_sideload()`.

Previously, date information was unable to be changed when using `media_handle_sideload()`. 

Now you can override the date for a media item using `$post_data['post_date']` before using the function.

Props jamesgol, mukesh27, SergeyBiryukov, hellofromTonya, Mista-Flo.
Fixes #50972.

Built from https://develop.svn.wordpress.org/trunk@50258


git-svn-id: http://core.svn.wordpress.org/trunk@49903 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
antpb 2021-02-08 23:22:04 +00:00
parent 71b277da38
commit 19dbb952f3
2 changed files with 12 additions and 10 deletions

View File

@ -430,21 +430,23 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid
* @since 2.6.0
* @since 5.3.0 The `$post_id` parameter was made optional.
*
* @param array $file_array Array that represents a `$_FILES` upload array.
* @param int $post_id Optional. The post ID the media is associated with.
* @param string $desc Optional. Description of the side-loaded file. Default null.
* @param array $post_data Optional. Post data to override. Default empty array.
* @param string[] $file_array Array that represents a `$_FILES` upload array.
* @param int $post_id Optional. The post ID the media is associated with.
* @param string $desc Optional. Description of the side-loaded file. Default null.
* @param array $post_data Optional. Post data to override. Default empty array.
* @return int|WP_Error The ID of the attachment or a WP_Error on failure.
*/
function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) {
$overrides = array( 'test_form' => false );
$time = current_time( 'mysql' );
$post = get_post( $post_id );
if ( $post ) {
if ( substr( $post->post_date, 0, 4 ) > 0 ) {
if ( isset( $post_data['post_date'] ) && substr( $post_data['post_date'], 0, 4 ) > 0 ) {
$time = $post_data['post_date'];
} else {
$post = get_post( $post_id );
if ( $post && substr( $post->post_date, 0, 4 ) > 0 ) {
$time = $post->post_date;
} else {
$time = current_time( 'mysql' );
}
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.7-beta1-50257';
$wp_version = '5.7-beta1-50258';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.