Make WordPress Core

Opened 7 years ago

Last modified 6 years ago

#43860 new enhancement

Dead code in feed_links_extra()

Reported by: dmenard's profile dmenard Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.7
Component: Feeds Keywords: has-patch
Focuses: template Cc:

Description

Probably a detail, but in general-template.php, function feed_links_extra() contains two elseif statements with the same condition if ( is_post_type_archive() ).

The second one can't be reached and can be considered as dead code.

Attachments (1)

43860.diff (827 bytes) - added by dmenard 7 years ago.
Remove duplicate elseif clause in feed_links_extra()

Download all attachments as: .zip

Change History (8)

#1 @desrosj
7 years ago

  • Focuses template added; coding-standards removed
  • Keywords needs-patch added
  • Version set to 3.7

Thanks for the ticket, @dmenard! And welcome to Trac.

Good find. Looks like the first conditional was introduced in r25291. I think we can remove the second conditional, but we need to make sure something was not left behind in the new conditional.

Are you interested in creating a patch for this?

#2 @desrosj
7 years ago

  • Milestone changed from Awaiting Review to 5.0
  • Severity changed from trivial to normal

@dmenard
7 years ago

Remove duplicate elseif clause in feed_links_extra()

#3 @dmenard
7 years ago

  • Keywords has-patch added; needs-patch removed

Hello @desrosj,

Thanks for the kind words!

we need to make sure something was not left behind in the new conditional

There are some differences between the old clause and the new one:

  • post type object: the old clause was using get_queried_object() to get the post type object. The new clause uses get_query_var( 'post_type' ) and keeps only the first value if there are many ones.
  • feed title: the old clause was using post_type_archive_title() (which can be filtered) to construct the feed title. The new clause calls directly $post_type_obj->labels->name.
  • return value: the old clause was creating a feed link only if we got a valid queried object. There are no checks in the new clause: we use directly the query var, call get_post_type_object() (which can return null) and always generate a feed by calling get_post_type_archive_feed_link( $post_type_obj->name ) (will generate a warning and an empty href if the post type is not valid). But perhaps the post_type query var is validated elsewhere during the query parsing?

So, it's not the same...

However, if the modification was introduced in r25291 as you found, it means that the old code has not been executed for more than five years. So I presume the new code is ok?..

Are you interested in creating a patch for this?

For now, I've added a diff attachment wich removes the duplicate elseif clause in feed_links_extra() and does nothing else.

As I haven't used svn for years, this is a git diff (I followed the guidelines of the handbook).

I hope it's ok, please let me know.

Last edited 7 years ago by dmenard (previous) (diff)

#4 @desrosj
7 years ago

#44071 was marked as a duplicate.

#5 @Ruxton
7 years ago

There's an issue with having it so far up the if/else stack as the new code (and therefore the proposed patches) has put it.

If you're in a post type archive & are filtering by taxon, it'll fire the post type archive first. I'd expect taxon to come first in that situation.

Though rather than moving them around, perhaps making the the result filterable would be a better solution?

#6 @pento
6 years ago

  • Milestone changed from 5.0 to 5.1

#7 @pento
6 years ago

  • Milestone changed from 5.1 to Future Release

This patch needs further investigation and review.

Note: See TracTickets for help on using tickets.