/** * Pulls the new featured image picture to local and sets it as featured image. * Since 1.0, got it own function in 1.5 * * @since 1.5 */ function set_featured_video_image($post_id, $data) { // Is this screen capture already existing in our media library? $img = $this->featured_video_plus->get_post_by_custom_meta('_fvp_image', $data['provider'] . '?' . $data['id']); if (!isset($img)) { // Generate attachment post metadata $img_data = array('post_content' => $data['description'], 'post_title' => $data['title'], 'post_name' => $data['filename']); // pull external img to local server and add to media library include_once FVP_DIR . 'php/somatic_attach_external_image.php'; $img = somatic_attach_external_image($data['img'], $post_id, false, $data['filename'], $img_data); // generate picture metadata $img_meta = wp_get_attachment_metadata($img); $img_meta['image_meta'] = array('aperture' => 0, 'credit' => $data['id'], 'camera' => $data['provider'], 'caption' => $data['description'], 'created_timestamp' => $data['timestamp'], 'copyright' => $data['author'], 'focal_length' => 0, 'iso' => 0, 'shutter_speed' => 0, 'title' => $data['title']); // save picture metadata wp_update_attachment_metadata($img, $img_meta); update_post_meta($img, '_fvp_image', $data['provider'] . '?' . $data['id']); } if (get_bloginfo('version') >= 3.1 && (!has_post_thumbnail($post_id) || $set_featimg)) { set_post_thumbnail($post_id, $img); } return $img; }
function send_img_to_post2($url, $identify, $short_desc) { global $post; require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; //------------------------- $get_the_id_new_image = somatic_attach_external_image($url, $identify, false, 'itestitonceagain'); //$get_the_id_new_image = somatic_attach_external_image($url,$identify, false, 'itestittwice', $short_desc, array("post_title"=>"$short_desc")); $get_the_url_new_image = wp_get_attachment_url($get_the_id_new_image); return $get_the_url_new_image; }