Make WordPress Core

Ticket #31271: 31271.2.diff

File 31271.2.diff, 2.3 KB (added by DrewAPicture, 10 years ago)

docs fixes

  • src/wp-includes/post-template.php

     
    16291629 * Whether currently in a page template.
    16301630 *
    16311631 * 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 be
    1633  * 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.
    16341634 *
    16351635 * @since 2.5.0
     1636 * @since 4.2.0 The `$template` parameter was changed to accept an array of page templates.
    16361637 *
    1637  * @param string $template The specific template name if specific matching is required.
     1638 * @param string|array $template The specific template name or array of templates to match.
    16381639 * @return bool True on success, false on failure.
    16391640 */
    16401641function is_page_template( $template = '' ) {
     
    16481649
    16491650        if ( $template == $page_template )
    16501651                return true;
     1652       
     1653        if ( is_array( $template ) && in_array( $page_template, $template ) ) {
     1654                return true;
     1655        }
    16511656
    16521657        if ( 'default' == $template && ! $page_template )
    16531658                return true;
  • tests/phpunit/tests/query/conditionals.php

     
    960960                $this->assertFalse( $q->is_page( $p2_name ) );
    961961                $this->assertFalse( $q->is_page( $p2 ) );
    962962        }
     963
     964        /**
     965         * @ticket 31271
     966         */
     967        function test_is_page_template() {
     968                $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     969                update_post_meta($post_id, '_wp_page_template', 'example.php');
     970                $this->go_to( "/?page_id=$post_id" );
     971                $this->assertTrue( is_page_template('example.php') );
     972        }
     973
     974        /**
     975         * @ticket 31271
     976         */
     977        function test_is_page_template_array() {
     978                $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     979                update_post_meta($post_id, '_wp_page_template', 'example.php');
     980                $this->go_to( "/?page_id=$post_id" );
     981                $this->assertTrue( is_page_template( array('test.php', 'example.php') ) );
     982                $this->assertFalse( is_page_template( array('test.php') ) );
     983        }
    963984}