Make WordPress Core

Ticket #50607: 50607.diff

File 50607.diff, 7.0 KB (added by swissspidy, 6 years ago)
  • src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php

    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 { 
    3737                $post_types = get_post_types( array( 'public' => true ), 'objects' );
    3838                unset( $post_types['attachment'] );
    3939
     40                $post_types = array_filter( $post_types, 'is_post_type_viewable' );
     41
    4042                /**
    4143                 * Filters the list of post object sub types available within the sitemap.
    4244                 *
  • src/wp-includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php

    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 { 
    3535        public function get_object_subtypes() {
    3636                $taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
    3737
     38                $taxonomies = array_filter( $taxonomies, 'is_taxonomy_viewable' );
     39
    3840                /**
    3941                 * Filter the list of taxonomy object subtypes available within the sitemap.
    4042                 *
  • tests/phpunit/tests/sitemaps/sitemaps-taxonomies.php

    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 { 
    142142                $this->assertEmpty( $post_list, 'Private taxonomy term links are visible.' );
    143143        }
    144144
     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
    145169        /**
    146170         * Test sitemap index entries with public and private taxonomies.
    147171         */
    class Test_WP_Sitemaps_Taxonomies extends WP_UnitTestCase { 
    150174
    151175                // Create a custom public and private taxonomies for this test.
    152176                register_taxonomy( 'public_taxonomy', 'post' );
     177                register_taxonomy( 'non_queryable_taxonomy', 'post', array( 'publicly_queryable' => false ) );
    153178                register_taxonomy( 'private_taxonomy', 'post', array( 'public' => false ) );
    154179
    155180                // 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' ) );
    158184
    159185                // Create a test post applied to all test terms.
    160186                self::factory()->post->create_and_get(
    161187                        array(
    162188                                '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 ),
    165192                                ),
    166193                        )
    167194                );
    class Test_WP_Sitemaps_Taxonomies extends WP_UnitTestCase { 
    171198
    172199                // Clean up.
    173200                unregister_taxonomy_for_object_type( 'public_taxonomy', 'post' );
     201                unregister_taxonomy_for_object_type( 'non_queryable_taxonomy', 'post' );
    174202                unregister_taxonomy_for_object_type( 'private_taxonomy', 'post' );
    175203
    176204                $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.' );
    177206                $this->assertNotContains( 'http://' . WP_TESTS_DOMAIN . '/?sitemap=taxonomies&sitemap-subtype=private_taxonomy&paged=1', $entries, 'Private Taxonomies are visible in the index.' );
    178207        }
    179208
  • tests/phpunit/tests/sitemaps/sitemaps.php

    diff --git tests/phpunit/tests/sitemaps/sitemaps.php tests/phpunit/tests/sitemaps/sitemaps.php
    index 16a259c298..9d10264677 100644
    class Test_Sitemaps extends WP_UnitTestCase { 
    191191                $this->assertNotContains( 'http://' . WP_TESTS_DOMAIN . '/?sitemap=posts&sitemap-subtype=private_cpt&paged=1', $entries, 'Private CPTs are visible in the index.' );
    192192        }
    193193
     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
    194217        /**
    195218         * Tests getting a URL list for post type post.
    196219         */
    class Test_Sitemaps extends WP_UnitTestCase { 
    307330                $this->assertEmpty( $post_list, 'Private post types may be returned by the post provider.' );
    308331        }
    309332
     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
    310361        /**
    311362         * Helper function for building an expected url list.
    312363         *