Ticket #32322: link-template-2.diff
File link-template-2.diff, 2.5 KB (added by , 10 years ago) |
---|
-
wp-includes/link-template.php
156 156 */ 157 157 $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); 158 158 159 if ( '' != $permalink && !in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) { 159 /** 160 * Filters the list of post statuses which should use shortlinks and avoid fancy permalinks. 161 * 162 * @since 4.3.0 163 * 164 * @param array $statuses The list of statuses 165 */ 166 $statuses_which_should_shortlink = apply_filters( 'shortlink_post_statuses', array( 167 'draft', 168 'pending', 169 'auto-draft', 170 'future' 171 ) ); 172 $use_shortlink = '' === $permalink || in_array( $post->post_status, $statuses_which_should_shortlink ); 173 174 if ( $use_shortlink ) { 175 $permalink = home_url('?p=' . $post->ID); 176 } else { 160 177 $unixtime = strtotime($post->post_date); 161 178 162 179 $category = ''; … … 212 229 ); 213 230 $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) ); 214 231 $permalink = user_trailingslashit($permalink, 'single'); 215 } else { // if they're not using the fancy permalink option216 $permalink = home_url('?p=' . $post->ID);217 232 } 218 233 219 234 /** … … 254 269 255 270 $slug = $post->post_name; 256 271 257 $draft_or_pending = isset( $post->post_status ) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ); 272 $statuses_which_should_shortlink = apply_filters( 'shortlink_post_statuses', array( 273 'draft', 274 'pending', 275 'auto-draft', 276 'future' 277 ) ); 278 $status_should_shortlink = isset( $post->post_status ) && in_array( $post->post_status, $statuses_which_should_shortlink ); 258 279 259 280 $post_type = get_post_type_object($post->post_type); 260 281 … … 262 283 $slug = get_page_uri( $id ); 263 284 } 264 285 265 if ( !empty($post_link) && ( !$ draft_or_pending|| $sample ) ) {286 if ( !empty($post_link) && ( !$status_should_shortlink || $sample ) ) { 266 287 if ( ! $leavename ) { 267 288 $post_link = str_replace("%$post->post_type%", $slug, $post_link); 268 289 } 269 290 $post_link = home_url( user_trailingslashit($post_link) ); 270 291 } else { 271 if ( $post_type->query_var && ( isset($post->post_status) && !$ draft_or_pending) )292 if ( $post_type->query_var && ( isset($post->post_status) && !$status_should_shortlink ) ) 272 293 $post_link = add_query_arg($post_type->query_var, $slug, ''); 273 294 else 274 295 $post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');