mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-06 23:58:03 +00:00
Press This:
- Strip slashes while running side_load_images(), add slashes after. - Simplify and clean up side_load_images(). - Add another arg to media_sideload_image() to return the uploaded image src only, and fix it to always return WP_Error on errors. Fixes #31660. git-svn-id: https://develop.svn.wordpress.org/trunk@31799 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -829,9 +829,10 @@ function wp_media_upload_handler() {
|
||||
* @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 string $desc Optional. Description of the image
|
||||
* @param string $return Optional. What to return: an image tag (default) or only the src.
|
||||
* @return string|WP_Error Populated HTML img tag on success
|
||||
*/
|
||||
function media_sideload_image( $file, $post_id, $desc = null ) {
|
||||
function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
|
||||
if ( ! empty( $file ) ) {
|
||||
// Set variables for storage, fix file filename for query strings.
|
||||
preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
|
||||
@@ -860,9 +861,15 @@ function media_sideload_image( $file, $post_id, $desc = null ) {
|
||||
|
||||
// Finally check to make sure the file has been saved, then return the HTML.
|
||||
if ( ! empty( $src ) ) {
|
||||
if ( $return === 'src' ) {
|
||||
return $src;
|
||||
}
|
||||
|
||||
$alt = isset( $desc ) ? esc_attr( $desc ) : '';
|
||||
$html = "<img src='$src' alt='$alt' />";
|
||||
return $html;
|
||||
} else {
|
||||
return new WP_Error( 'image_sideload_failed' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3071,4 +3078,4 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) {
|
||||
wp_redirect( $location );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user