Make WordPress Core


Ignore:
Timestamp:
04/09/2005 05:12:36 PM (20 years ago)
Author:
ryan
Message:

Remove old preview stuff. Allow draft posts to be displayed if the logged in user has edit permissions on the draft. Don't use cruft-free links for drafts since they might not have a slug. http://mosquito.wordpress.org/view.php?id=1220

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/classes.php

    r2478 r2523  
    494494
    495495        if ($this->is_page) {
    496             $where .= ' AND (post_status = "static"';
     496            $where .= ' AND (post_status = "static")';
     497        } elseif ($this->is_single) {
     498            $where .= ' AND (post_status != "static")';
    497499        } else {
    498500            $where .= ' AND (post_status = "publish"';
    499         }
    500 
    501         // Get private posts
    502         if (isset($user_ID) && ('' != intval($user_ID)))
    503             $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
    504         else
    505             $where .= ')';
     501
     502            if (isset($user_ID) && ('' != intval($user_ID)))
     503                $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
     504            else
     505                $where .= ')';             
     506        }
    506507
    507508        // Apply filters on where and join prior to paging so that any
     
    544545        $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1".$where." ORDER BY " . $orderby . " $limits";
    545546
    546         if ($q['preview']) {
    547             $request = 'SELECT 1-1'; // dummy mysql query for the preview
    548             // little funky fix for IEwin, rawk on that code
    549             $is_winIE = ((preg_match('/MSIE/',$HTTP_USER_AGENT)) && (preg_match('/Win/',$HTTP_USER_AGENT)));
    550             if (($is_winIE) && (!isset($IEWin_bookmarklet_fix))) {
    551                 $preview_content =  preg_replace('/\%u([0-9A-F]{4,4})/e',  "'&#'.base_convert('\\1',16,10).';'", $preview_content);
    552             }
    553         }
    554 
    555547        $this->posts = $wpdb->get_results($request);
     548
     549        // Check post status to determine if post should be displayed.
     550        if ($this->is_single) {
     551            if ('publish' != $this->posts[0]->post_status) {
     552                if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) {
     553                    // User must be logged in to view unpublished posts.
     554                    $this->posts = array();
     555                } else {
     556                    if ('draft' == $this->posts[0]->post_status) {
     557                        // User must have edit permissions on the draft to preview.
     558                        if (! user_can_edit_post($user_ID, $this->posts[0]->ID))
     559                            $this->posts = array();
     560                    } elseif ('private' == $this->posts[0]->post_status) {
     561                        if ($this->posts[0]->post_author != $user_ID)
     562                            $this->posts = array();
     563                    }
     564                }
     565            }
     566        }
     567
    556568        $this->posts = apply_filters('the_posts', $this->posts);
    557569        $this->post_count = count($this->posts);
Note: See TracChangeset for help on using the changeset viewer.