Make WordPress Core


Ignore:
Timestamp:
03/17/2015 12:46:01 AM (11 years ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r31694 r31799  
    830830 * @param int $post_id The post ID the media is to be associated with
    831831 * @param string $desc Optional. Description of the image
     832 * @param string $return Optional. What to return: an image tag (default) or only the src.
    832833 * @return string|WP_Error Populated HTML img tag on success
    833834 */
    834 function media_sideload_image( $file, $post_id, $desc = null ) {
     835function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
    835836    if ( ! empty( $file ) ) {
    836837        // Set variables for storage, fix file filename for query strings.
     
    861862    // Finally check to make sure the file has been saved, then return the HTML.
    862863    if ( ! empty( $src ) ) {
     864        if ( $return === 'src' ) {
     865            return $src;
     866        }
     867
    863868        $alt = isset( $desc ) ? esc_attr( $desc ) : '';
    864869        $html = "<img src='$src' alt='$alt' />";
    865870        return $html;
     871    } else {
     872        return new WP_Error( 'image_sideload_failed' );
    866873    }
    867874}
Note: See TracChangeset for help on using the changeset viewer.