WordPress.org

Make WordPress Core

Ticket #13265: 13265.diff

File 13265.diff, 4.2 KB (added by nacin, 7 years ago)

Add post context to the filter.

  • wp-admin/includes/meta-boxes.php

     
    705705<?php
    706706                } // end empty pages check
    707707        } // end hierarchical check.
    708         if ( 'page' == $post->post_type && 0 != count( get_page_templates() ) ) {
     708        if ( 'page' == $post->post_type && 0 != count( get_page_templates( $post ) ) ) {
    709709                $template = !empty($post->page_template) ? $post->page_template : false;
    710710                ?>
    711711<p><strong><?php _e('Template') ?></strong></p>
  • wp-admin/includes/template.php

     
    741741 * @param string $default Optional. The template file name. Default empty.
    742742 */
    743743function page_template_dropdown( $default = '' ) {
    744         $templates = get_page_templates();
     744        $templates = get_page_templates( get_post() );
    745745        ksort( $templates );
    746746        foreach ( array_keys( $templates ) as $template ) {
    747747                $selected = selected( $default, $templates[ $template ], false );
  • wp-admin/includes/theme.php

     
    7878 *
    7979 * @since 1.5.0
    8080 *
     81 * @param WP_Post|null $post Optional. The post being edited, provided for context.
    8182 * @return array Key is the template name, value is the filename of the template
    8283 */
    83 function get_page_templates() {
    84         return array_flip( wp_get_theme()->get_page_templates() );
     84function get_page_templates( $post = null ) {
     85        return array_flip( wp_get_theme()->get_page_templates( $post ) );
    8586}
    8687
    8788/**
  • wp-includes/class-wp-theme.php

     
    931931         * @since 3.4.0
    932932         * @access public
    933933         *
     934         * @param WP_Post|null $post Optional. The post being edited, provided for context.
    934935         * @return array Array of page templates, keyed by filename, with the value of the translated header name.
    935936         */
    936         public function get_page_templates() {
     937        public function get_page_templates( $post = null ) {
    937938                // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
    938939                if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) )
    939940                        return array();
     
    961962                }
    962963
    963964                if ( $this->parent() )
    964                         $page_templates += $this->parent()->get_page_templates();
     965                        $page_templates += $this->parent()->get_page_templates( $post );
    965966
    966967                /**
    967968                 * Remove or rename page templates for a theme.
     
    970971                 *
    971972                 * @since 3.9.0
    972973                 *
    973                  * @param array    $page_templates Array of page templates. Keys are filenames,
    974                  *                                 values are translated names.
    975                  * @param WP_Theme $this           The theme object.
     974                 * @param array        $page_templates Array of page templates. Keys are filenames,
     975                 *                                     values are translated names.
     976                 * @param WP_Theme     $this           The theme object.
     977                 * @param WP_Post|null $post           The post being edited, provided for context, or null.
    976978                 */
    977                 $return = apply_filters( 'page_templates', $page_templates, $this );
     979                $return = apply_filters( 'page_templates', $page_templates, $this, $post );
    978980                return array_intersect_assoc( $return, $page_templates );
    979981        }
    980982
  • wp-includes/post.php

     
    29482948
    29492949        if ( !empty($page_template) && 'page' == $data['post_type'] ) {
    29502950                $post->page_template = $page_template;
    2951                 $page_templates = wp_get_theme()->get_page_templates();
     2951                $page_templates = wp_get_theme()->get_page_templates( $post );
    29522952                if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) {
    29532953                        if ( $wp_error )
    29542954                                return new WP_Error('invalid_page_template', __('The page template is invalid.'));