| 1 |
<?php |
| 2 |
/** |
| 3 |
* Common utilities for the plugin |
| 4 |
* |
| 5 |
*/ |
| 6 |
|
| 7 |
if( ! defined( 'ABSPATH' ) ) exit; |
| 8 |
|
| 9 |
class SRR_Utilities{ |
| 10 |
|
| 11 |
public static function init(){ |
| 12 |
|
| 13 |
add_filter( 'the_excerpt_rss', array( __CLASS__, 'insert_featured_image_rss_feed' ) ); |
| 14 |
add_filter( 'the_content_feed', array( __CLASS__, 'insert_featured_image_rss_feed' ) ); |
| 15 |
|
| 16 |
} |
| 17 |
|
| 18 |
public static function insert_featured_image_rss_feed( $content ){ |
| 19 |
|
| 20 |
global $post; |
| 21 |
|
| 22 |
preg_match_all( '~<img.*?src=["\']+(.*?)["\']+~', $content, $image_urls ); |
| 23 |
|
| 24 |
if( empty( $image_urls[1] ) && has_post_thumbnail( $post->ID ) ) { |
| 25 |
$content = '<p>' . get_the_post_thumbnail( $post->ID ) . '</p>' . $content; |
| 26 |
} |
| 27 |
|
| 28 |
return $content; |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
SRR_Utilities::init(); |
| 35 |
|
| 36 |
?> |