Opened 3 years ago

Last modified 10 days ago

#13265 reopened enhancement

Filter results of get_page_templates()

Reported by: nathanrice Owned by: nathanrice
Priority: normal Milestone: Future Release
Component: Themes Version: 3.0
Severity: normal Keywords: has-patch
Cc: westi, nathanrice, pross@…, mikeschinkel@…, anointed, anmari@…, travis@…, alex.ciobica@…, pbaylies, pippin@…, erick@…, mercijavier@…, andyadamscp@…, stephenharris, info@…

Description

It doesn't make sense to not have a filter on the returned value of this function. I can think of several instances where this would be useful.

I also inserted a "pre_" filter at the beginning of the function so plugins/themes can short-circuit the function as well.

I'm hoping this is small enough to get in for 3.0.

Attachments (6)

theme.php.diff (653 bytes) - added by nathanrice 3 years ago.
13265.patch (834 bytes) - added by wpsmith 5 months ago.
Filter moved to WP_Theme
core-page-templates.zip (1.7 KB) - added by wpsmith 5 months ago.
Sample plugin per Nacin's request
core-page-templates.2.zip (1.7 KB) - added by wpsmith 5 months ago.
Sample plugin per Nacin's request
plugin.php (2.0 KB) - added by wpsmith 5 months ago.
test.php (540 bytes) - added by wpsmith 5 months ago.
template file for plugin.php

Download all attachments as: .zip

Change History (46)

comment:1 follow-up: ↓ 3   nacin3 years ago

  • Milestone changed from 3.0 to Future Release

There's a typo in the patch. I don't like the idea of adding filters after the feature freeze and especially once we're deep in beta because we generally don't have the time to develop the idea out to the point where we are satisfied with implementation, as we need to then account for filters in the future. Maintaining back compat is difficult, and this just makes it more so.

In this case, two tickets jump out at me for why we should not be rushing this: #12253 and #10959. Just because we return page templates doesn't mean they won't then work.

comment:2 follow-up: ↓ 4   nacin3 years ago

  • Cc nacin westi ryan removed

CC should be used so people can subscribe themselves, not so others can subscribe them (unless requested). We look at all of the tickets, we don't need the extra emails.

comment:3 in reply to: ↑ 1   nathanrice3 years ago

Replying to nacin:

There's a typo in the patch.

Indeed there was. Fixed and re-uploaded.

I don't like the idea of adding filters after the feature freeze and especially once we're deep in beta

Fair enough. I knew it was a long-shot for 3.0. Just hoped it was a small enough change to make it in. You guys know more about the larger implications than I do, so I defer to your judgment on that one.

we need to then account for filters in the future. Maintaining back compat is difficult, and this just makes it more so.

Is it just a matter of naming conventions? I've got no problem renaming the filter to something more specific like "get_page_templates" to match the function name, if that helps.

In this case, two tickets jump out at me for why we should not be rushing this: #12253 and #10959. Just because we return page templates doesn't mean they won't then work.

I don't see the relevance in #12253, but I do see some issue with #10959. But given the fact that a plugin/theme could filter, and thus control, the entire array (keys and values), assuming they do it correctly, the new page template would show up in the dropdown with the correct file location as the value (folder/file.php or folder/folder/file.php).

comment:4 in reply to: ↑ 2   nathanrice3 years ago

Replying to nacin:

CC should be used so people can subscribe themselves, not so others can subscribe them (unless requested). We look at all of the tickets, we don't need the extra emails.

Sorry, probably bad timing. I just recall westi mentioning that this was the best way to get him to take a look at a patch:
http://lists.automattic.com/pipermail/wp-hackers/2009-February/024952.html (his last sentence).

If that does still apply, I can understand why that might not necessarily be true at the moment, with 3.0 lurking.

  • Cc westi added

Sorry, probably bad timing. I just recall westi mentioning that this was the best way to get him to take a look at a patch: http://lists.automattic.com/pipermail/wp-hackers/2009-February/024952.html (his last sentence).

Fair enough. I'll re-CC westi especially since he was heavily involved in #10959, which I think could pose problems here if we ever revisit #11216. (I meant that ticket, 12253 is actually [12253], the commit in #10959.)

comment:6 follow-up: ↓ 7   westi3 years ago

This definitely needs exploration before popping a set of filters in as we are quite particular in what does work.

It would be interesting to see how you intend to use the filter from a plugin too :-)

comment:7 in reply to: ↑ 6   nathanrice3 years ago

  • Cc nathanrice added

Replying to westi:

It would be interesting to see how you intend to use the filter from a plugin too :-)

Plugins, maybe not so much :-) Though, it is theoretically possible, assuming I had access to the page templates array. Would be fun :-)

I think #14310 covers this.

Nevermind, I confused it with get_page_template().

  • Keywords has-patch added
  • Keywords page templates filter removed
  • Cc pross@… added

I'd also like to submit a request that something is done with this.. Adding static files for every page template is not ideal.

A filter here would allow page templates to be added dynamically, and would allow page template names to be changed on the fly.

comment:14 follow-ups: ↓ 17 ↓ 24   nacin2 years ago

This won't be enough to make this work. You'd also have to filter get_page_template() (via the {$type}_template filter in get_query_template(), with $type being 'page'), because the validate_file() check in get_page_template() will fail.

Selecting a special template doesn't help much when the template loader can't do anything with it.

In order to back a patch like this, it would be great seeing a plugin uploaded here that then implements something using it. That way we know we're doing it correctly. If that happens soon this is something that can make it into trunk after some review.

