Ticket #32243: post.diff
| File post.diff, 2.1 KB (added by , 11 years ago) |
|---|
-
post.php
5330 5330 * 5331 5331 * @see get_private_posts_cap_sql() 5332 5332 * 5333 * @param string $post_type Post type.5333 * @param array $post_types Post type(s). 5334 5334 * @param bool $full Optional. Returns a full WHERE statement instead of just 5335 5335 * an 'andalso' term. Default true. 5336 5336 * @param int $post_author Optional. Query posts having a single author ID. Default null. … … 5338 5338 * $current_user. Default false. 5339 5339 * @return string SQL WHERE code that can be added to a query. 5340 5340 */ 5341 function get_posts_by_author_sql( $post_type , $full = true, $post_author = null, $public_only = false ) {5341 function get_posts_by_author_sql( $post_types, $full = true, $post_author = null, $public_only = false ) { 5342 5342 global $wpdb; 5343 5343 5344 5344 // Private posts. 5345 $post_type_obj = get_post_type_object( $post_type );5345 foreach ($post_types as $post_type) $post_type_obj = get_post_type_object( $post_type ); 5346 5346 if ( ! $post_type_obj ) 5347 5347 return $full ? 'WHERE 1 = 0' : ' 1 = 0 '; 5348 5348 … … 5358 5358 if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) ) { 5359 5359 $cap = $post_type_obj->cap->read_private_posts; 5360 5360 } 5361 5362 $post_type_sql = array_fill(0, count($post_types), '%s'); 5363 $where = '(post_type = '.implode(' OR post_type = ', $post_type_sql).')'; 5364 $sql = $wpdb->prepare($where, $post_types); 5361 5365 5362 $sql = $wpdb->prepare( 'post_type = %s', $post_type );5363 5364 5366 if ( null !== $post_author ) { 5365 5367 $sql .= $wpdb->prepare( ' AND post_author = %d', $post_author ); 5366 5368 } … … 5369 5371 $post_status_sql = "post_status = 'publish'"; 5370 5372 if ( false === $public_only ) { 5371 5373 if ( current_user_can( $cap ) ) { 5372 // Does the user have the capability to view private posts ? Guess so.5374 // Does the user have the capability to view private posts (we're only checking for the last post_type, but that's ok)? Guess so. 5373 5375 $post_status_sql .= " OR post_status = 'private'"; 5374 5376 } elseif ( is_user_logged_in() ) { 5375 5377 // Users can view their own private posts.