diff --git a/src/wp-includes/feed-atom-comments.php b/src/wp-includes/feed-atom-comments.php
index b43f8d4eb1..b9d4f533bb 100644
a
|
b
|
do_action( 'rss_tag_pre', 'atom-comments' ); |
27 | 27 | do_action( 'atom_comments_ns' ); |
28 | 28 | ?> |
29 | 29 | > |
30 | | <title type="text"> |
31 | 30 | <?php |
| 31 | $feed_title = ''; |
32 | 32 | if ( is_singular() ) { |
33 | 33 | /* translators: Comments feed title. %s: Post title. */ |
34 | | printf( ent2ncr( __( 'Comments on %s' ) ), get_the_title_rss() ); |
| 34 | $feed_title = sprintf( ent2ncr( __( 'Comments on: %s' ) ), get_the_title_rss() ); |
35 | 35 | } elseif ( is_search() ) { |
36 | 36 | /* translators: Comments feed title. 1: Site title, 2: Search query. */ |
37 | | printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() ); |
| 37 | $feed_title = sprintf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() ); |
38 | 38 | } else { |
39 | 39 | /* translators: Comments feed title. %s: Site title. */ |
40 | | printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() ); |
| 40 | $feed_title = sprintf( ent2ncr( __( 'Comments for %s' ) ), get_bloginfo_rss( 'name' ) . get_wp_title_rss() ); |
41 | 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Filters the page title for the comments feed. |
| 45 | * |
| 46 | * @since 5.9.0 |
| 47 | * |
| 48 | * @param string $feed_title Comments feed page title. |
| 49 | */ |
| 50 | $feed_title = apply_filters( 'comments_feed_title', $feed_title, get_the_title_rss() ); |
42 | 51 | ?> |
43 | | </title> |
| 52 | |
| 53 | <title type="text"><?php echo $feed_title; ?></title> |
44 | 54 | <subtitle type="text"><?php bloginfo_rss( 'description' ); ?></subtitle> |
45 | 55 | |
46 | 56 | <updated><?php echo get_feed_build_date( 'Y-m-d\TH:i:s\Z' ); ?></updated> |
diff --git a/src/wp-includes/feed-rss2-comments.php b/src/wp-includes/feed-rss2-comments.php
index bf69a4d3ae..d8658eeef9 100644
a
|
b
|
do_action( 'rss_tag_pre', 'rss2-comments' ); |
32 | 32 | ?> |
33 | 33 | > |
34 | 34 | <channel> |
35 | | <title> |
| 35 | |
36 | 36 | <?php |
| 37 | $feed_title = ''; |
37 | 38 | if ( is_singular() ) { |
38 | 39 | /* translators: Comments feed title. %s: Post title. */ |
39 | | printf( ent2ncr( __( 'Comments on: %s' ) ), get_the_title_rss() ); |
| 40 | $feed_title = sprintf( ent2ncr( __( 'Comments on: %s' ) ), get_the_title_rss() ); |
40 | 41 | } elseif ( is_search() ) { |
41 | 42 | /* translators: Comments feed title. 1: Site title, 2: Search query. */ |
42 | | printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() ); |
| 43 | $feed_title = sprintf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() ); |
43 | 44 | } else { |
44 | 45 | /* translators: Comments feed title. %s: Site title. */ |
45 | | printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() ); |
| 46 | $feed_title = sprintf( ent2ncr( __( 'Comments for %s' ) ), get_bloginfo_rss( 'name' ) . get_wp_title_rss() ); |
46 | 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Filters the page title for the comments feed. |
| 51 | * |
| 52 | * @since 5.9.0 |
| 53 | * |
| 54 | * @param string $feed_title Comments feed page title. |
| 55 | */ |
| 56 | $feed_title = apply_filters( 'comments_feed_title', $feed_title, get_the_title_rss() ); |
47 | 57 | ?> |
48 | | </title> |
| 58 | |
| 59 | <title><?php echo $feed_title; ?></title> |
| 60 | <!-- JBA --> |
49 | 61 | <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> |
50 | 62 | <link><?php ( is_single() ) ? the_permalink_rss() : bloginfo_rss( 'url' ); ?></link> |
51 | 63 | <description><?php bloginfo_rss( 'description' ); ?></description> |
diff --git a/tests/phpunit/tests/feed/atom.php b/tests/phpunit/tests/feed/atom.php
index 3b2c827749..41f10b2543 100644
a
|
b
|
class Tests_Feed_Atom extends WP_UnitTestCase { |
12 | 12 | public static $user_id; |
13 | 13 | public static $posts; |
14 | 14 | public static $category; |
| 15 | public static $post_id; |
| 16 | public static $comment_ids = array(); |
15 | 17 | |
16 | 18 | /** |
17 | 19 | * Setup a new user and attribute some posts. |
… |
… |
class Tests_Feed_Atom extends WP_UnitTestCase { |
51 | 53 | wp_set_object_terms( $post, self::$category->slug, 'category' ); |
52 | 54 | } |
53 | 55 | |
| 56 | self::$post_id = $factory->post->create(); |
| 57 | |
| 58 | // Create a comment |
| 59 | self::$comment_ids[] = $factory->comment->create( |
| 60 | array( |
| 61 | 'comment_author' => 1, |
| 62 | 'comment_date' => '2014-05-06 12:00:00', |
| 63 | 'comment_date_gmt' => '2014-05-06 07:00:00', |
| 64 | 'comment_post_ID' => self::$post_id, |
| 65 | ) |
| 66 | ); |
54 | 67 | } |
55 | 68 | |
56 | 69 | /** |
… |
… |
class Tests_Feed_Atom extends WP_UnitTestCase { |
126 | 139 | $this->assertSame( home_url( '/?feed=atom' ), $link[1]['attributes']['href'] ); |
127 | 140 | } |
128 | 141 | |
| 142 | /** |
| 143 | * Test the <feed> element to make sure its present and populated |
| 144 | * with the modified version of the title. |
| 145 | * |
| 146 | * @ticket 13867 |
| 147 | */ |
| 148 | function test_feed_title() { |
| 149 | add_filter( 'comments_feed_title', array( $this, 'apply_comments_feed_title' ), 10, 2 ); |
| 150 | $this->go_to( '?feed=comments-atom' ); |
| 151 | $feed = $this->do_rss2_comments(); |
| 152 | $xml = xml_to_array( $feed ); |
| 153 | |
| 154 | // Get the <feed> child element of <xml>. |
| 155 | $rss = xml_find( $xml, 'feed' ); |
| 156 | error_log( print_r( $rss, true) ); |
| 157 | $this->assertEquals( 'Filtered Title', $rss[0]['child'][0]['child'][0]['content'] ); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Apply the comments feed title filter. |
| 162 | * |
| 163 | * @ticket 13867 |
| 164 | */ |
| 165 | function apply_comments_feed_title( $item_title, $the_title_rss ) { |
| 166 | $item_title = 'Filtered Title'; |
| 167 | return $item_title; |
| 168 | } |
| 169 | |
129 | 170 | /** |
130 | 171 | * Validate <entry> child elements. |
131 | 172 | */ |
diff --git a/tests/phpunit/tests/feed/rss2.php b/tests/phpunit/tests/feed/rss2.php
index 50138cf255..7640e00f52 100644
a
|
b
|
class Tests_Feed_RSS2 extends WP_UnitTestCase { |
13 | 13 | public static $posts; |
14 | 14 | public static $category; |
15 | 15 | public static $post_date; |
| 16 | public static $post_id; |
| 17 | public static $comment_ids = array(); |
16 | 18 | |
17 | 19 | /** |
18 | 20 | * Setup a new user and attribute some posts. |
… |
… |
class Tests_Feed_RSS2 extends WP_UnitTestCase { |
58 | 60 | foreach ( self::$posts as $post ) { |
59 | 61 | wp_set_object_terms( $post, self::$category->slug, 'category' ); |
60 | 62 | } |
| 63 | |
| 64 | self::$post_id = $factory->post->create(); |
| 65 | |
| 66 | // Create a comment |
| 67 | self::$comment_ids[] = $factory->comment->create( |
| 68 | array( |
| 69 | 'comment_author' => 1, |
| 70 | 'comment_date' => '2014-05-06 12:00:00', |
| 71 | 'comment_date_gmt' => '2014-05-06 07:00:00', |
| 72 | 'comment_post_ID' => self::$post_id, |
| 73 | ) |
| 74 | ); |
61 | 75 | } |
62 | 76 | |
63 | 77 | /** |
… |
… |
class Tests_Feed_RSS2 extends WP_UnitTestCase { |
117 | 131 | $this->assertCount( 1, $rss[0]['child'] ); |
118 | 132 | } |
119 | 133 | |
| 134 | /** |
| 135 | * Test the <rss> element to make sure its present and populated |
| 136 | * with the modified version of the title. |
| 137 | * |
| 138 | * @ticket 13867 |
| 139 | */ |
| 140 | function test_feed_title() { |
| 141 | add_filter( 'comments_feed_title', array( $this, 'apply_comments_feed_title' ), 10, 2 ); |
| 142 | $this->go_to( '/comments/feed/' ); |
| 143 | $feed = $this->do_rss2_comments(); |
| 144 | $xml = xml_to_array( $feed ); |
| 145 | |
| 146 | // Get the <rss> child element of <xml>. |
| 147 | $rss = xml_find( $xml, 'rss' ); |
| 148 | error_log( print_r( $rss, true) ); |
| 149 | $this->assertEquals( 'Filtered Title', $rss[0]['child'][0]['child'][0]['content'] ); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Apply the comments feed title filter. |
| 154 | * |
| 155 | * @ticket 13867 |
| 156 | */ |
| 157 | function apply_comments_feed_title( $item_title, $the_title_rss ) { |
| 158 | $item_title = 'Filtered Title'; |
| 159 | return $item_title; |
| 160 | } |
| 161 | |
120 | 162 | /** |
121 | 163 | * [test_channel_element description] |
122 | 164 | * |