Rename the new page_templates filter to theme_page_templates, and pass it a post object for proper context.
see #13265. git-svn-id: https://develop.svn.wordpress.org/trunk@27470 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4cf6fc1a99
commit
928a972fb5
@ -705,7 +705,7 @@ function page_attributes_meta_box($post) {
|
|||||||
<?php
|
<?php
|
||||||
} // end empty pages check
|
} // end empty pages check
|
||||||
} // end hierarchical check.
|
} // end hierarchical check.
|
||||||
if ( 'page' == $post->post_type && 0 != count( get_page_templates() ) ) {
|
if ( 'page' == $post->post_type && 0 != count( get_page_templates( $post ) ) ) {
|
||||||
$template = !empty($post->page_template) ? $post->page_template : false;
|
$template = !empty($post->page_template) ? $post->page_template : false;
|
||||||
?>
|
?>
|
||||||
<p><strong><?php _e('Template') ?></strong></p>
|
<p><strong><?php _e('Template') ?></strong></p>
|
||||||
|
@ -741,7 +741,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
|
|||||||
* @param string $default Optional. The template file name. Default empty.
|
* @param string $default Optional. The template file name. Default empty.
|
||||||
*/
|
*/
|
||||||
function page_template_dropdown( $default = '' ) {
|
function page_template_dropdown( $default = '' ) {
|
||||||
$templates = get_page_templates();
|
$templates = get_page_templates( get_post() );
|
||||||
ksort( $templates );
|
ksort( $templates );
|
||||||
foreach ( array_keys( $templates ) as $template ) {
|
foreach ( array_keys( $templates ) as $template ) {
|
||||||
$selected = selected( $default, $templates[ $template ], false );
|
$selected = selected( $default, $templates[ $template ], false );
|
||||||
|
@ -78,10 +78,11 @@ function delete_theme($stylesheet, $redirect = '') {
|
|||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*
|
*
|
||||||
|
* @param WP_Post|null $post Optional. The post being edited, provided for context.
|
||||||
* @return array Key is the template name, value is the filename of the template
|
* @return array Key is the template name, value is the filename of the template
|
||||||
*/
|
*/
|
||||||
function get_page_templates() {
|
function get_page_templates( $post = null ) {
|
||||||
return array_flip( wp_get_theme()->get_page_templates() );
|
return array_flip( wp_get_theme()->get_page_templates( $post ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -931,9 +931,10 @@ final class WP_Theme implements ArrayAccess {
|
|||||||
* @since 3.4.0
|
* @since 3.4.0
|
||||||
* @access public
|
* @access public
|
||||||
*
|
*
|
||||||
|
* @param WP_Post|null $post Optional. The post being edited, provided for context.
|
||||||
* @return array Array of page templates, keyed by filename, with the value of the translated header name.
|
* @return array Array of page templates, keyed by filename, with the value of the translated header name.
|
||||||
*/
|
*/
|
||||||
public function get_page_templates() {
|
public function get_page_templates( $post = null ) {
|
||||||
// If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
|
// If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
|
||||||
if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) )
|
if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) )
|
||||||
return array();
|
return array();
|
||||||
@ -961,7 +962,7 @@ final class WP_Theme implements ArrayAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->parent() )
|
if ( $this->parent() )
|
||||||
$page_templates += $this->parent()->get_page_templates();
|
$page_templates += $this->parent()->get_page_templates( $post );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove or rename page templates for a theme.
|
* Remove or rename page templates for a theme.
|
||||||
@ -970,11 +971,13 @@ final class WP_Theme implements ArrayAccess {
|
|||||||
*
|
*
|
||||||
* @since 3.9.0
|
* @since 3.9.0
|
||||||
*
|
*
|
||||||
* @param array $page_templates Array of page templates. Keys are filenames,
|
* @param array $page_templates Array of page templates. Keys are filenames,
|
||||||
* values are translated names.
|
* values are translated names.
|
||||||
* @param WP_Theme $this The theme object.
|
* @param WP_Theme $this The theme object.
|
||||||
|
* @param WP_Post|null $post The post being edited, provided for context, or null.
|
||||||
*/
|
*/
|
||||||
$return = apply_filters( 'page_templates', $page_templates, $this );
|
error_log( serialize( $this ) );
|
||||||
|
$return = apply_filters( 'theme_page_templates', $page_templates, $this, $post );
|
||||||
return array_intersect_assoc( $return, $page_templates );
|
return array_intersect_assoc( $return, $page_templates );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2948,7 +2948,7 @@ function wp_insert_post( $postarr, $wp_error = false ) {
|
|||||||
|
|
||||||
if ( !empty($page_template) && 'page' == $data['post_type'] ) {
|
if ( !empty($page_template) && 'page' == $data['post_type'] ) {
|
||||||
$post->page_template = $page_template;
|
$post->page_template = $page_template;
|
||||||
$page_templates = wp_get_theme()->get_page_templates();
|
$page_templates = wp_get_theme()->get_page_templates( $post );
|
||||||
if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) {
|
if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) {
|
||||||
if ( $wp_error )
|
if ( $wp_error )
|
||||||
return new WP_Error('invalid_page_template', __('The page template is invalid.'));
|
return new WP_Error('invalid_page_template', __('The page template is invalid.'));
|
||||||
|
Loading…
Reference in New Issue
Block a user