Make WordPress Core


Ignore:
Timestamp:
07/14/2020 11:54:49 AM (6 years ago)
Author:
swissspidy
Message:

Sitemaps: Exclude post types and taxonomies that are not publicly queryable.

Props Cybr.
Fixes #50607.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/sitemaps/sitemaps.php

    r48472 r48474  
    193193
    194194        /**
     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
     217        /**
    195218         * Tests getting a URL list for post type post.
    196219         */
     
    306329
    307330                $this->assertEmpty( $post_list, 'Private post types may be returned by the post provider.' );
     331        }
     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.' );
    308359        }
    309360
Note: See TracChangeset for help on using the changeset viewer.