Make WordPress Core

Opened 2 years ago

Last modified 27 hours ago

#25879 new enhancement

Add filter to page_template_dropdown()

Reported by: meloniq Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.8
Component: Posts, Post Types Keywords: has-patch
Focuses: template Cc:


page_template_dropdown() is used in 'Page Attributes' metabox to list available page templates. The filter hook will give ability to adjust what's displayed in this box.

Our issue:
We use many custom templates to perform some specific tasks like building frontend dashboards, submit/edit forms, login pages, etc.
As far it works well, but the 'Page Attributes' metabox fulfill with page templates that in most of cases are not intended for any other use, and some administrators get confused seeing full list of available templates while creating a new page.

Attachments (4)

25879.patch (1.2 KB) - added by meloniq 2 years ago.
Adds 'page_template_dropdown' filter
25879-2.patch (526 bytes) - added by meloniq 2 years ago.
Adds 'page_template_dropdown' filter (without selected() and docs changes)
25879-3.patch (760 bytes) - added by meloniq 2 years ago.
Renamed filter to 'page_template_dropdown_items', added inline filter doc
25879.diff (865 bytes) - added by iamfriendly 27 hours ago.
Refreshed the patch

Download all attachments as: .zip

Change History (15)

@meloniq2 years ago

Adds 'page_template_dropdown' filter

comment:1 @meloniq2 years ago

  • Cc meloniq@… added

comment:2 @SergeyBiryukov2 years ago

Appears to be a duplicate of #13265 and #21891.

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

comment:3 @SergeyBiryukov2 years ago

The move to selected() looks good though, touch_time() and parent_dropdown() would benefit from that as well. I'd suggest creating a new ticket for that.

comment:4 @meloniq2 years ago

Created separate ticket for the selected() use, and documenting this functions, see: #25889

Referenced tickets touches similar item (filtering page templates) but on lower level, using that filter to change items in dropdown could cause unexpected issues, as it will remove templates from all places, and not only from mentioned dropdown.

@meloniq2 years ago

Adds 'page_template_dropdown' filter (without selected() and docs changes)

comment:5 @SergeyBiryukov2 years ago

  • Milestone changed from Awaiting Review to 3.8

My only concern with 'page_template_dropdown' filter name is that filters of the same name as the function are generally used to filter the actual result of that function. I'd suggest 'page_template_dropdown_items'.

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

@meloniq2 years ago

Renamed filter to 'page_template_dropdown_items', added inline filter doc

comment:7 @emzo23 months ago

  • Cc wordpress@… added

comment:8 @nacin23 months ago

  • Keywords 3.9-early added
  • Milestone changed from 3.8 to Future Release

comment:9 @nacin20 months ago

  • Component changed from Template to Posts, Post Types
  • Focuses template added

comment:10 @chriscct732 hours ago

  • Keywords needs-refresh added; 3.9-early removed

@iamfriendly27 hours ago

Refreshed the patch

comment:11 @iamfriendly27 hours ago

  • Keywords needs-refresh removed

Refreshed the patch as the function has moved locations to template-functions.php and also updated the docs to reflect this would be for 4.4.0

Note: See TracTickets for help on using tickets.