-
-
Save kalmas/4453401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: RSS Featured Image | |
Description: Add featured image to rss feed. | |
Version: 1.0 | |
*/ | |
/* | |
* Code minimized from | |
* WP RSS Images (http://web-argument.com/wp-rss-images-wordpress-plugin/) | |
*/ | |
function wp_rss_img_do_feed($for_comments) | |
{ | |
if(!$for_comments){ | |
add_action('rss2_ns', 'wp_rss_img_adding_yahoo_media_tag'); | |
add_action('rss_item', 'wp_rss_img_include'); | |
add_action('rss2_item', 'wp_rss_img_include'); | |
} | |
} | |
function wp_rss_img_include () | |
{ | |
$image_url = wp_rss_img_url(); | |
if (!empty($image_url)){ | |
$uploads = wp_upload_dir(); | |
$url = parse_url($image_url); | |
$path = $uploads['basedir'] . preg_replace('/.*uploads(.*)/', '${1}', $url['path']); | |
if (file_exists($path)) | |
{ | |
$url = $path; | |
} else { | |
$ary_header = get_headers($image_url, 1); | |
$url = $image_url; | |
} | |
list($width, $height, $type, $attr) = getimagesize($url); | |
echo '<media:content url="'.$image_url.'" width="'.$width.'" height="'.$height.'" medium="image" type="'.image_type_to_mime_type($type).'" />'; | |
} | |
} | |
function wp_rss_img_url($size = 'full') { | |
global $post; | |
if(function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)){ | |
$thumbnail_id = get_post_thumbnail_id($post->ID); | |
if(!empty($thumbnail_id)){ | |
$img = wp_get_attachment_image_src($thumbnail_id, $size); | |
} | |
} else { | |
$attachments = get_children( array( | |
'post_parent' => $post->ID, | |
'post_type' => 'attachment', | |
'post_mime_type' => 'image', | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'numberposts' => 1) ); | |
if($attachments == true) { | |
foreach($attachments as $id => $attachment){ | |
$img = wp_get_attachment_image_src($id, $size); | |
} | |
} | |
} | |
if (isset($img)) return $img[0]; | |
} | |
function wp_rss_img_adding_yahoo_media_tag(){ | |
echo 'xmlns:media="http://search.yahoo.com/mrss/"'; | |
} | |
add_action("do_feed_rss", "wp_rss_img_do_feed", 5, 1); | |
add_action("do_feed_rss2", "wp_rss_img_do_feed", 5, 1); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment