WordPress.org

Make WordPress Core

Changeset 39236


Ignore:
Timestamp:
11/15/2016 03:36:13 AM (19 months ago)
Author:
peterwilsoncc
Message:

Posts, Post Types: Improve sanitisation of templates' post types.

Prevents post type templates ignoring post types due to invalid characters. Each entry in the Template Post Type comment is run through sanitize_key() to match the sanitisation used by register_post_type().

Fixes #38766.

Location:
trunk
Files:
7 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme.php

    r39168 r39236  
    10391039
    10401040                foreach ( $types as $type ) {
    1041                     $type = trim( $type );
     1041                    $type = sanitize_key( $type );
    10421042                    if ( ! isset( $post_templates[ $type ] ) ) {
    10431043                        $post_templates[ $type ] = array();
  • trunk/tests/phpunit/tests/admin/includesTheme.php

    r39168 r39236  
    8888
    8989    /**
     90     * @ticket 38766
     91     */
     92    function test_page_templates_for_post_types_with_trailing_periods() {
     93        $theme = wp_get_theme( 'page-templates' );
     94        $this->assertNotEmpty( $theme );
     95
     96        switch_theme( $theme['Template'], $theme['Stylesheet'] );
     97
     98        $this->assertEqualSetsWithIndex( array(
     99            'No Trailing Period' => '38766/no-trailing-period-post-types.php',
     100            'Trailing Period.' => '38766/trailing-period-post-types.php',
     101            'Trailing Comma,' => '38766/trailing-comma-post-types.php',
     102            'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php',
     103            'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php',
     104            'Tilde in Post Type.' => '38766/tilde-post-types.php',
     105        ), get_page_templates( null, 'period' ) );
     106        $this->assertEqualSetsWithIndex( array(
     107            'No Trailing Period' => '38766/no-trailing-period-post-types.php',
     108            'Trailing Period.' => '38766/trailing-period-post-types.php',
     109            'Trailing Comma,' => '38766/trailing-comma-post-types.php',
     110            'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php',
     111            'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php',
     112        ), get_page_templates( null, 'full-stop' ) );
     113    }
     114
     115    /**
    90116     * @ticket 38696
    91117     */
Note: See TracChangeset for help on using the changeset viewer.