Opened 10 years ago
Closed 10 years ago
#31271 closed enhancement (fixed)
Allow is_page_template() to accept an array of templates to check.
Reported by: | morganestes | Owned by: | DrewAPicture |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 4.2 |
Component: | Posts, Post Types | Keywords: | has-patch commit |
Focuses: | template | Cc: |
Description
Currently, is_page_template()
takes an optional single template name to check. This would also allow for an array of strings to check.
Before:
if ( is_page_template( 'page-one.php' ) || is_page_template( 'page-two.php' ) || is_page_template( 'page-four.php' ) ) { throw_hhg( false ); }
After:
if ( is_page_template( array( 'page-one.php' , 'page-two.php', 'page-three.php' ) ) ) { throw_hhg( true ); }
Related: #15061
Attachments (6)
Change History (17)
#1
@
10 years ago
- Keywords has-patch added
Great idea. Personally I find that useful - it would help avoiding repetitive is_page_template()
calls, making such checks shorter. I'd definitely use that often in my projects.
I've just added a patch that contains 2 unit tests for is_page_template()
with the 2 parameter types.
This ticket was mentioned in Slack in #core by johnbillion. View the logs.
10 years ago
#7
@
10 years ago
- Keywords commit removed
Seems like it would be nice to get some tests going for the default
case. Would also highly recommend wrapping in_array( 'default', $template, true ) && ! $page_template
in parens so it's clear what the grouping is, rather than trickily relying on operator precedence.
Adding a unit test for the
is_page_template()
array parameter case. Also, adding a unit test for theis_page_template()
string parameter case.