diff --git src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php
index 3ec20bf23f..5845f7eb9e 100644
|
|
|
class WP_Sitemaps_Posts extends WP_Sitemaps_Provider { |
| 37 | 37 | $post_types = get_post_types( array( 'public' => true ), 'objects' ); |
| 38 | 38 | unset( $post_types['attachment'] ); |
| 39 | 39 | |
| | 40 | $post_types = array_filter( $post_types, 'is_post_type_viewable' ); |
| | 41 | |
| 40 | 42 | /** |
| 41 | 43 | * Filters the list of post object sub types available within the sitemap. |
| 42 | 44 | * |
diff --git src/wp-includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php src/wp-includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php
index 4ee3143d63..b8ea2e94d2 100644
|
|
|
class WP_Sitemaps_Taxonomies extends WP_Sitemaps_Provider { |
| 35 | 35 | public function get_object_subtypes() { |
| 36 | 36 | $taxonomies = get_taxonomies( array( 'public' => true ), 'objects' ); |
| 37 | 37 | |
| | 38 | $taxonomies = array_filter( $taxonomies, 'is_taxonomy_viewable' ); |
| | 39 | |
| 38 | 40 | /** |
| 39 | 41 | * Filter the list of taxonomy object subtypes available within the sitemap. |
| 40 | 42 | * |
diff --git tests/phpunit/tests/sitemaps/sitemaps-taxonomies.php tests/phpunit/tests/sitemaps/sitemaps-taxonomies.php
index 044e868e74..7b1600c07c 100644
|
|
|
class Test_WP_Sitemaps_Taxonomies extends WP_UnitTestCase { |
| 142 | 142 | $this->assertEmpty( $post_list, 'Private taxonomy term links are visible.' ); |
| 143 | 143 | } |
| 144 | 144 | |
| | 145 | /** |
| | 146 | * Test getting a URL list for a custom taxonomy that is not publicly queryable. |
| | 147 | */ |
| | 148 | public function test_get_url_list_custom_taxonomy_not_publicly_queryable() { |
| | 149 | // Create a custom taxonomy for this test. |
| | 150 | $taxonomy = 'non_queryable_tax'; |
| | 151 | register_taxonomy( $taxonomy, 'post', array( 'publicly_queryable' => false ) ); |
| | 152 | |
| | 153 | // Create test terms in the custom taxonomy. |
| | 154 | $terms = self::factory()->term->create_many( 10, array( 'taxonomy' => $taxonomy ) ); |
| | 155 | |
| | 156 | // Create a test post applied to all test terms. |
| | 157 | self::factory()->post->create( array( 'tax_input' => array( $taxonomy => $terms ) ) ); |
| | 158 | |
| | 159 | $tax_provider = new WP_Sitemaps_Taxonomies(); |
| | 160 | |
| | 161 | $post_list = $tax_provider->get_url_list( 1, $taxonomy ); |
| | 162 | |
| | 163 | // Clean up. |
| | 164 | unregister_taxonomy_for_object_type( $taxonomy, 'post' ); |
| | 165 | |
| | 166 | $this->assertEmpty( $post_list, 'Private taxonomy term links are visible.' ); |
| | 167 | } |
| | 168 | |
| 145 | 169 | /** |
| 146 | 170 | * Test sitemap index entries with public and private taxonomies. |
| 147 | 171 | */ |
| … |
… |
class Test_WP_Sitemaps_Taxonomies extends WP_UnitTestCase { |
| 150 | 174 | |
| 151 | 175 | // Create a custom public and private taxonomies for this test. |
| 152 | 176 | register_taxonomy( 'public_taxonomy', 'post' ); |
| | 177 | register_taxonomy( 'non_queryable_taxonomy', 'post', array( 'publicly_queryable' => false ) ); |
| 153 | 178 | register_taxonomy( 'private_taxonomy', 'post', array( 'public' => false ) ); |
| 154 | 179 | |
| 155 | 180 | // Create test terms in the custom taxonomy. |
| 156 | | $public_term = self::factory()->term->create( array( 'taxonomy' => 'public_taxonomy' ) ); |
| 157 | | $private_term = self::factory()->term->create( array( 'taxonomy' => 'private_taxonomy' ) ); |
| | 181 | $public_term = self::factory()->term->create( array( 'taxonomy' => 'public_taxonomy' ) ); |
| | 182 | $non_queryable_term = self::factory()->term->create( array( 'taxonomy' => 'non_queryable_taxonomy' ) ); |
| | 183 | $private_term = self::factory()->term->create( array( 'taxonomy' => 'private_taxonomy' ) ); |
| 158 | 184 | |
| 159 | 185 | // Create a test post applied to all test terms. |
| 160 | 186 | self::factory()->post->create_and_get( |
| 161 | 187 | array( |
| 162 | 188 | 'tax_input' => array( |
| 163 | | 'public_taxonomy' => array( $public_term ), |
| 164 | | 'private_taxonomy' => array( $private_term ), |
| | 189 | 'public_taxonomy' => array( $public_term ), |
| | 190 | 'non_queryable_taxonomy' => array( $non_queryable_term ), |
| | 191 | 'private_taxonomy' => array( $private_term ), |
| 165 | 192 | ), |
| 166 | 193 | ) |
| 167 | 194 | ); |
| … |
… |
class Test_WP_Sitemaps_Taxonomies extends WP_UnitTestCase { |
| 171 | 198 | |
| 172 | 199 | // Clean up. |
| 173 | 200 | unregister_taxonomy_for_object_type( 'public_taxonomy', 'post' ); |
| | 201 | unregister_taxonomy_for_object_type( 'non_queryable_taxonomy', 'post' ); |
| 174 | 202 | unregister_taxonomy_for_object_type( 'private_taxonomy', 'post' ); |
| 175 | 203 | |
| 176 | 204 | $this->assertContains( 'http://' . WP_TESTS_DOMAIN . '/?sitemap=taxonomies&sitemap-subtype=public_taxonomy&paged=1', $entries, 'Public Taxonomies are not in the index.' ); |
| | 205 | $this->assertNotContains( 'http://' . WP_TESTS_DOMAIN . '/?sitemap=taxonomies&sitemap-subtype=non_queryable_taxonomy&paged=1', $entries, 'Private Taxonomies are visible in the index.' ); |
| 177 | 206 | $this->assertNotContains( 'http://' . WP_TESTS_DOMAIN . '/?sitemap=taxonomies&sitemap-subtype=private_taxonomy&paged=1', $entries, 'Private Taxonomies are visible in the index.' ); |
| 178 | 207 | } |
| 179 | 208 | |
diff --git tests/phpunit/tests/sitemaps/sitemaps.php tests/phpunit/tests/sitemaps/sitemaps.php
index 16a259c298..9d10264677 100644
|
|
|
class Test_Sitemaps extends WP_UnitTestCase { |
| 191 | 191 | $this->assertNotContains( 'http://' . WP_TESTS_DOMAIN . '/?sitemap=posts&sitemap-subtype=private_cpt&paged=1', $entries, 'Private CPTs are visible in the index.' ); |
| 192 | 192 | } |
| 193 | 193 | |
| | 194 | /** |
| | 195 | * Test sitemap index entries with public and private custom post types. |
| | 196 | * |
| | 197 | * @ticket 50607 |
| | 198 | */ |
| | 199 | public function test_get_sitemap_entries_not_publicly_queryable_post_types() { |
| | 200 | register_post_type( |
| | 201 | 'non_queryable_cpt', |
| | 202 | array( |
| | 203 | 'public' => true, |
| | 204 | 'publicly_queryable' => false, |
| | 205 | ) |
| | 206 | ); |
| | 207 | self::factory()->post->create( array( 'post_type' => 'non_queryable_cpt' ) ); |
| | 208 | |
| | 209 | $entries = wp_list_pluck( $this->_get_sitemap_entries(), 'loc' ); |
| | 210 | |
| | 211 | // Clean up. |
| | 212 | unregister_post_type( 'non_queryable_cpt' ); |
| | 213 | |
| | 214 | $this->assertNotContains( 'http://' . WP_TESTS_DOMAIN . '/?sitemap=posts&sitemap-subtype=non_queryable_cpt&paged=1', $entries, 'Non-publicly queryable CPTs are visible in the index.' ); |
| | 215 | } |
| | 216 | |
| 194 | 217 | /** |
| 195 | 218 | * Tests getting a URL list for post type post. |
| 196 | 219 | */ |
| … |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
| 307 | 330 | $this->assertEmpty( $post_list, 'Private post types may be returned by the post provider.' ); |
| 308 | 331 | } |
| 309 | 332 | |
| | 333 | /** |
| | 334 | * Tests getting a URL list for a private custom post type. |
| | 335 | * |
| | 336 | * @ticket 50607 |
| | 337 | */ |
| | 338 | public function test_get_url_list_cpt_not_publicly_queryable() { |
| | 339 | $post_type = 'non_queryable_cpt'; |
| | 340 | |
| | 341 | register_post_type( |
| | 342 | $post_type, |
| | 343 | array( |
| | 344 | 'public' => true, |
| | 345 | 'publicly_queryable' => false, |
| | 346 | ) |
| | 347 | ); |
| | 348 | |
| | 349 | self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) ); |
| | 350 | |
| | 351 | $providers = wp_get_sitemaps(); |
| | 352 | |
| | 353 | $post_list = $providers['posts']->get_url_list( 1, $post_type ); |
| | 354 | |
| | 355 | // Clean up. |
| | 356 | unregister_post_type( $post_type ); |
| | 357 | |
| | 358 | $this->assertEmpty( $post_list, 'Non-publicly queryable post types may be returned by the post provider.' ); |
| | 359 | } |
| | 360 | |
| 310 | 361 | /** |
| 311 | 362 | * Helper function for building an expected url list. |
| 312 | 363 | * |