Make WordPress Core

Ticket #32322: link-template-2.diff

File link-template-2.diff, 2.5 KB (added by kdoole, 10 years ago)
  • wp-includes/link-template.php

     
    156156         */
    157157        $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
    158158
    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 {
    160177                $unixtime = strtotime($post->post_date);
    161178
    162179                $category = '';
     
    212229                );
    213230                $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) );
    214231                $permalink = user_trailingslashit($permalink, 'single');
    215         } else { // if they're not using the fancy permalink option
    216                 $permalink = home_url('?p=' . $post->ID);
    217232        }
    218233
    219234        /**
     
    254269
    255270        $slug = $post->post_name;
    256271
    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 );
    258279
    259280        $post_type = get_post_type_object($post->post_type);
    260281
     
    262283                $slug = get_page_uri( $id );
    263284        }
    264285
    265         if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
     286        if ( !empty($post_link) && ( !$status_should_shortlink || $sample ) ) {
    266287                if ( ! $leavename ) {
    267288                        $post_link = str_replace("%$post->post_type%", $slug, $post_link);
    268289                }
    269290                $post_link = home_url( user_trailingslashit($post_link) );
    270291        } 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 ) )
    272293                        $post_link = add_query_arg($post_type->query_var, $slug, '');
    273294                else
    274295                        $post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');