Ticket #14675: patch.patch
| File patch.patch, 7.0 KB (added by johnpbloch, 3 years ago) |
|---|
-
wp-includes/post.php
870 870 $wp_rewrite->add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); 871 871 else 872 872 $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);873 $wp_rewrite->add_permastruct($post_type, "%post_type%/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask); 874 874 } 875 875 876 876 if ( $args->register_meta_box_cb ) -
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%', 106 $leavename? '' : '%'.$post->post_type.'%', 93 107 ); 94 95 if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) { 96 $post = $id; 97 $sample = true; 108 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 } 119 $post_type = get_post_type_object( $post->post_type ); 102 120 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 121 $permalink = apply_filters('pre_post_link', $permalink, $post, $leavename); 116 122 117 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {123 if ( !empty($permalink) && ( isset($post->post_status) && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) ) { 118 124 $unixtime = strtotime($post->post_date); 125 126 $post_type_slug = isset( $post_type->rewrite['slug'] ) ? $post_type->rewrite['slug'] : ''; 119 127 120 128 $category = ''; 121 if ( strpos($permalink, '%category%') !== false ) {129 if ( strpos($permalink, '%category%') !== false && is_object_in_taxonomy( $post->post_type, 'category' ) ) { 122 130 $cats = get_the_category($post->ID); 123 131 if ( $cats ) { 124 132 usort($cats, '_usort_terms_by_ID'); // order by ID … … 139 147 $authordata = get_userdata($post->post_author); 140 148 $author = $authordata->user_nicename; 141 149 } 150 151 $hierarchical_name = $post_type->hierarchical ? get_page_uri( $post->ID ) : $post->post_name; 142 152 143 153 $date = explode(" ",date('Y m d H i s', $unixtime)); 144 154 $rewritereplace = … … 154 164 $category, 155 165 $author, 156 166 $post->post_name, 167 $post_type_slug, 168 $hierarchical_name, 157 169 ); 158 170 $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) ); 159 171 $permalink = user_trailingslashit($permalink, 'single'); 160 172 } else { // if they're not using the fancy permalink option 161 $permalink = home_url('?p=' . $post->ID); 173 if ( $post_type->query_var && ( isset($post->post_status) && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) ) 174 $permalink = home_url( '?' . $post_type->query_var . '=' . $post->post_name ); 175 else 176 $permalink = home_url('?p=' . $post->ID); 162 177 } 163 178 return apply_filters('post_link', $permalink, $post, $leavename); 164 179 } -
wp-includes/rewrite.php
1979 1979 unset($this->feed_structure); 1980 1980 unset($this->comment_feed_structure); 1981 1981 $this->use_trailing_slashes = ( '/' == substr($this->permalink_structure, -1, 1) ); 1982 if( !did_action( 'wp_loaded' ) ) 1983 add_action( 'wp_loaded', array( $this, 'set_post_type_rewrite_tag' ) ); 1982 1984 1983 1985 // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. 1984 1986 if ( preg_match("/^[^%]*%(?:postname|category|tag|author)%/", $this->permalink_structure) ) … … 2047 2049 $this->init(); 2048 2050 } 2049 2051 } 2052 2053 /** 2054 * Sets the rewrite tag for 'post type' 2055 * 2056 * Retrieves all publicly queryable custom post types and adds a rewrite tag 2057 * to handle their presence in the permalink. 2058 * 2059 * @since 3.1 2060 * @access public 2061 */ 2062 2063 function set_post_type_rewrite_tag(){ 2064 $queryable_post_types = get_post_types( array( 'publicly_queryable' => true, '_builtin' => false ), 'object' ); 2065 if( !empty($queryable_post_types) ){ 2066 foreach( $queryable_post_types as $name => $args ) 2067 $queryable_post_types[$name] = empty($args->rewrite) ? $name : $args->rewrite['slug']; 2068 } 2069 $this->add_rewrite_tag( '%post_type%', '('.implode('|',$queryable_post_types).')', 'post_type=' ); 2070 } 2050 2071 2051 2072 /** 2052 2073 * PHP4 Constructor - Calls init(), which runs setup. -
wp-includes/classes.php
285 285 } 286 286 } 287 287 288 // Limit publicly queried post_types to those that are publicly_queryable 288 /* Limit publicly queried post_types to those that are publicly_queryable, taking into account 289 the post type's name may not be the same as its rewrite slug */ 289 290 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'] ); 291 $queryable_post_types = get_post_types( array('publicly_queryable' => true), 'object' ); 292 if ( ! in_array( $this->query_vars['post_type'], array_keys( $queryable_post_types ) ) ){ 293 foreach( $queryable_post_types as $n => $args ) 294 if( !empty($args->rewrite) && $this->query_vars['post_type'] == $args->rewrite['slug'] ){ $this->query_vars['post_type'] = $n; } 295 if( ! in_array( $this->query_vars['post_type'], array_keys( $queryable_post_types ) ) ) 296 unset( $this->query_vars['post_type'] ); 297 } 293 298 } 294 299 295 300 foreach ( (array) $this->private_query_vars as $var) {
