mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Feeds: Fix the URL returned by get_feed_link() when pretty permalinks are not in use.
Props hauvong, peterwilsoncc, SergeyBiryukov Fixes #51839 git-svn-id: https://develop.svn.wordpress.org/trunk@50354 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -690,7 +690,7 @@ function get_feed_link( $feed = '' ) {
|
||||
|
||||
$permalink = $wp_rewrite->get_feed_permastruct();
|
||||
|
||||
if ( '' !== $permalink ) {
|
||||
if ( $permalink ) {
|
||||
if ( false !== strpos( $feed, 'comments_' ) ) {
|
||||
$feed = str_replace( 'comments_', '', $feed );
|
||||
$permalink = $wp_rewrite->get_comment_feed_permastruct();
|
||||
|
||||
67
tests/phpunit/tests/link/getFeedLink.php
Normal file
67
tests/phpunit/tests/link/getFeedLink.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group link
|
||||
* @covers ::get_feed_link
|
||||
*/
|
||||
class Tests_Link_GetFeedLink extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 51839
|
||||
* @dataProvider data_plain_permastruct
|
||||
*
|
||||
* @param string $expected Expected suffix to home_url().
|
||||
* @param string $type Feed type to request.
|
||||
*/
|
||||
public function tests_plain_permastruct( $expected, $type ) {
|
||||
$this->set_permalink_structure( '' );
|
||||
|
||||
$this->assertSame( home_url( $expected ), get_feed_link( $type ) );
|
||||
}
|
||||
|
||||
public function data_plain_permastruct() {
|
||||
return array(
|
||||
array( '?feed=rss2', '' ),
|
||||
array( '?feed=atom', 'atom' ),
|
||||
array( '?feed=get-feed-link', 'get-feed-link' ),
|
||||
array( '?feed=comments-rss2', 'comments_rss2' ),
|
||||
array( '?feed=comments-atom', 'comments_atom' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 51839
|
||||
* @dataProvider data_pretty_permastruct
|
||||
*
|
||||
* @param string $expected Expected suffix to home_url().
|
||||
* @param string $type Feed type to request.
|
||||
*/
|
||||
public function tests_pretty_permastruct( $expected, $type ) {
|
||||
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
|
||||
|
||||
$this->assertSame( home_url( $expected ), get_feed_link( $type ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 51839
|
||||
* @dataProvider data_pretty_permastruct
|
||||
*
|
||||
* @param string $expected Expected suffix to home_url().
|
||||
* @param string $type Feed type to request.
|
||||
*/
|
||||
public function tests_pretty_permastruct_with_prefix( $expected, $type ) {
|
||||
$this->set_permalink_structure( '/archives/%post_id%/%postname%/' );
|
||||
|
||||
$this->assertSame( home_url( $expected ), get_feed_link( $type ) );
|
||||
}
|
||||
|
||||
public function data_pretty_permastruct() {
|
||||
return array(
|
||||
array( '/feed/', '' ),
|
||||
array( '/feed/atom/', 'atom' ),
|
||||
array( '/feed/get-feed-link/', 'get-feed-link' ),
|
||||
array( '/comments/feed/', 'comments_rss2' ),
|
||||
array( '/comments/feed/atom/', 'comments_atom' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user