Make WordPress Core

Ticket #58905: 58905.diff

File 58905.diff, 2.1 KB (added by jorbin, 20 months ago)
  • src/wp-includes/template.php

     
    704704                if ( ! $template_name ) {
    705705                        continue;
    706706                }
    707                 if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) {
    708                         $located = STYLESHEETPATH . '/' . $template_name;
     707
     708                $stylesheet      = STYLESHEETPATH . '/' . $template_name;
     709                $template        = TEMPLATEPATH . '/' . $template_name;
     710                $template_compat = ABSPATH . WPINC . '/theme-compat/' . $template_name;
     711
     712                if ( file_exists( $stylesheet ) && 0 === strpos( realpath( $stylesheet ), realpath( STYLESHEETPATH ) ) ) {
     713                        $located = $stylesheet;
    709714                        break;
    710                 } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) {
    711                         $located = TEMPLATEPATH . '/' . $template_name;
     715                } elseif ( file_exists( $template ) && 0 === strpos( realpath( $template ), realpath( TEMPLATEPATH ) ) ) {
     716                        $located = $template;
    712717                        break;
    713                 } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
    714                         $located = ABSPATH . WPINC . '/theme-compat/' . $template_name;
     718                } elseif ( file_exists( $template_compat ) && 0 === strpos( realpath( $template_compat ), realpath( ABSPATH . WPINC . '/theme-compat/' ) ) ) {
     719                        $located = $template_compat;
    715720                        break;
    716721                }
    717722        }
  • tests/phpunit/tests/template.php

     
    628628                        ),
    629629                );
    630630        }
     631        public function test_locate_template_file_outside_of_the_directory() {
     632                $template = locate_template( '../../templates/template.html', false, false );
     633                $this->assertEmpty( $template );
     634        }
    631635
     636        public function test_locate_template_file_inside_of_the_directory() {
     637                $template = locate_template( 'index.php', false, false );
     638                $this->assertNotEmpty( $template );
     639        }
     640
    632641        public function assertTemplateHierarchy( $url, array $expected, $message = '' ) {
    633642                $this->go_to( $url );
    634643                $hierarchy = $this->get_template_hierarchy();