Ticket #23049: 23049.2.diff
File 23049.2.diff, 3.7 KB (added by , 7 years ago) |
---|
-
src/wp-includes/template.php
85 85 * and {@see '$type_template'} dynamic hooks, where `$type` is '404'. 86 86 * 87 87 * @since 1.5.0 88 * @since 4.9.0 The hierachy was extended to include specific templates dependent on the query. 88 89 * 89 90 * @see get_query_template() 90 91 * … … 91 92 * @return string Full path to 404 template file. 92 93 */ 93 94 function get_404_template() { 94 return get_query_template('404'); 95 $checks = array( 96 'taxonomy' => 'taxonomy-%s', 97 'attachment_id' => 'attachment', 98 'page_id' => 'page', 99 'pagename' => 'page', 100 'post_type' => 'single-%s', 101 'p' => 'single', 102 'name' => 'single', 103 'cat' => 'category', 104 'category_name' => 'category', 105 'tag' => 'tag', 106 'author' => 'author', 107 'm' => 'date', 108 'year' => 'date', 109 'monthnum' => 'date', 110 'day' => 'date', 111 ); 112 113 $templates = array(); 114 115 foreach ( $checks as $query_var => $template ) { 116 $query_val = get_query_var( $query_var ); 117 if ( ! empty( $query_val ) ) { 118 $templates[] = '404-' . sprintf( $template, $query_val ) . '.php'; 119 break; 120 } 121 } 122 123 $templates[] = '404.php'; 124 125 return get_query_template( '404', $templates ); 95 126 } 96 127 97 128 /** -
tests/phpunit/tests/template.php
41 41 42 42 public function setUp() { 43 43 parent::setUp(); 44 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 44 45 register_post_type( 'cpt', array( 45 46 'public' => true, 46 47 ) ); … … 58 59 parent::tearDown(); 59 60 } 60 61 62 /** 63 * @ticket 23049 64 */ 65 public function test_404_template_hierarchy_for_term() { 66 $url = home_url( 'taxo/not-found' ); 61 67 62 public function test_404_template_hierarchy() { 68 $this->assertTemplateHierarchy( $url, array( 69 '404-taxonomy-taxo.php', 70 '404.php', 71 ) ); 72 } 73 74 /** 75 * @ticket 23049 76 */ 77 public function test_404_template_hierarchy_for_attachment() { 63 78 $url = add_query_arg( array( 64 ' p' => '-1',79 'attachment_id' => '99999999', 65 80 ), home_url() ); 66 81 67 82 $this->assertTemplateHierarchy( $url, array( 83 '404-attachment.php', 68 84 '404.php', 69 85 ) ); 70 86 } 71 87 88 /** 89 * @ticket 23049 90 */ 91 public function test_404_template_hierarchy_for_page() { 92 $url = home_url( 'not-found' ); 93 94 $this->assertTemplateHierarchy( $url, array( 95 '404-page.php', 96 '404.php', 97 ) ); 98 } 99 100 /** 101 * @ticket 23049 102 */ 103 public function test_404_template_hierarchy_for_single_post() { 104 $url = home_url( '1984/02/25/not-found' ); 105 106 $this->assertTemplateHierarchy( $url, array( 107 '404-single.php', 108 '404.php', 109 ) ); 110 } 111 112 /** 113 * @ticket 23049 114 */ 115 public function test_404_template_hierarchy_for_single_post_type() { 116 $url = home_url( 'cpt/not-found' ); 117 118 $this->assertTemplateHierarchy( $url, array( 119 '404-single-cpt.php', 120 '404.php', 121 ) ); 122 } 123 124 /** 125 * @ticket 23049 126 */ 127 public function test_404_template_hierarchy_for_category() { 128 $url = home_url( 'category/not-found' ); 129 130 $this->assertTemplateHierarchy( $url, array( 131 '404-category.php', 132 '404.php', 133 ) ); 134 } 135 136 /** 137 * @ticket 23049 138 */ 139 public function test_404_template_hierarchy_for_tag() { 140 $url = home_url( 'tag/not-found' ); 141 142 $this->assertTemplateHierarchy( $url, array( 143 '404-tag.php', 144 '404.php', 145 ) ); 146 } 147 72 148 public function test_author_template_hierarchy() { 73 149 $author = self::factory()->user->create_and_get( array( 74 150 'user_nicename' => 'foo',