mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-15 07:05:37 +01:00
Media: Optionally return attachment id from media_sideload_image()
.
Introduces option to `$return` parameter to return the attachment id created after a successful image sideload. Props slbmeh, kawauso, alexkingorg, SergeyBiryukov, georgestephanis, DrewAPicture, nacin, trepmal, mattheu, kraftbj, whyisjake, dotancohen, MrGregWaugh, danielbachhuber. Fixes #19629. Built from https://develop.svn.wordpress.org/trunk@40597 git-svn-id: http://core.svn.wordpress.org/trunk@40467 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d5ae7e682e
commit
391145df30
@ -852,11 +852,12 @@ function wp_media_upload_handler() {
|
|||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
* @since 4.2.0 Introduced the `$return` parameter.
|
* @since 4.2.0 Introduced the `$return` parameter.
|
||||||
|
* @since 4.8.0 Introduced the 'id' option within the `$return` parameter.
|
||||||
*
|
*
|
||||||
* @param string $file The URL of the image to download.
|
* @param string $file The URL of the image to download.
|
||||||
* @param int $post_id The post ID the media is to be associated with.
|
* @param int $post_id The post ID the media is to be associated with.
|
||||||
* @param string $desc Optional. Description of the image.
|
* @param string $desc Optional. Description of the image.
|
||||||
* @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'.
|
* @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'.
|
||||||
* @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
|
* @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
|
||||||
*/
|
*/
|
||||||
function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
|
function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
|
||||||
@ -886,6 +887,9 @@ function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' )
|
|||||||
if ( is_wp_error( $id ) ) {
|
if ( is_wp_error( $id ) ) {
|
||||||
@unlink( $file_array['tmp_name'] );
|
@unlink( $file_array['tmp_name'] );
|
||||||
return $id;
|
return $id;
|
||||||
|
// If attachment id was requested, return it early.
|
||||||
|
} elseif ( $return === 'id' ) {
|
||||||
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$src = wp_get_attachment_url( $id );
|
$src = wp_get_attachment_url( $id );
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.8-alpha-40596';
|
$wp_version = '4.8-alpha-40597';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user