Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Save External image as Featured with WPUF plugin
- add_action('wpuf_add_post_after_insert', 'featured_img_wpuf');
- function featured_img_wpuf($post_id) {
- //$enlace_link = get_post_meta( $post_id, 'url_link', true );
- $thumb_url = 'http://img.vidaextra.com/2012/11/031112_imagen-disney_01.jpg';
- require_once(ABSPATH . 'wp-admin/includes/file.php');
- require_once(ABSPATH . 'wp-admin/includes/media.php');
- set_time_limit(300);
- if ( ! empty($thumb_url) ) {
- // Download file to temp location
- $tmp = download_url( $thumb_url );
- // Set variables for storage
- // fix file filename for query strings
- preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
- $file_array['name'] = basename($matches[0]);
- $file_array['tmp_name'] = $tmp;
- // If error storing temporarily, unlink
- if ( is_wp_error( $tmp ) ) {
- @unlink($file_array['tmp_name']);
- $file_array['tmp_name'] = '';
- }
- // do the validation and storage stuff
- $thumbid = media_handle_sideload( $file_array, $post_id, $desc );
- // If error storing permanently, unlink
- if ( is_wp_error($thumbid) ) {
- @unlink($file_array['tmp_name']);
- return $thumbid;
- }
- }
- set_post_thumbnail( $post_id, $thumbid );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement