WordPress.org

Make WordPress Core

Ticket #23665: 23665-post-preview.patch

File 23665-post-preview.patch, 1.1 KB (added by johnjamesjacoby, 12 months ago)

Fix logic for generating post preview $url in post_preview()

  • wp-admin/includes/post.php

     
    13831383        if ( is_wp_error($id) ) 
    13841384                wp_die( $id->get_error_message() ); 
    13851385 
    1386         if ( $_POST['post_status'] == 'draft' && $user_id == $post->post_author ) { 
    1387                 $url = add_query_arg( 'preview', 'true', get_permalink($id) ); 
     1386        // Get post-request post-status-object to check if public/private/protected 
     1387        $post_request_status_obj = get_post_status_object( $_POST['post_status'] ); 
     1388 
     1389        // This tricky bit determines if the post-status-object for the post-request 
     1390        // is public, or one that only the current user can see, so that the proper 
     1391        // preview link is generated (with or without a preview nonce.) 
     1392        if ( true === $post_request_status_obj->public || ( $user_id == $post->post_author && ( true === $post_request_status_obj->private ) || ( true === $post_request_status_obj->protected ) )  ) { 
     1393                $url = add_query_arg( 'preview', 'true', get_permalink( $id ) ); 
    13881394        } else { 
    13891395                $nonce = wp_create_nonce('post_preview_' . $id); 
    13901396                $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) );