Ya, basically having this functionality is the only thing preventing database driven template handing.

In PageLines' framework, templates are more dynamic. Basically, it allows users to configure their own templates using the 'drag and drop' interface.

Ideally we'd be able to allow them to create and remove templates at will, then set those templates up.
Unfortunately, because of this issue; we'd have to resort to generating static files, which leads to other problems.

We will look in to doing the patch/plugin for you if needed.

  • Cc mikeschinkel@… added

comment:17 in reply to: ↑ 14   johnjamesjacoby16 months ago

Replying to nacin:

This won't be enough to make this work. You'd also have to filter get_page_template() (via the {$type}_template filter in get_query_template(), with $type being 'page'), because the validate_file() check in get_page_template() will fail.

Selecting a special template doesn't help much when the template loader can't do anything with it.

bbPress 2.0/2.1 both have functions to do everything except filter get_page_templates(). I stopped short of that, because it simply was not possible to do.

It's neigh impossible to accurately guess the mark-up needed to match a header/body/footer in a cookie-cutter page template; twentyeleven and twentyten are different enough where the same 1 page template will not work with both themes. As it stands, I'm not convinced that putting a filter on get_page_template() actually will solve the problems outlined here; maybe for parent/child themes, or for creating some kind of "theme compatibility pack" for each specific theme where functionality can be almost guaranteed.

In order to back a patch like this, it would be great seeing a plugin uploaded here that then implements something using it. That way we know we're doing it correctly. If that happens soon this is something that can make it into trunk after some review.

See: bbp-template-functions.php for the functions needed to bypass WordPress limitations.

See: bbp-template-loader.php to see how bbPress mirrors WordPress's template loader.

See: bbp-theme-compatibility.php to see how bbPress shoehorns itself into existing themes.

Even with WordPress core filters, the functions bbPress uses still need to exist; instead they would filter existing WordPress core functions that currently lack filters. The filters you mention above would make it easier for plugins to ship working templates or template parts with their new functionality without needing to write custom template loaders.

If anyone is looking to incorporate a patch for WordPress core and is unsure where to start, I'm happy to provide some direction and support.

  • Cc anointed added
  • Cc anmari@… added
  • Cc travis@… added

This would be a good addition, especially for plugins who want to add a page template for certain themes.

  • Cc alex.ciobica@… added
  • Resolution set to fixed
  • Status changed from new to closed
  • Resolution fixed deleted
  • Status changed from closed to reopened

sorry about that :)

I think this would be a very nice addition as well. We are using wordpress as a pure cms and being able to override the template list would help us greatly.

comment:24 in reply to: ↑ 14   F J Kaiser13 months ago

Replying to nacin:

In order to back a patch like this, it would be great seeing a plugin uploaded here that then implements something using it. That way we know we're doing it correctly. If that happens soon this is something that can make it into trunk after some review.

Normally, the relevance of a plugin is meassured by its downloads. BUT: Every update equals a download. Conclusion: Deliver tons of minor updates & make a plugin become relevant. (As I've seen with my own: Every update = +70% downloads).

If you want to how relevant such an issue is, then you'll have to search the support channels: Tons of Qs about it.

Version 0, edited 13 months ago by F J Kaiser (next)

comment:25 follow-up: ↓ 26   nacin13 months ago

I didn't say anything about relevance. I wanted to see a sample plugin that implemented the patch.

comment:26 in reply to: ↑ 25 ; follow-up: ↓ 27   F J Kaiser13 months ago

Replying to nacin:

I didn't say anything about relevance. I wanted to see a sample plugin that implemented the patch.

Just that I get this right: You want to know what the possible use case might be?

comment:27 in reply to: ↑ 26 ; follow-up: ↓ 28   nacin13 months ago

Replying to F J Kaiser:

Just that I get this right: You want to know what the possible use case might be?

Not even that. I want to see a plugin that successfully implements the hooks in this patch and shows the selected template on the frontend.

comment:28 in reply to: ↑ 27   F J Kaiser13 months ago

Replying to nacin:

Not even that. I want to see a plugin that successfully implements the hooks in this patch and shows the selected template on the frontend.

I know that the current patch isn't working. And I also don't know if it worked for 2.9(? - 12 month ago). The only thing I want is to not let this ticket die, as people seem to need it.

The only real problem is that you can't add templates to the meta box drop down, but as I can't find a ticket for that, I'm adding to this one. If there's a ticket for the drop-down: We don't need the current ticket.

#22566 was marked as a duplicate.

It seems this feature request is not getting attention anymore, but it's a really good one. What about its integration to core ?

  • Cc pbaylies added
  • Cc pippin@… added
  • Cc erick@… added

Filter moved to WP_Theme

Sample plugin per Nacin's request

Sample plugin per Nacin's request

template file for plugin.php

  • Cc mercijavier@… added

@wpsmith: uploading attachments doesn't trigger any email notifications, so whenever you've uploaded something, please leave a comment.

  • Cc andyadamscp@… added
  • Cc stephenharris added

I don't think the filter should be inside the WP_Theme & parent themes.

Adding the filter in the class method means a call to get_page_templates() will trigger that filter twice (potentially): once for the parent templates - and once for the child & parent templates.

It would make sense to just filter the parent & child templates in the function get_page_templates() instead.

  • Cc info@… added

#24333 was marked as a duplicate.

Note: See TracTickets for help on using tickets.