Ticket #46283: archive-slug-filters-with-test.patch
File archive-slug-filters-with-test.patch, 3.4 KB (added by , 6 years ago) |
---|
-
src/wp-includes/class-wp-post-type.php
551 551 $archive_slug = $wp_rewrite->root . $archive_slug; 552 552 } 553 553 554 add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$this->name", 'top' ); 554 $archive_slug = apply_filters( 'post_type_archive_slug', $archive_slug, $this->name, $this ); 555 556 add_rewrite_rule( "{$archive_slug}/?$", apply_filters( 'post_type_archive_rewrite_query', "index.php?post_type=$this->name", $archive_slug, $this->name, $this ), 'top' ); 555 557 if ( $this->rewrite['feeds'] && $wp_rewrite->feeds ) { 556 558 $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; 557 add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );558 add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );559 add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", apply_filters( 'post_type_archive_rewrite_feed_query', "index.php?post_type=$this->name" . '&feed=$matches[1]', $archive_slug, $this->name, $this, $feeds ), 'top' ); 560 add_rewrite_rule( "{$archive_slug}/$feeds/?$", apply_filters( 'post_type_archive_rewrite_feed_root_query', "index.php?post_type=$this->name" . '&feed=$matches[1]', $archive_slug, $this->name, $this, $feeds ), 'top' ); 559 561 } 560 562 if ( $this->rewrite['pages'] ) { 561 add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$this->name" . '&paged=$matches[1]', 'top' );563 add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", apply_filters( 'post_type_archive_rewrite_pagination_query', "index.php?post_type=$this->name" . '&paged=$matches[1]', $archive_slug, $this->name, $this ), 'top' ); 562 564 } 563 565 } 564 566 -
tests/phpunit/tests/post/wpPostType.php
132 132 $this->assertFalse( array_search( "%$post_type%", $rewrite_tags_after ) ); 133 133 } 134 134 135 public function test_adds_rewrite_rules_with_filtered_archive_slug() { 136 $this->set_permalink_structure( '/%postname%' ); 137 138 /* @var WP_Rewrite $wp_rewrite */ 139 global $wp_rewrite; 140 141 $original_slug = 'unfiltered-archive-slug'; 142 $new_archive_slug = 'filtered-archive-slug'; 143 144 add_filter( 145 'post_type_archive_slug', 146 function() use ( $new_archive_slug ) { 147 return $new_archive_slug; 148 } 149 ); 150 151 $post_type = 'cpt'; 152 $post_type_object = new WP_Post_Type( 153 $post_type, 154 array( 155 'public' => true, 156 'has_archive' => true, 157 'rewrite' => array( 158 'slug' => $original_slug, 159 ), 160 ) 161 ); 162 163 $post_type_object->add_rewrite_rules(); 164 $wp_rewrite->flush_rules(); 165 $rewrite_rules = $wp_rewrite->rules; 166 167 $this->assertNotFalse( array_key_exists( "{$new_archive_slug}/?$", $rewrite_rules ) ); 168 $this->assertFalse( array_key_exists( "{$original_slug}/?$", $rewrite_rules ) ); 169 } 170 135 171 public function test_register_meta_boxes() { 136 172 $post_type = 'cpt'; 137 173 $post_type_object = new WP_Post_Type( $post_type, array( 'register_meta_box_cb' => '__return_false' ) );