Make WordPress Core


Ignore:
Timestamp:
09/15/2015 04:14:23 AM (9 years ago)
Author:
wonderboymusic
Message:

Create a function, get_preview_post_link(), to DRY the logic for applying the 'preview_post_link' filter to a URL.

Props TomHarrigan, wonderboymusic.
Fixes #24345.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r34020 r34170  
    13191319    if ( isset( $view_post ) ) {
    13201320        if ( 'draft' == $post->post_status ) {
    1321             $preview_link = set_url_scheme( get_permalink( $post->ID ) );
     1321            $draft_link = set_url_scheme( get_permalink( $post->ID ) );
    13221322            /** This filter is documented in wp-admin/includes/meta-boxes.php */
    1323             $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
     1323            $preview_link = get_preview_post_link( $post, array(), $draft_link );
    13241324            $return .= "<span id='view-post-btn'><a href='" . esc_url( $preview_link ) . "' class='button button-small' target='wp-preview-{$post->ID}'>$view_post</a></span>\n";
    13251325        } else {
     
    15121512
    15131513    if ( $locked ) {
     1514        $query_args = array();
    15141515        if ( get_post_type_object( $post->post_type )->public ) {
    1515             $preview_link = set_url_scheme( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) );
    1516 
    15171516            if ( 'publish' == $post->post_status || $user->ID != $post->post_author ) {
    15181517                // Latest content is in autosave
    15191518                $nonce = wp_create_nonce( 'post_preview_' . $post->ID );
    1520                 $preview_link = add_query_arg( array( 'preview_id' => $post->ID, 'preview_nonce' => $nonce ), $preview_link );
     1519                $query_args['preview_id'] = $post->ID;
     1520                $query_args['preview_nonce'] = $nonce;
    15211521            }
    1522         } else {
    1523             $preview_link = '';
    1524         }
    1525 
    1526         /** This filter is documented in wp-admin/includes/meta-boxes.php */
    1527         $preview_link = apply_filters( 'preview_post_link', $preview_link, $post );
     1522        }
     1523
     1524        $preview_link = get_preview_post_link( $post->ID, $query_args );
    15281525
    15291526        /**
     
    17111708        wp_die( $saved_post_id->get_error_message() );
    17121709
    1713     $query_args = array( 'preview' => 'true' );
     1710    $query_args = array();
    17141711
    17151712    if ( $is_autosave && $saved_post_id ) {
     
    17211718    }
    17221719
    1723     $url = add_query_arg( $query_args, get_permalink( $post->ID ) );
    1724 
    1725     /** This filter is documented in wp-admin/includes/meta-boxes.php */
    1726     return apply_filters( 'preview_post_link', $url, $post );
     1720    return get_preview_post_link( $post, $query_args );
    17271721}
    17281722
Note: See TracChangeset for help on using the changeset viewer.