Ticket #14675: 14675.patch
File 14675.patch, 7.1 KB (added by , 14 years ago) |
---|
-
wp-includes/classes.php
287 287 288 288 // Limit publicly queried post_types to those that are publicly_queryable 289 289 if ( isset( $this->query_vars['post_type']) ) { 290 $queryable_post_types = get_post_types( array('publicly_queryable' => true) ); 291 if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) ) 292 unset( $this->query_vars['post_type'] ); 290 $queryable_post_types = get_post_types( array('publicly_queryable' => true), 'object' ); 291 if ( ! in_array( $this->query_vars['post_type'], array_keys( $queryable_post_types ) ) ){ 292 $post_type_match = false; 293 foreach( $queryable_post_types as $n => $args ){ 294 if( !empty( $args->rewrite ) && $this->query_vars['post_type'] == $args->rewrite['slug'] ){ 295 $this->query_vars['post_type'] = $n; 296 $post_type_match = true; 297 break; 298 } 299 } 300 if( ! $post_type_match ) 301 unset( $this->query_vars['post_type'] ); 302 } 293 303 } 294 304 295 305 foreach ( (array) $this->private_query_vars as $var) { -
wp-includes/link-template.php
78 78 * @return string 79 79 */ 80 80 function get_permalink($id = 0, $leavename = false) { 81 82 if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) { 83 $post = $id; 84 $sample = true; 85 } else { 86 $post = &get_post($id); 87 $sample = false; 88 } 89 90 if ( empty($post->ID) ) 91 return false; 92 81 93 $rewritecode = array( 82 94 '%year%', 83 95 '%monthnum%', … … 90 102 '%category%', 91 103 '%author%', 92 104 $leavename? '' : '%pagename%', 105 '%post_type_' . $post->post_type . '%', 106 '%' . $post->post_type . '%', 93 107 ); 94 108 95 if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) { 96 $post = $id; 97 $sample = true; 109 if ( $post->post_type == 'page' ) { 110 return get_page_link($post->ID, $leavename, $sample); 111 } elseif ( $post->post_type == 'attachment' ) { 112 return get_attachment_link($post->ID); 113 } elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) ) { 114 global $wp_rewrite; 115 $permalink = $wp_rewrite->get_extra_permastruct( $post->post_type ); 98 116 } else { 99 $post = &get_post($id); 100 $sample = false; 117 $permalink = get_option('permalink_structure'); 101 118 } 102 119 103 if ( empty($post->ID) )104 return false;105 106 if ( $post->post_type == 'page' )107 return get_page_link($post->ID, $leavename, $sample);108 elseif ( $post->post_type == 'attachment' )109 return get_attachment_link($post->ID);110 elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )111 return get_post_permalink($post->ID, $leavename, $sample);112 113 $permalink = get_option('permalink_structure');114 115 120 $permalink = apply_filters('pre_post_link', $permalink, $post, $leavename); 116 121 117 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) { 122 if ( !empty($permalink) && ( isset($post->post_status) && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) ) { 123 124 $post_type = get_post_type_object( $post->post_type ); 125 118 126 $unixtime = strtotime($post->post_date); 127 128 $post_type_slug = isset( $post_type->rewrite['slug'] ) ? $post_type->rewrite['slug'] : ''; 119 129 120 130 $category = ''; 121 if ( strpos($permalink, '%category%') !== false ) {131 if ( strpos($permalink, '%category%') !== false && is_object_in_taxonomy( $post->post_type, 'category' ) ) { 122 132 $cats = get_the_category($post->ID); 123 133 if ( $cats ) { 124 134 usort($cats, '_usort_terms_by_ID'); // order by ID … … 139 149 $authordata = get_userdata($post->post_author); 140 150 $author = $authordata->user_nicename; 141 151 } 152 153 $hierarchical_name = $post_type->hierarchical ? get_page_uri( $post->ID ) : $post->post_name; 142 154 143 155 $date = explode(" ",date('Y m d H i s', $unixtime)); 144 156 $rewritereplace = … … 154 166 $category, 155 167 $author, 156 168 $post->post_name, 169 $post_type_slug, 170 $hierarchical_name, 157 171 ); 158 172 $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) ); 159 173 $permalink = user_trailingslashit($permalink, 'single'); 160 174 } else { // if they're not using the fancy permalink option 161 $permalink = home_url('?p=' . $post->ID); 175 if( $post_type->query_var ) 176 $permalink = home_url( '?' . $post_type->query_var . '=' . $post->post_name ); 177 else 178 $permalink = home_url('?p=' . $post->ID); 162 179 } 163 180 return apply_filters('post_link', $permalink, $post, $leavename); 164 181 } -
wp-includes/post.php
866 866 $args->rewrite['slug'] = $post_type; 867 867 if ( !isset($args->rewrite['with_front']) ) 868 868 $args->rewrite['with_front'] = true; 869 $wp_rewrite->add_rewrite_tag("%post_type_$post_type%", '(' . $args->rewrite['slug'] . ')', 'post_type=' ); 869 870 if ( $args->hierarchical ) 870 871 $wp_rewrite->add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); 871 872 else 872 873 $wp_rewrite->add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); 873 $wp_rewrite->add_permastruct($post_type, " {$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask);874 $wp_rewrite->add_permastruct($post_type, "%post_type_$post_type%/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask); 874 875 } 875 876 876 877 if ( $args->register_meta_box_cb ) -
wp-includes/rewrite.php
1988 1988 unset($this->feed_structure); 1989 1989 unset($this->comment_feed_structure); 1990 1990 $this->use_trailing_slashes = ( '/' == substr($this->permalink_structure, -1, 1) ); 1991 if( !did_action( 'wp_loaded' ) ) 1992 add_action( 'wp_loaded', array( $this, 'set_post_type_rewrite_tag' ) ); 1991 1993 1992 1994 // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. 1993 1995 if ( preg_match("/^[^%]*%(?:postname|category|tag|author)%/", $this->permalink_structure) ) … … 2056 2058 $this->init(); 2057 2059 } 2058 2060 } 2061 2062 /** 2063 * 2064 * Sets the rewrite tag for custom post types 2065 * 2066 * Retrieves all publicly queryable custom post types and adds a rewrite tag 2067 * to handle their presence in the permalink. 2068 */ 2069 2070 function set_post_type_rewrite_tag(){ 2071 $queryable_post_types = get_post_types( array( 'publicly_queryable' => true, '_builtin' => false ), 'object' ); 2072 if( !empty($queryable_post_types) ){ 2073 foreach( $queryable_post_types as $name => $args ){ 2074 $queryable_post_type = empty($args->rewrite) ? $name : $args->rewrite['slug']; 2075 $this->add_rewrite_tag( '%post_type_' . $name . '%', '(' . $queryable_post_type . ')', 'post_type=' ); 2076 } 2077 } 2078 } 2059 2079 2060 2080 /** 2061 2081 * PHP4 Constructor - Calls init(), which runs setup.