Changeset 31754
- Timestamp:
- 03/12/2015 04:27:06 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-template.php
r31726 r31754 1630 1630 * 1631 1631 * This template tag allows you to determine if you are in a page template. 1632 * You can optionally provide a template name and then the check will be1633 * specific to that template.1632 * You can optionally provide a template name or array of template names 1633 * and then the check will be specific to that template. 1634 1634 * 1635 1635 * @since 2.5.0 1636 * 1637 * @param string $template The specific template name if specific matching is required. 1636 * @since 4.2.0 The `$template` parameter was changed to accept an array of page templates. 1637 * 1638 * @param string|array $template The specific template name or array of templates to match. 1638 1639 * @return bool True on success, false on failure. 1639 1640 */ … … 1649 1650 if ( $template == $page_template ) 1650 1651 return true; 1652 1653 if ( is_array( $template ) ) { 1654 if ( ( in_array( 'default', $template, true ) && ! $page_template ) 1655 || in_array( $page_template, $template, true ) 1656 ) { 1657 return true; 1658 } 1659 } 1651 1660 1652 1661 if ( 'default' == $template && ! $page_template ) -
trunk/tests/phpunit/tests/query/conditionals.php
r31622 r31754 961 961 $this->assertFalse( $q->is_page( $p2 ) ); 962 962 } 963 964 function test_is_page_template() { 965 $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 966 update_post_meta($post_id, '_wp_page_template', 'example.php'); 967 $this->go_to( "/?page_id=$post_id" ); 968 $this->assertTrue( is_page_template( 'example.php' ) ); 969 } 970 971 /** 972 * @ticket 31271 973 */ 974 function test_is_page_template_default() { 975 $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 976 $this->go_to( "/?page_id=$post_id" ); 977 $this->assertTrue( is_page_template( 'default' ) ); 978 $this->assertTrue( is_page_template( array( 'random', 'default' ) ) ); 979 } 980 981 /** 982 * @ticket 31271 983 */ 984 function test_is_page_template_array() { 985 $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 986 update_post_meta($post_id, '_wp_page_template', 'example.php'); 987 $this->go_to( "/?page_id=$post_id" ); 988 $this->assertFalse( is_page_template( array( 'test.php' ) ) ); 989 $this->assertTrue( is_page_template( array('test.php', 'example.php') ) ); 990 } 963 991 }
Note: See TracChangeset
for help on using the changeset viewer.