Ticket #19629: 19629-deprecated.2.diff
File 19629-deprecated.2.diff, 5.0 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/class-wp-press-this.php
80 80 } 81 81 82 82 // Sideload image, which gives us a new image src. 83 $new_src = media_sideload_image( $image_src, $post_id, null, 'src');83 $new_src_id = media_handle_sideload( $image_src, $post_id, null ); 84 84 85 if ( ! is_wp_error( $new_src ) ) { 85 if ( ! is_wp_error( $new_src_id ) ) { 86 $new_src = wp_get_attachment_url( $new_src_id ); 86 87 // Replace the POSTED content <img> with correct uploaded ones. 87 88 // Need to do it in two steps so we don't replace links to the original image if any. 88 89 $new_image = str_replace( $image_src, $new_src, $image ); -
src/wp-admin/includes/deprecated.php
1183 1183 function _relocate_children( $old_ID, $new_ID ) { 1184 1184 _deprecated_function( __FUNCTION__, '3.9' ); 1185 1185 } 1186 1187 /** 1188 * Downloads an image from the specified URL and attaches it to a post. 1189 * 1190 * @since 2.6.0 1191 * @since 4.2.0 Introduced the `$return` parameter. 1192 * @deprecated X.X.X 1193 * 1194 * @param string $file The URL of the image to download. 1195 * @param int $post_id The post ID the media is to be associated with. 1196 * @param string $desc Optional. Description of the image. 1197 * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'. 1198 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise. 1199 */ 1200 function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) { 1201 _deprecated_function( __FUNCTION__, 'X.X.X' ); 1202 if ( ! empty( $file ) ) { 1203 1204 // Set variables for storage, fix file filename for query strings. 1205 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); 1206 $file_array = array(); 1207 $file_array['name'] = basename( $matches[0] ); 1208 1209 // Download file to temp location. 1210 $file_array['tmp_name'] = download_url( $file ); 1211 1212 // If error storing temporarily, return the error. 1213 if ( is_wp_error( $file_array['tmp_name'] ) ) { 1214 return $file_array['tmp_name']; 1215 } 1216 1217 // Do the validation and storage stuff. 1218 $id = media_handle_sideload( $file_array, $post_id, $desc ); 1219 1220 // If error storing permanently, unlink. 1221 if ( is_wp_error( $id ) ) { 1222 @unlink( $file_array['tmp_name'] ); 1223 return $id; 1224 } 1225 1226 $src = wp_get_attachment_url( $id ); 1227 } 1228 1229 // Finally, check to make sure the file has been saved, then return the HTML. 1230 if ( ! empty( $src ) ) { 1231 if ( $return === 'src' ) { 1232 return $src; 1233 } 1234 1235 $alt = isset( $desc ) ? esc_attr( $desc ) : ''; 1236 $html = "<img src='$src' alt='$alt' />"; 1237 return $html; 1238 } else { 1239 return new WP_Error( 'image_sideload_failed' ); 1240 } 1241 } 1242 No newline at end of file -
src/wp-admin/includes/media.php
827 827 } 828 828 829 829 /** 830 * Downloads an image from the specified URL and attaches it to a post.831 *832 * @since 2.6.0833 * @since 4.2.0 Introduced the `$return` parameter.834 *835 * @param string $file The URL of the image to download.836 * @param int $post_id The post ID the media is to be associated with.837 * @param string $desc Optional. Description of the image.838 * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'.839 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.840 */841 function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {842 if ( ! empty( $file ) ) {843 844 // Set variables for storage, fix file filename for query strings.845 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );846 $file_array = array();847 $file_array['name'] = basename( $matches[0] );848 849 // Download file to temp location.850 $file_array['tmp_name'] = download_url( $file );851 852 // If error storing temporarily, return the error.853 if ( is_wp_error( $file_array['tmp_name'] ) ) {854 return $file_array['tmp_name'];855 }856 857 // Do the validation and storage stuff.858 $id = media_handle_sideload( $file_array, $post_id, $desc );859 860 // If error storing permanently, unlink.861 if ( is_wp_error( $id ) ) {862 @unlink( $file_array['tmp_name'] );863 return $id;864 }865 866 $src = wp_get_attachment_url( $id );867 }868 869 // Finally, check to make sure the file has been saved, then return the HTML.870 if ( ! empty( $src ) ) {871 if ( $return === 'src' ) {872 return $src;873 }874 875 $alt = isset( $desc ) ? esc_attr( $desc ) : '';876 $html = "<img src='$src' alt='$alt' />";877 return $html;878 } else {879 return new WP_Error( 'image_sideload_failed' );880 }881 }882 883 /**884 830 * {@internal Missing Short Description}} 885 831 * 886 832 * @since 2.5.0