mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-07-11 18:46:03 +09:00
add class for RSS work
extracted RSS filters from output class and created new RSS class.
This commit is contained in:
@@ -29,18 +29,21 @@ require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesi
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-common.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-description.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-output.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-rss.php';
|
||||
require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-settings.php';
|
||||
|
||||
// Instantiate dependent classes
|
||||
$displayfeaturedimagegenesis_common = new Display_Featured_Image_Genesis_Common();
|
||||
$displayfeaturedimagegenesis_description = new Display_Featured_Image_Genesis_Description();
|
||||
$displayfeaturedimagegenesis_output = new Display_Featured_Image_Genesis_Output();
|
||||
$displayfeaturedimagegenesis_rss = new Display_Featured_Image_Genesis_RSS();
|
||||
$displayfeaturedimagegenesis_settings = new Display_Featured_Image_Genesis_Settings();
|
||||
|
||||
$displayfeaturedimage = new Display_Featured_Image_Genesis(
|
||||
$displayfeaturedimagegenesis_common,
|
||||
$displayfeaturedimagegenesis_description,
|
||||
$displayfeaturedimagegenesis_output,
|
||||
$displayfeaturedimagegenesis_rss,
|
||||
$displayfeaturedimagegenesis_settings
|
||||
);
|
||||
|
||||
|
||||
@@ -188,77 +188,4 @@ class Display_Featured_Image_Genesis_Output {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @since x.y.z
|
||||
*/
|
||||
public function maybe_do_feed() {
|
||||
|
||||
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
|
||||
$feed_image = $displaysetting['feed_image'];
|
||||
$rss_option = get_option( 'rss_use_excerpt' );
|
||||
|
||||
if ( ! $feed_image ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( '1' === $rss_option ) {
|
||||
add_filter( 'the_excerpt_rss', array( $this, 'add_image_to_feed' ), 1000, 1 );
|
||||
}
|
||||
else {
|
||||
add_filter( 'the_content_feed', array( $this, 'add_image_to_feed' ), 15 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @since x.y.z
|
||||
*/
|
||||
public function add_image_to_feed( $content ) {
|
||||
|
||||
if ( ! has_post_thumbnail() ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'original' );
|
||||
if ( class_exists( 'SendImagesRSS' ) ) {
|
||||
$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'mailchimp' );
|
||||
}
|
||||
$image_content = strpos( $content, 'src="' . $post_thumbnail[0] );
|
||||
|
||||
if ( false !== $image_content ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$rss_option = get_option( 'rss_use_excerpt' );
|
||||
$size = 'large';
|
||||
$align = '';
|
||||
$style = 'display:block;margin:10px auto;';
|
||||
$class = 'rss-featured-image';
|
||||
|
||||
if ( class_exists( 'SendImagesRSS' ) ) {
|
||||
$size = 'mailchimp';
|
||||
$class = 'rss-mailchimp';
|
||||
}
|
||||
|
||||
if ( '1' === $rss_option ) {
|
||||
$size = 'thumbnail';
|
||||
$align = 'left';
|
||||
$style = 'margin:0px 0px 20px 20px;';
|
||||
$class = 'rss-small';
|
||||
}
|
||||
|
||||
$image = get_the_post_thumbnail( get_the_ID(), $size, array( 'align' => $align, 'style' => $style, 'class' => $class ) );
|
||||
|
||||
$content = $image . $content;
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?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)
|
||||
* @since x.y.z
|
||||
*/
|
||||
public function maybe_do_feed() {
|
||||
|
||||
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
|
||||
$feed_image = $displaysetting['feed_image'];
|
||||
$rss_option = get_option( 'rss_use_excerpt' );
|
||||
|
||||
if ( ! $feed_image ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( '1' === $rss_option ) {
|
||||
add_filter( 'the_excerpt_rss', array( $this, 'add_image_to_feed' ), 1000, 1 );
|
||||
}
|
||||
else {
|
||||
add_filter( 'the_content_feed', array( $this, 'add_image_to_feed' ), 15 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @since x.y.z
|
||||
*/
|
||||
public function add_image_to_feed( $content ) {
|
||||
|
||||
if ( ! has_post_thumbnail() ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'original' );
|
||||
if ( class_exists( 'SendImagesRSS' ) ) {
|
||||
$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'mailchimp' );
|
||||
}
|
||||
$image_content = strpos( $content, 'src="' . $post_thumbnail[0] );
|
||||
|
||||
if ( false !== $image_content ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$rss_option = get_option( 'rss_use_excerpt' );
|
||||
$size = 'large';
|
||||
$align = '';
|
||||
$style = 'display:block;margin:10px auto;';
|
||||
$class = 'rss-featured-image';
|
||||
|
||||
if ( class_exists( 'SendImagesRSS' ) ) {
|
||||
$size = 'mailchimp';
|
||||
$class = 'rss-mailchimp';
|
||||
}
|
||||
|
||||
if ( '1' === $rss_option ) {
|
||||
$size = 'thumbnail';
|
||||
$align = 'left';
|
||||
$style = 'margin:0px 0px 20px 20px;';
|
||||
$class = 'rss-small';
|
||||
}
|
||||
|
||||
$image = get_the_post_thumbnail( get_the_ID(), $size, array( 'align' => $align, 'style' => $style, 'class' => $class ) );
|
||||
|
||||
$content = $image . $content;
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,10 +16,11 @@
|
||||
*/
|
||||
class Display_Featured_Image_Genesis {
|
||||
|
||||
function __construct( $common, $description, $output, $settings ) {
|
||||
function __construct( $common, $description, $output, $rss, $settings ) {
|
||||
$this->common = $common;
|
||||
$this->archive = $description;
|
||||
$this->output = $output;
|
||||
$this->rss = $rss;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ class Display_Featured_Image_Genesis {
|
||||
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
||||
add_action( 'admin_menu', array( $this->settings, 'do_submenu_page' ) );
|
||||
add_action( 'get_header', array( $this->output, 'manage_output' ) );
|
||||
add_action( 'template_redirect', array( $this->output, 'maybe_do_feed' ) );
|
||||
add_action( 'template_redirect', array( $this->rss, 'maybe_do_feed' ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user