Make media_handle_sideload() return attachment id instead of URL. Props joostdevalk. Fixes #15432
git-svn-id: http://svn.automattic.com/wordpress/trunk@16383 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9e939da4f3
commit
2dcfb8a55f
|
@ -239,15 +239,15 @@ function media_handle_upload($file_id, $post_id, $post_data = array(), $override
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@internal Missing Short Description}}
|
* This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()}
|
||||||
*
|
*
|
||||||
* @since unknown
|
* @since 2.6
|
||||||
*
|
*
|
||||||
* @param unknown_type $file_array
|
* @param array $file_array Array similar to a {@link $_FILES} upload array
|
||||||
* @param unknown_type $post_id
|
* @param int $post_id The post ID the media is associated with
|
||||||
* @param unknown_type $desc
|
* @param string $desc Description of the sideloaded file
|
||||||
* @param unknown_type $post_data
|
* @param array $post_data allows you to overwrite some of the attachment
|
||||||
* @return unknown
|
* @return int|object The ID of the attachment or a WP_Error on failure
|
||||||
*/
|
*/
|
||||||
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
|
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
|
||||||
$overrides = array('test_form'=>false);
|
$overrides = array('test_form'=>false);
|
||||||
|
@ -283,10 +283,9 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
|
||||||
|
|
||||||
// Save the attachment metadata
|
// Save the attachment metadata
|
||||||
$id = wp_insert_attachment($attachment, $file, $post_id);
|
$id = wp_insert_attachment($attachment, $file, $post_id);
|
||||||
if ( !is_wp_error($id) ) {
|
if ( !is_wp_error($id) )
|
||||||
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
|
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,14 +517,14 @@ function media_sideload_image($file, $post_id, $desc = null) {
|
||||||
$file_array['tmp_name'] = $tmp;
|
$file_array['tmp_name'] = $tmp;
|
||||||
|
|
||||||
// If error storing temporarily, unlink
|
// If error storing temporarily, unlink
|
||||||
if ( is_wp_error($tmp) ) {
|
if ( is_wp_error( $tmp ) ) {
|
||||||
@unlink($file_array['tmp_name']);
|
@unlink($file_array['tmp_name']);
|
||||||
$file_array['tmp_name'] = '';
|
$file_array['tmp_name'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the validation and storage stuff
|
// do the validation and storage stuff
|
||||||
$id = media_handle_sideload($file_array, $post_id, @$desc);
|
$id = media_handle_sideload( $file_array, $post_id, @$desc );
|
||||||
$src = $id;
|
$src = get_attachment_link( $id );
|
||||||
|
|
||||||
// If error storing permanently, unlink
|
// If error storing permanently, unlink
|
||||||
if ( is_wp_error($id) ) {
|
if ( is_wp_error($id) ) {
|
||||||
|
|
Loading…
Reference in New Issue