WordPress.org

Make WordPress Core

Changeset 34215


Ignore:
Timestamp:
09/15/2015 06:53:12 PM (5 years ago)
Author:
wonderboymusic
Message:

In WP::parse_request(), don't add query vars of non-viewable post types to WP::public_query_vars. In register_post_type(), don't add query vars of non-viewable post types to WP::public_query_vars.
In _unregister_post_type() (unit tests), don't add query vars of non-viewable post types to WP::public_query_vars.

Adds unit test.

Fixes #30018.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp.php

    r33734 r34215  
    262262        $this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );
    263263
    264         foreach ( get_post_types( array(), 'objects' ) as $post_type => $t )
    265             if ( $t->query_var )
     264        foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) {
     265            if ( is_post_type_viewable( $t ) && $t->query_var ) {
    266266                $post_type_query_vars[$t->query_var] = $post_type;
     267            }
     268        }
    267269
    268270        foreach ( $this->public_query_vars as $wpvar ) {
  • trunk/src/wp-includes/post-functions.php

    r34201 r34215  
    10731073    }
    10741074
    1075     if ( false !== $args->query_var && ! empty( $wp ) ) {
     1075    if ( false !== $args->query_var ) {
    10761076        if ( true === $args->query_var )
    10771077            $args->query_var = $post_type;
    10781078        else
    10791079            $args->query_var = sanitize_title_with_dashes( $args->query_var );
    1080         $wp->add_query_var( $args->query_var );
     1080
     1081        if ( $wp && is_post_type_viewable( $args ) ) {
     1082            $wp->add_query_var( $args->query_var );
     1083        }
    10811084    }
    10821085
  • trunk/tests/phpunit/includes/utils.php

    r33123 r34215  
    363363
    364364    foreach ( get_post_types( array() , 'objects' ) as $t ) {
    365         if ( ! empty( $t->query_var ) )
     365        if ( is_post_type_viewable( $t ) && ! empty( $t->query_var ) )
    366366            $GLOBALS['wp']->add_query_var( $t->query_var );
    367367    }
  • trunk/tests/phpunit/tests/rewrite.php

    r32918 r34215  
    145145    }
    146146
     147    /**
     148     * @ticket 30018
     149     */
     150    function test_parse_request_home_path_non_public_type() {
     151        register_post_type( 'foo', array( 'public' => false ) );
     152
     153        $url = add_query_arg( 'foo', '1', home_url() );
     154
     155        $this->go_to( $url );
     156
     157        _unregister_post_type( 'foo' );
     158
     159        $this->assertEquals( array(), $GLOBALS['wp']->query_vars );
     160    }
     161
    147162    function test_url_to_postid_dupe_path() {
    148163        update_option( 'home', home_url('/example/') );
Note: See TracChangeset for help on using the changeset viewer.