Files
display-featured-image-genesis/includes/class-displayfeaturedimagegenesis-rss.php
T

110 lines
3.5 KiB
PHP
Raw Normal View History

2014-12-12 10:08:00 -05:00
<?php
/**
* @package DisplayFeaturedImageGenesis
* @author Robin Cornett <hello@robincornett.com>
* @license GPL-2.0+
* @link http://robincornett.com
* @copyright 2014 Robin Cornett Creative, LLC
*/
class Display_Featured_Image_Genesis_RSS {
/**
* Decide whether or not to add the featured image to the feed or the feed excerpt
*
* @return filter the_excerpt_rss (if summaries) or the_content_feed (full text)
2014-12-13 10:03:55 -05:00
* @since 1.5.0
2014-12-12 10:08:00 -05:00
*/
public function maybe_do_feed() {
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
$feed_image = $displaysetting['feed_image'];
$rss_option = get_option( 'rss_use_excerpt' );
$post_types = array();
$skipped_types = apply_filters( 'display_featured_image_genesis_skipped_posttypes', $post_types );
2014-12-12 10:08:00 -05:00
2014-12-12 14:05:58 -05:00
//* if the user isn't sending images to the feed, we're done
if ( ! $feed_image || ( in_array( get_post_type(), $skipped_types ) ) ) {
2014-12-12 10:08:00 -05:00
return;
}
2014-12-12 14:05:58 -05:00
//* if the feed is full text, filter the content
if ( '0' === $rss_option ) {
add_filter( 'the_content_feed', array( $this, 'add_image_to_feed' ), 15 );
2014-12-12 10:08:00 -05:00
}
2014-12-12 14:05:58 -05:00
//* if the feed is summaries, filter the excerpt, not the content
2014-12-12 10:08:00 -05:00
else {
2014-12-12 14:05:58 -05:00
add_filter( 'the_excerpt_rss', array( $this, 'add_image_to_feed' ), 1000, 1 );
2014-12-12 10:08:00 -05:00
}
}
/**
* add the featured image to the feed, unless it already exists
* includes allowances for Send Images to RSS plugin, which processes before this
*
* @param return $content
2014-12-13 10:03:55 -05:00
* @since 1.5.0
2014-12-12 10:08:00 -05:00
*/
public function add_image_to_feed( $content ) {
2015-04-05 21:19:14 -04:00
// if the post doesn't have a thumbnail, we're done here
2014-12-12 10:08:00 -05:00
if ( ! has_post_thumbnail() ) {
return $content;
}
2015-04-05 21:19:14 -04:00
// first check: see if the featured image already exists in full in the content
2014-12-12 14:05:58 -05:00
$size = 'original';
2014-12-12 10:08:00 -05:00
if ( class_exists( 'SendImagesRSS' ) ) {
2014-12-12 14:05:58 -05:00
$simplify = get_option( 'sendimagesrss_simplify_feed' );
$alt_feed = get_option( 'sendimagesrss_alternate_feed' );
if ( ! $simplify && ( ( $alt_feed && is_feed( 'email' ) ) || ! $alt_feed ) ) {
$size = 'mailchimp';
}
2014-12-12 10:08:00 -05:00
}
2014-12-12 14:05:58 -05:00
$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), $size );
2014-12-12 10:08:00 -05:00
$image_content = strpos( $content, 'src="' . $post_thumbnail[0] );
2014-12-12 14:05:58 -05:00
$rss_option = get_option( 'rss_use_excerpt' );
2014-12-12 10:08:00 -05:00
2015-04-05 21:19:14 -04:00
// if the featured image already exists in all its glory in the content, we're done here
2014-12-12 14:05:58 -05:00
if ( false !== $image_content && '0' === $rss_option ) {
2014-12-12 10:08:00 -05:00
return $content;
}
2015-04-05 21:19:14 -04:00
// reset size to large so we don't send huge files to the feed
2014-12-12 14:05:58 -05:00
$size = 'large';
if ( class_exists( 'SendImagesRSS' ) ) {
$simplify = get_option( 'sendimagesrss_simplify_feed' );
$alt_feed = get_option( 'sendimagesrss_alternate_feed' );
2015-04-05 21:19:14 -04:00
// if the user is using Send Images to RSS, send the right images to the right feeds
2014-12-12 14:05:58 -05:00
if ( ! $simplify && ( ( $alt_feed && is_feed( 'email' ) ) || ! $alt_feed ) ) {
$size = 'mailchimp';
$class = 'rss-mailchimp';
}
}
2015-04-05 21:19:14 -04:00
$align = '';
$style = 'display:block;margin:10px auto;';
$class = 'rss-featured-image';
2014-12-12 10:08:00 -05:00
2015-04-05 21:19:14 -04:00
// if the feed output is descriptions only, change image size to thumbnail with small alignment
2014-12-12 10:08:00 -05:00
if ( '1' === $rss_option ) {
$size = 'thumbnail';
$align = 'left';
$style = 'margin:0px 0px 20px 20px;';
$class = 'rss-small';
}
2015-04-05 21:19:14 -04:00
// whew. build the image!
$image = get_the_post_thumbnail( get_the_ID(), $size, array( 'align' => $align, 'style' => $style, 'class' => $class ) );
$image = apply_filters( 'display_featured_image_genesis_modify_rss_image', $image );
2014-12-12 10:08:00 -05:00
$content = $image . $content;
return $content;
2014-12-12 14:05:58 -05:00
2014-12-12 10:08:00 -05:00
}
}