media_handle_sideload [ WordPress Function ]
media_handle_sideload ( $file_array, $post_id, $desc = null, $post_data = array() )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: media_handle_upload, wp_handle_sideload, media_sideload_image, wp_handle_upload, wp_embed_handler_googlevideo
This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()}
Source
<?php
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
$overrides = array('test_form'=>false);
$file = wp_handle_sideload($file_array, $overrides);
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$title = preg_replace('/\.[^.]+$/', '', basename($file));
$content = '';
// use image exif/iptc data for title and caption defaults if possible
if ( $image_meta = @wp_read_image_metadata($file) ) {
if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
$title = $image_meta['title'];
if ( trim( $image_meta['caption'] ) )
$content = $image_meta['caption'];
}
if ( isset( $desc ) )
$title = $desc;
// Construct the attachment array
$attachment = array_merge( array(
'post_mime_type' => $type,
'guid' => $url,
'post_parent' => $post_id,
'post_title' => $title,
'post_content' => $content,
), $post_data );
// This should never be set as it would then overwrite an existing attachment.
if ( isset( $attachment['ID'] ) )
unset( $attachment['ID'] );
// Save the attachment metadata
$id = wp_insert_attachment($attachment, $file, $post_id);
if ( !is_wp_error($id) )
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
return $id;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- media_handle_sideload | A HitchHackers guide through WordPress
Feb 12, 2011 ... function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { $overrides = array('test_form'=>false); $file ...
hitchhackerguide.com - #18185 (media_handle_sideload clears $title if $desc is not set ...
media_handle_sideload() -- found in wp-admin>includes>media.php -- is setting $title to ... function media_handle_sideload($file_array, $post_id, $desc = null, ...
core.trac.wordpress.org - #15432 (media_handle_sideload() is not returning right value ...
The media_handle_sideload() is not return the right value. Just like the media_handle_upload you would expect the $id as integer return value, but it returns the ...
core.trac.wordpress.org - media_handle_sideload
Function and Method Cross Reference. media_handle_sideload(). Defined at: / wp-admin/includes/media.php -> line 258. Referenced 1 times: ...
phpxref.ftwr.co.uk