mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@39236 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
80bd60fb88
commit
f62112fa16
@ -1038,7 +1038,7 @@ final class WP_Theme implements ArrayAccess {
|
||||
}
|
||||
|
||||
foreach ( $types as $type ) {
|
||||
$type = trim( $type );
|
||||
$type = sanitize_key( $type );
|
||||
if ( ! isset( $post_templates[ $type ] ) ) {
|
||||
$post_templates[ $type ] = array();
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
Template Name: No Trailing Period
|
||||
Template Post Type: period, full-stop
|
||||
*/
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
Template Name: Tilde in Post Type.
|
||||
Template Post Type: period, full~stop
|
||||
|
||||
This template should be applied to the `period` post type and ignored by the `full-stop` post type.
|
||||
*/
|
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
Template Name: Trailing Comma,
|
||||
Template Post Type: period, full-stop,
|
||||
*/
|
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
Template Name: Trailing Period.
|
||||
Template Post Type: period, full-stop.
|
||||
*/
|
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
Template Name: Trailing Period, White Space.
|
||||
Template Post Type: period, full-stop.
|
||||
*/
|
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
Template Name: Trailing White Space, Period.
|
||||
Template Post Type: period, full-stop .
|
||||
*/
|
@ -86,6 +86,32 @@ class Tests_Admin_includesTheme extends WP_UnitTestCase {
|
||||
$this->assertEquals( array(), get_page_templates( null, 'bar' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38766
|
||||
*/
|
||||
function test_page_templates_for_post_types_with_trailing_periods() {
|
||||
$theme = wp_get_theme( 'page-templates' );
|
||||
$this->assertNotEmpty( $theme );
|
||||
|
||||
switch_theme( $theme['Template'], $theme['Stylesheet'] );
|
||||
|
||||
$this->assertEqualSetsWithIndex( array(
|
||||
'No Trailing Period' => '38766/no-trailing-period-post-types.php',
|
||||
'Trailing Period.' => '38766/trailing-period-post-types.php',
|
||||
'Trailing Comma,' => '38766/trailing-comma-post-types.php',
|
||||
'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php',
|
||||
'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php',
|
||||
'Tilde in Post Type.' => '38766/tilde-post-types.php',
|
||||
), get_page_templates( null, 'period' ) );
|
||||
$this->assertEqualSetsWithIndex( array(
|
||||
'No Trailing Period' => '38766/no-trailing-period-post-types.php',
|
||||
'Trailing Period.' => '38766/trailing-period-post-types.php',
|
||||
'Trailing Comma,' => '38766/trailing-comma-post-types.php',
|
||||
'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php',
|
||||
'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php',
|
||||
), get_page_templates( null, 'full-stop' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38696
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user