Make WordPress Core

Ticket #38959: wordpress_38959.diff

File wordpress_38959.diff, 1.2 KB (added by dotancohen, 9 years ago)

Patch to optionally allow a sideloaded media file to not be assigned to a particular post.

  • src/wp-admin/includes/media.php

    diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php
    index c6b2dcd..57fc0df 100644
    a b function media_handle_upload($file_id, $post_id, $post_data = array(), $override 
    385385 * @since 2.6.0
    386386 *
    387387 * @param array  $file_array Array similar to a `$_FILES` upload array.
    388  * @param int    $post_id    The post ID the media is associated with.
     388 * @param int    $post_id    Optional. The post ID the media is associated with.
    389389 * @param string $desc       Optional. Description of the side-loaded file. Default null.
    390390 * @param array  $post_data  Optional. Post data to override. Default empty array.
    391391 * @return int|object The ID of the attachment or a WP_Error on failure.
    392392 */
    393 function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data = array() ) {
     393function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) {
    394394        $overrides = array('test_form'=>false);
    395395
    396396        $time = current_time( 'mysql' );
    397         if ( $post = get_post( $post_id ) ) {
     397        if ( $post_id && $post = get_post( $post_id ) ) {
    398398                if ( substr( $post->post_date, 0, 4 ) > 0 )
    399399                        $time = $post->post_date;
    400400        }