Make WordPress Core


Ignore:
Timestamp:
02/01/2010 11:12:26 PM (17 years ago)
Author:
ryan
Message:

Permalinks for custom post types. Props prettyboymp. see #9674

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/classes.php

    r12598 r12923  
    2727         * @var array
    2828         */
    29         var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage');
     29        var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');
    3030
    3131        /**
     
    145145                $rewrite = $wp_rewrite->wp_rewrite_rules();
    146146
    147                 if (! empty($rewrite)) {
     147                if ( ! empty($rewrite) ) {
    148148                        // If we match a rewrite rule, this will be cleared.
    149149                        $error = '404';
     
    204204                                // If the requesting file is the anchor of the match, prepend it
    205205                                // to the path info.
    206                                 if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request)) {
     206                                if ( (! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request) )
    207207                                        $request_match = $req_uri . '/' . $request;
    208                                 }
    209 
    210                                 if (preg_match("#^$match#", $request_match, $matches) ||
    211                                         preg_match("#^$match#", urldecode($request_match), $matches)) {
     208
     209                                if ( preg_match("#^$match#", $request_match, $matches) ||
     210                                        preg_match("#^$match#", urldecode($request_match), $matches) ) {
    212211                                        // Got a match.
    213212                                        $this->matched_rule = $match;
     
    226225                                        // If we're processing a 404 request, clear the error var
    227226                                        // since we found something.
    228                                         if (isset($_GET['error']))
     227                                        if ( isset($_GET['error']) )
    229228                                                unset($_GET['error']);
    230229
    231                                         if (isset($error))
     230                                        if ( isset($error) )
    232231                                                unset($error);
    233232
     
    237236
    238237                        // If req_uri is empty or if it is a request for ourself, unset error.
    239                         if (empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
    240                                 if (isset($_GET['error']))
     238                        if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
     239                                if ( isset($_GET['error']) )
    241240                                        unset($_GET['error']);
    242241
    243                                 if (isset($error))
     242                                if ( isset($error) )
    244243                                        unset($error);
    245244
    246                                 if (isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false)
     245                                if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
    247246                                        unset($perma_query_vars);
    248247
     
    257256                                $taxonomy_query_vars[$t->query_var] = $taxonomy;
    258257
    259                 for ($i=0; $i<count($this->public_query_vars); $i += 1) {
     258                foreach ( $GLOBALS['wp_post_types'] as $post_type => $t )
     259                        if ( $t->query_var )
     260                                $post_type_query_vars[$t->query_var] = $post_type;
     261
     262                for ( $i = 0; $i < count($this->public_query_vars); $i += 1 ) {
    260263                        $wpvar = $this->public_query_vars[$i];
    261                         if (isset($this->extra_query_vars[$wpvar]))
     264                        if ( isset($this->extra_query_vars[$wpvar]) )
    262265                                $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
    263                         elseif (isset($GLOBALS[$wpvar]))
     266                        elseif ( isset($GLOBALS[$wpvar]) )
    264267                                $this->query_vars[$wpvar] = $GLOBALS[$wpvar];
    265                         elseif (!empty($_POST[$wpvar]))
     268                        elseif ( !empty($_POST[$wpvar]) )
    266269                                $this->query_vars[$wpvar] = $_POST[$wpvar];
    267                         elseif (!empty($_GET[$wpvar]))
     270                        elseif ( !empty($_GET[$wpvar]) )
    268271                                $this->query_vars[$wpvar] = $_GET[$wpvar];
    269                         elseif (!empty($perma_query_vars[$wpvar]))
     272                        elseif ( !empty($perma_query_vars[$wpvar]) )
    270273                                $this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
    271274
     
    275278                                        $this->query_vars['taxonomy'] = $taxonomy_query_vars[$wpvar];
    276279                                        $this->query_vars['term'] = $this->query_vars[$wpvar];
     280                                } elseif ( in_array( $wpvar, $post_type_query_vars ) ) {
     281                                        $this->query_vars['post_type'] = $post_type_query_vars[$wpvar];
     282                                        $this->query_vars['name'] = $this->query_vars[$wpvar];
    277283                                }
    278284                        }
    279285                }
    280286
     287                // Limit publicly queried post_types to those that are publicly_queryable
     288                if ( isset( $this->query_vars['post_type']) ) {
     289                        $queryable_post_types =  get_post_types( array('publicly_queryable' => true) );
     290                        if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) )
     291                                unset( $this->query_vars['post_type'] );
     292                }
     293
    281294                foreach ( (array) $this->private_query_vars as $var) {
    282                         if (isset($this->extra_query_vars[$var]))
     295                        if ( isset($this->extra_query_vars[$var]) )
    283296                                $this->query_vars[$var] = $this->extra_query_vars[$var];
    284                         elseif (isset($GLOBALS[$var]) && '' != $GLOBALS[$var])
     297                        elseif ( isset($GLOBALS[$var]) && '' != $GLOBALS[$var] )
    285298                                $this->query_vars[$var] = $GLOBALS[$var];
    286299                }
Note: See TracChangeset for help on using the changeset viewer.