| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JP\CC\Site; |
| 5 |
|
| 6 |
use JP\CC\Options; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
|
| 13 |
class Feeds { |
| 14 |
|
| 15 |
public static function init() { |
| 16 |
add_action( 'the_excerpt', array( __CLASS__, 'filter_feed_posts' ) ); |
| 17 |
add_action( 'the_content', array( __CLASS__, 'filter_feed_posts' ) ); |
| 18 |
add_filter( 'jp_cc_restricted_message', array( __CLASS__, 'restricted_message_filter' ), 10, 1 ); |
| 19 |
} |
| 20 |
|
| 21 |
public static function filter_feed_posts( $content ) { |
| 22 |
global $post; |
| 23 |
|
| 24 |
if( ! is_feed() ) { |
| 25 |
return $content; |
| 26 |
} |
| 27 |
|
| 28 |
if ( ! isset( Restrictions::$protected_posts[ $post->ID ] ) ) { |
| 29 |
Restrictions::$protected_posts[ $post->ID ] = Restrictions::restricted_content(); |
| 30 |
} |
| 31 |
|
| 32 |
$restricted_content = Restrictions::$protected_posts[ $post->ID ]; |
| 33 |
|
| 34 |
if ( ! $restricted_content ) { |
| 35 |
return $content; |
| 36 |
} |
| 37 |
|
| 38 |
if ( isset( $restricted_content['override_default_message'] ) ) { |
| 39 |
$message = $restricted_content['custom_message']; |
| 40 |
} else { |
| 41 |
$message = Options::get( 'default_denial_message', '' ); |
| 42 |
} |
| 43 |
|
| 44 |
if ( empty( $message ) ) { |
| 45 |
$message = __( 'This content is restricted.', 'content-control' ); |
| 46 |
} |
| 47 |
|
| 48 |
//return Posts::format_message( $message ); |
| 49 |
return Posts::format_message( $message ); |
| 50 |
} |
| 51 |
|
| 52 |
public static function restricted_message_filter( $message ) { |
| 53 |
if ( ! is_feed() ) { |
| 54 |
return $message; |
| 55 |
} |
| 56 |
return do_shortcode( $message ); |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|