Rss.php
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace AIOSEO\Plugin\Common;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Adds content before or after posts in the RSS feed.
*
* @since 4.0.0
*/
class Rss {
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
add_filter( 'the_content_feed', [ $this, 'addRssContent' ] );
add_filter( 'the_excerpt_rss', [ $this, 'addRssContentExcerpt' ] );
}
/**
* Adds content before or after the RSS excerpt.
*
* @since 4.0.0
*
* @param string $content The
* @return void
*/
public function addRssContentExcerpt( $content ) {
return $this->addRssContent( $content, 'excerpt' );
}
/**
* Adds content before or after the RSS post.
*
* @since 4.0.0
*
* @param string $content The post content.
* @return string The post content with prepended/appended content.
*/
public function addRssContent( $content, $type = 'complete' ) {
$content = trim( $content );
if ( empty( $content ) ) {
return '';
}
if ( is_feed() ) {
$before = aioseo()->tags->replaceTags( aioseo()->options->rssContent->before, get_the_ID() );
$after = aioseo()->tags->replaceTags( aioseo()->options->rssContent->after, get_the_ID() );
if ( $before || $after ) {
if ( 'excerpt' === $type ) {
$content = wpautop( $content );
}
$content = aioseo()->helpers->decodeHtmlEntities( $before ) . $content . aioseo()->helpers->decodeHtmlEntities( $after );
}
}
return $content;
}
}