Make WordPress Core

Opened 7 years ago

Closed 2 years ago

#41737 closed enhancement (wontfix)

Possibly redundant template files in the hierarchy

Reported by: danburzo's profile danburzo Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords: close
Focuses: template Cc:

Description

Hi,

As I'm building https://forklor.github.io/wp-template-hierarchy/ (still a work in progress) and sifting through the source code, it looks like the following template files in the hierarchy may be redundant:

  1. ${subtype}.php for attachments — is there a need for a template for a subtype without its associated ${mime_type}? Is there a use-case am I missing where a subtype may be associated with different mime types?
  1. attachment.php can be caught in single-attachment.php.

For the sake of simplifying WP's API surface, I am proposing deprecating these templates in a future version.

And as a related question (let me know if I should open a separate issue), to preserve symmetry with other post types and and pages, should a Custom Post Template set for an attachment not get priority before the other attachment templates?

(Please let me know if I misunderstood anything!)

Change History (4)

#1 @danburzo
7 years ago

For convenience, here's where the relevant code is located:

And a few related issues I found:

  • attachment.php is too high in priority: #38160
  • attachment.php is usually missing in themes: #41461
  • attachment uploaded to Page goes on to page.php instead of single-....php: #33017

In regards to Custom Post Templates to apply to single attachments, posts, and pages, maybe have a get_custom_template() method in template.php that gets called in template-loader.php before is_attachment() / is_single() / is_page()?


On the topic of deprecation, I salute the demise of paged.php — I could not wrap my head around how to use it :P.

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

#2 @SergeyBiryukov
7 years ago

  • Component changed from General to Themes

#3 in reply to: ↑ description ; follow-up: @johnbillion
7 years ago

  • Keywords close added
  • Version trunk deleted

Replying to danburzo:

Is there a use-case am I missing where a subtype may be associated with different mime types?

It's rare, but yes this does happen. Mime types for Ogg files work like this, with video/ogg and audio/ogg.

attachment.php can be caught in single-attachment.php.

Yeah, the attachment template hierarchy has gotten a bit messed up. Deprecating or removing this doesn't provide much benefit, so I'd be hesitant to deprecate it.

See #38160 for more attachment template hierarchy weirdness.

#4 in reply to: ↑ 3 @hellofromTonya
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I agree with johnbillion's hesitation:

Yeah, the attachment template hierarchy has gotten a bit messed up. Deprecating or removing this doesn't provide much benefit, so I'd be hesitant to deprecate it.

as well as John's reasoning for closing #38160:

It would be nice to fix this but there's no sign of any demand for it.

I too think there's not enough benefits to outweigh the impacts of deprecating. If however enough benefits do surface, this could be reopened for consideration.

Thank you @danburzo for opening this ticket and contributing!

Note: See TracTickets for help on using tickets.