Changeset 12923
- Timestamp:
- 02/01/2010 11:12:26 PM (15 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/classes.php
r12598 r12923 27 27 * @var array 28 28 */ 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'); 30 30 31 31 /** … … 145 145 $rewrite = $wp_rewrite->wp_rewrite_rules(); 146 146 147 if ( ! empty($rewrite)) {147 if ( ! empty($rewrite) ) { 148 148 // If we match a rewrite rule, this will be cleared. 149 149 $error = '404'; … … 204 204 // If the requesting file is the anchor of the match, prepend it 205 205 // 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) ) 207 207 $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) ) { 212 211 // Got a match. 213 212 $this->matched_rule = $match; … … 226 225 // If we're processing a 404 request, clear the error var 227 226 // since we found something. 228 if ( isset($_GET['error']))227 if ( isset($_GET['error']) ) 229 228 unset($_GET['error']); 230 229 231 if ( isset($error))230 if ( isset($error) ) 232 231 unset($error); 233 232 … … 237 236 238 237 // 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']) ) 241 240 unset($_GET['error']); 242 241 243 if ( isset($error))242 if ( isset($error) ) 244 243 unset($error); 245 244 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 ) 247 246 unset($perma_query_vars); 248 247 … … 257 256 $taxonomy_query_vars[$t->query_var] = $taxonomy; 258 257 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 ) { 260 263 $wpvar = $this->public_query_vars[$i]; 261 if ( isset($this->extra_query_vars[$wpvar]))264 if ( isset($this->extra_query_vars[$wpvar]) ) 262 265 $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar]; 263 elseif ( isset($GLOBALS[$wpvar]))266 elseif ( isset($GLOBALS[$wpvar]) ) 264 267 $this->query_vars[$wpvar] = $GLOBALS[$wpvar]; 265 elseif ( !empty($_POST[$wpvar]))268 elseif ( !empty($_POST[$wpvar]) ) 266 269 $this->query_vars[$wpvar] = $_POST[$wpvar]; 267 elseif ( !empty($_GET[$wpvar]))270 elseif ( !empty($_GET[$wpvar]) ) 268 271 $this->query_vars[$wpvar] = $_GET[$wpvar]; 269 elseif ( !empty($perma_query_vars[$wpvar]))272 elseif ( !empty($perma_query_vars[$wpvar]) ) 270 273 $this->query_vars[$wpvar] = $perma_query_vars[$wpvar]; 271 274 … … 275 278 $this->query_vars['taxonomy'] = $taxonomy_query_vars[$wpvar]; 276 279 $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]; 277 283 } 278 284 } 279 285 } 280 286 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 281 294 foreach ( (array) $this->private_query_vars as $var) { 282 if ( isset($this->extra_query_vars[$var]))295 if ( isset($this->extra_query_vars[$var]) ) 283 296 $this->query_vars[$var] = $this->extra_query_vars[$var]; 284 elseif ( isset($GLOBALS[$var]) && '' != $GLOBALS[$var])297 elseif ( isset($GLOBALS[$var]) && '' != $GLOBALS[$var] ) 285 298 $this->query_vars[$var] = $GLOBALS[$var]; 286 299 } -
trunk/wp-includes/link-template.php
r12789 r12923 105 105 if ( $post->post_type == 'page' ) 106 106 return get_page_link($post->ID, $leavename, $sample); 107 elseif ( $post->post_type == 'attachment')107 elseif ( $post->post_type == 'attachment' ) 108 108 return get_attachment_link($post->ID); 109 elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) ) 110 return get_post_link($post); 109 111 110 112 $permalink = get_option('permalink_structure'); … … 161 163 162 164 /** 165 * Retrieve the permalink for a post with a custom post type. 166 * 167 * @since 3.0.0 168 * 169 * @param int $id Optional. Post ID. 170 * @param bool $leavename Optional, defaults to false. Whether to keep post name. 171 * @param bool $sample Optional, defaults to false. Is it a sample permalink. 172 * @return string 173 */ 174 function get_post_link( $id = 0, $leavename = false, $sample = false ) { 175 global $wp_rewrite; 176 177 $post = &get_post($id); 178 179 if ( is_wp_error( $post ) ) 180 return $post; 181 182 $post_link = $wp_rewrite->get_extra_permastruct($post->post_type); 183 184 $slug = $post->post_name; 185 186 if ( !empty($post_link) && ( ( isset($post->post_status) && 'draft' != $post->post_status && 'pending' != $post->post_status ) || $sample ) ) { 187 $post_link = ( $leavename ) ? $post_link : str_replace("%$post->post_type%", $slug, $post_link); 188 $post_link = home_url( user_trailingslashit($post_link) ); 189 } else { 190 $post_type = get_post_type_object($post->post_type); 191 if ( $post_type->query_var && ( isset($post->post_status) && 'draft' != $post->post_status && 'pending' != $post->post_status ) ) 192 $post_link = "?$post_type->query_var=$slug"; 193 else 194 $post_link = "?post_type=$post->post_type&p=$post->ID"; 195 $post_link = home_url($post_link); 196 } 197 198 return apply_filters('post_type_link', $post_link, $id); 199 } 200 201 /** 163 202 * Retrieve permalink from post ID. 164 203 * -
trunk/wp-includes/post.php
r12898 r12923 17 17 function create_initial_post_types() { 18 18 register_post_type( 'post', array( 'label' => __('Posts'), 19 'publicly_queryable' => true, 19 20 'exclude_from_search' => false, 20 21 '_builtin' => true, … … 22 23 'capability_type' => 'post', 23 24 'hierarchical' => false, 25 'rewrite' => false, 26 'query_var' => false, 24 27 'supports' => array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments', 'revisions') 25 28 ) ); 26 29 27 30 register_post_type( 'page', array( 'label' => __('Pages'), 31 'publicly_queryable' => true, 28 32 'exclude_from_search' => false, 29 33 '_builtin' => true, … … 31 35 'capability_type' => 'page', 32 36 'hierarchical' => true, 37 'rewrite' => false, 38 'query_var' => false, 33 39 'supports' => array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments', 'revisions') 34 40 ) ); … … 39 45 '_edit_link' => 'media.php?attachment_id=%d', 40 46 'capability_type' => 'post', 41 'hierarchical' => false 47 'hierarchical' => false, 48 'rewrite' => false, 49 'query_var' => false, 42 50 ) ); 43 51 … … 47 55 '_edit_link' => 'revision.php?revision=%d', 48 56 'capability_type' => 'post', 49 'hierarchical' => false 57 'hierarchical' => false, 58 'rewrite' => false, 59 'query_var' => false, 50 60 ) ); 51 61 … … 687 697 * label - A descriptive name for the post type marked for translation. Defaults to $post_type. 688 698 * public - Whether posts of this type should be shown in the admin UI. Defaults to false. 689 * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true. 699 * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true if the type is not public, false if the type is public. 700 * publicly_queryable - Whether post_type queries can be performed from the front page. Defaults to whatever public is set as. 690 701 * inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none. 691 702 * capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post". … … 702 713 */ 703 714 function register_post_type($post_type, $args = array()) { 704 global $wp_post_types ;705 706 if ( !is_array($wp_post_types))715 global $wp_post_types, $wp_rewrite, $wp; 716 717 if ( !is_array($wp_post_types) ) 707 718 $wp_post_types = array(); 708 719 709 720 // Args prefixed with an underscore are reserved for internal use. 710 $defaults = array('label' => false, ' exclude_from_search' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false, 'supports' => array());721 $defaults = array('label' => false, 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array()); 711 722 $args = wp_parse_args($args, $defaults); 712 723 $args = (object) $args; … … 714 725 $post_type = sanitize_user($post_type, true); 715 726 $args->name = $post_type; 727 728 // If not set, default to the setting for public. 729 if ( null === $args->publicly_queryable ) 730 $args->publicly_queryable = $args->public; 731 732 // If not set, default to true if not public, false if public. 733 if ( null === $args->exclude_from_search ) 734 $args->exclude_from_search = !$args->public; 716 735 717 736 if ( false === $args->label ) … … 734 753 add_post_type_support($post_type, $args->supports); 735 754 unset($args->supports); 755 } 756 757 if ( false !== $args->query_var && !empty($wp) ) { 758 if ( true === $args->query_var ) 759 $args->query_var = $post_type; 760 $args->query_var = sanitize_title_with_dashes($args->query_var); 761 $wp->add_query_var($args->query_var); 762 } 763 764 if ( false !== $args->rewrite && '' != get_option('permalink_structure') ) { 765 if ( !is_array($args->rewrite) ) 766 $args->rewrite = array(); 767 if ( !isset($args->rewrite['slug']) ) 768 $args->rewrite['slug'] = $post_type; 769 if ( !isset($args->rewrite['with_front']) ) 770 $args->rewrite['with_front'] = true; 771 $wp_rewrite->add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); 772 $wp_rewrite->add_permastruct($post_type, "/{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front']); 736 773 } 737 774
Note: See TracChangeset
for help on using the changeset viewer.