Feeds/Links: fix feed links for unattached attachments.

Adds unit tests.

Props wonderboymusic, iworks.
Fixes #33693.

Built from https://develop.svn.wordpress.org/trunk@34336


git-svn-id: http://core.svn.wordpress.org/trunk@34300 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-19 20:10:24 +00:00
parent 2b3c283040
commit 8d2abbffac
2 changed files with 21 additions and 8 deletions

View File

@ -622,22 +622,35 @@ function get_post_comments_feed_link($post_id = 0, $feed = '') {
if ( empty( $feed ) ) if ( empty( $feed ) )
$feed = get_default_feed(); $feed = get_default_feed();
$post = get_post( $post_id );
$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
if ( '' != get_option('permalink_structure') ) { if ( '' != get_option('permalink_structure') ) {
if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') ) if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') )
$url = _get_page_link( $post_id ); $url = _get_page_link( $post_id );
else else
$url = get_permalink($post_id); $url = get_permalink($post_id);
$url = trailingslashit($url) . 'feed'; if ( $unattached ) {
if ( $feed != get_default_feed() ) $url = home_url( '/feed/' );
$url .= "/$feed"; if ( $feed !== get_default_feed() ) {
$url = user_trailingslashit($url, 'single_feed'); $url .= "$feed/";
}
$url = add_query_arg( 'attachment_id', $post_id, $url );
} else {
$url = trailingslashit($url) . 'feed';
if ( $feed != get_default_feed() )
$url .= "/$feed";
$url = user_trailingslashit($url, 'single_feed');
}
} else { } else {
$type = get_post_field('post_type', $post_id); if ( $unattached ) {
if ( 'page' == $type ) $url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id ), home_url( '/' ) );
} elseif ( 'page' == $post->post_type ) {
$url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) ); $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) );
else } else {
$url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) ); $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) );
}
} }
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-alpha-34335'; $wp_version = '4.4-alpha-34336';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.