From 928a972fb5cfa6e55d4bb2cf9579a9c858981da8 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 8 Mar 2014 04:18:30 +0000 Subject: [PATCH] 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 --- src/wp-admin/includes/meta-boxes.php | 2 +- src/wp-admin/includes/template.php | 2 +- src/wp-admin/includes/theme.php | 5 +++-- src/wp-includes/class-wp-theme.php | 15 +++++++++------ src/wp-includes/post.php | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/wp-admin/includes/meta-boxes.php b/src/wp-admin/includes/meta-boxes.php index 18970fdd5a..68d4611bae 100644 --- a/src/wp-admin/includes/meta-boxes.php +++ b/src/wp-admin/includes/meta-boxes.php @@ -705,7 +705,7 @@ function page_attributes_meta_box($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; ?>

diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index e0d0b7139c..80d6c9fb49 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -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. */ function page_template_dropdown( $default = '' ) { - $templates = get_page_templates(); + $templates = get_page_templates( get_post() ); ksort( $templates ); foreach ( array_keys( $templates ) as $template ) { $selected = selected( $default, $templates[ $template ], false ); diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index edfccb0ae5..9e06596ccd 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -78,10 +78,11 @@ function delete_theme($stylesheet, $redirect = '') { * * @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 */ -function get_page_templates() { - return array_flip( wp_get_theme()->get_page_templates() ); +function get_page_templates( $post = null ) { + return array_flip( wp_get_theme()->get_page_templates( $post ) ); } /** diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index 9cfe23d9e5..f383ac4f06 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -931,9 +931,10 @@ final class WP_Theme implements ArrayAccess { * @since 3.4.0 * @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. */ - 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 ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) return array(); @@ -961,7 +962,7 @@ final class WP_Theme implements ArrayAccess { } 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. @@ -970,11 +971,13 @@ final class WP_Theme implements ArrayAccess { * * @since 3.9.0 * - * @param array $page_templates Array of page templates. Keys are filenames, - * values are translated names. - * @param WP_Theme $this The theme object. + * @param array $page_templates Array of page templates. Keys are filenames, + * values are translated names. + * @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 ); } diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index a80db16165..14c02d3a4a 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -2948,7 +2948,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { if ( !empty($page_template) && 'page' == $data['post_type'] ) { $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 ( $wp_error ) return new WP_Error('invalid_page_template', __('The page template is invalid.'));