[wp-trac] [WordPress Trac] #48427: feed_links_extra() has 2 "elseif ( is_post_type_archive() ) {}" clauses

WordPress Trac noreply at wordpress.org
Thu Oct 24 21:01:41 UTC 2019


#48427: feed_links_extra() has 2 "elseif ( is_post_type_archive() ) {}" clauses
--------------------------+------------------------------
 Reporter:  pbiron        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Feeds         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Description changed by pbiron:

Old description:

> While add some custom RSS feed support to a plugin, I discovered
> something odd about
> [https://developer.wordpress.org/reference/functions/feed_links_extra/
> feed_links_extra()].
>
> It consists a large `if/elseif/elseif` statement and 2 of the `elseif`
> clauses are for `is_post_type_archive()`.
>
> {{{#!php
> if ( is_singular() ) {
> ...
> } elseif ( is_post_type_archive() ) {
>         $post_type = get_query_var( 'post_type' );
>         if ( is_array( $post_type ) ) {
>                 $post_type = reset( $post_type );
>         }
>
>         $post_type_obj = get_post_type_object( $post_type );
>         $title         = sprintf( $args['posttypetitle'], get_bloginfo(
> 'name' ), $args['separator'], $post_type_obj->labels->name );
>         $href          = get_post_type_archive_feed_link(
> $post_type_obj->name );
> }
> ...
> } elseif ( is_post_type_archive() ) {
>         $title         = sprintf( $args['posttypetitle'], get_bloginfo(
> 'name' ), $args['separator'], post_type_archive_title( '', false ) );
>         $post_type_obj = get_queried_object();
>         if ( $post_type_obj ) {
>                 $href = get_post_type_archive_feed_link(
> $post_type_obj->name );
>         }
> }
> }}}
>
> Obviously, the code in the 2nd one will never execute.
>
> I'm a little unclear about how they both ended up in there, as Trac's
> `blame` is a little hard to follow in this case.
>
> One of them should be removed...but not sure which one would be better to
> keep.  Notice that the 1st one uses the `post_type` query arg in building
> the URL for the feed link, while the 2nd one uses `get_queried_object()`.

New description:

 While add some custom RSS feed support to a plugin, I discovered something
 odd about
 [https://developer.wordpress.org/reference/functions/feed_links_extra/
 feed_links_extra()].

 It consists a large `if/elseif/elseif` statement and 2 of the `elseif`
 clauses are for `is_post_type_archive()`.

 {{{#!php
 <?php
 if ( is_singular() ) {
 ...
 } elseif ( is_post_type_archive() ) {
         $post_type = get_query_var( 'post_type' );
         if ( is_array( $post_type ) ) {
                 $post_type = reset( $post_type );
         }

         $post_type_obj = get_post_type_object( $post_type );
         $title         = sprintf( $args['posttypetitle'], get_bloginfo(
 'name' ), $args['separator'], $post_type_obj->labels->name );
         $href          = get_post_type_archive_feed_link(
 $post_type_obj->name );
 }
 ...
 } elseif ( is_post_type_archive() ) {
         $title         = sprintf( $args['posttypetitle'], get_bloginfo(
 'name' ), $args['separator'], post_type_archive_title( '', false ) );
         $post_type_obj = get_queried_object();
         if ( $post_type_obj ) {
                 $href = get_post_type_archive_feed_link(
 $post_type_obj->name );
         }
 }
 }}}

 Obviously, the code in the 2nd one will never execute.

 I'm a little unclear about how they both ended up in there, as Trac's
 `blame` is a little hard to follow in this case.

 One of them should be removed...but not sure which one would be better to
 keep.  Notice that the 1st one uses the `post_type` query arg in building
 the URL for the feed link, while the 2nd one uses `get_queried_object()`.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48427#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list