Make WordPress Core

Changeset 34336


Ignore:
Timestamp:
09/19/2015 08:09:05 PM (9 years ago)
Author:
wonderboymusic
Message:

Feeds/Links: fix feed links for unattached attachments.

Adds unit tests.

Props wonderboymusic, iworks.
Fixes #33693.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r34177 r34336  
    623623        $feed = get_default_feed();
    624624
     625    $post = get_post( $post_id );
     626    $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
     627
    625628    if ( '' != get_option('permalink_structure') ) {
    626629        if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') )
     
    629632            $url = get_permalink($post_id);
    630633
    631         $url = trailingslashit($url) . 'feed';
    632         if ( $feed != get_default_feed() )
    633             $url .= "/$feed";
    634         $url = user_trailingslashit($url, 'single_feed');
     634        if ( $unattached ) {
     635            $url =  home_url( '/feed/' );
     636            if ( $feed !== get_default_feed() ) {
     637                $url .= "$feed/";
     638            }
     639            $url = add_query_arg( 'attachment_id', $post_id, $url );
     640        } else {
     641            $url = trailingslashit($url) . 'feed';
     642            if ( $feed != get_default_feed() )
     643                $url .= "/$feed";
     644            $url = user_trailingslashit($url, 'single_feed');
     645        }
    635646    } else {
    636         $type = get_post_field('post_type', $post_id);
    637         if ( 'page' == $type )
     647        if ( $unattached ) {
     648            $url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id ), home_url( '/' ) );
     649        } elseif ( 'page' == $post->post_type ) {
    638650            $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) );
    639         else
     651        } else {
    640652            $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) );
     653        }
    641654    }
    642655
Note: See TracChangeset for help on using the changeset viewer.