function wp_rp_get_attached_img_url($related_post, $size) { $extracted_image = get_post_meta($related_post->ID, '_wp_rp_image', true); if ($extracted_image === 'empty') { return false; } $image_data = wp_rp_get_image_data((int) $extracted_image); if (!$image_data && $extracted_image) { // image_id in the db is incorrect delete_post_meta($related_post->ID, '_wp_rp_image'); } if (!$image_data && has_post_thumbnail($related_post->ID)) { $image_data = wp_rp_get_image_data(get_post_thumbnail_id($related_post->ID)); } if (!$image_data && function_exists('get_post_format_meta') && function_exists('img_html_to_post_id')) { // WP 3.6 Image post format. Check wp-includes/media.php:get_the_post_format_image for the reference. $meta = get_post_format_meta($related_post->ID); if (!empty($meta['image'])) { if (is_numeric($meta['image'])) { $image_id = absint($meta['image']); } else { $image_id = img_html_to_post_id($meta['image']); } $image_data = wp_rp_get_image_data($image_id); } } if (!$image_data) { wp_rp_extract_images_from_post($related_post); return false; } if ($img_src = wp_rp_get_image_with_exact_size($image_data, $size)) { return $img_src['url']; } wp_rp_extract_images_from_post($related_post, $image_data['id']); return false; }
function wp_rp_get_post_thumbnail_img($related_post, $size = null, $force = false) { $options = wp_rp_get_options(); $platform_options = wp_rp_get_platform_options(); if (!($platform_options["display_thumbnail"] || $force)) { return false; } $post_id = str_replace("in_", "", "{$related_post->ID}"); $post_title = wptexturize($related_post->post_title); $size = wp_rp_get_thumbnail_size_array($size); if (!$size) { return false; } if ($options['thumbnail_use_custom']) { $thumbnail_src = get_post_meta($post_id, $options["thumbnail_custom_field"], true); if ($thumbnail_src) { return wp_rp_get_img_tag($thumbnail_src, $post_title, $size); } } $featured_image = get_post_thumbnail_id($post_id); if ($featured_image) { $featured_image_data = wp_rp_get_image_data($featured_image); $featured_image_thumb = wp_rp_get_image_with_exact_size($featured_image_data, $size); if ($featured_image_thumb) { return wp_rp_get_img_tag($featured_image_thumb["url"], $post_title, $size); } else { return get_the_post_thumbnail($post_id, $size); } } $attached_img_url = wp_rp_get_attached_img_url($related_post, $size); if ($attached_img_url) { return wp_rp_get_img_tag($attached_img_url, $post_title, $size); } return wp_rp_get_img_tag(wp_rp_get_default_thumbnail_url($related_post->ID, $size), $post_title, $size); }