Changeset 22386
- Timestamp:
- 11/05/2012 11:11:25 PM (13 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r22357 r22386 4432 4432 * @param bool $full Optional. Returns a full WHERE statement instead of just an 'andalso' term. 4433 4433 * @param int $post_author Optional. Query posts having a single author ID. 4434 * @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user. Default is false. 4434 4435 * @return string SQL WHERE code that can be added to a query. 4435 4436 */ 4436 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) {4437 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { 4437 4438 global $user_ID, $wpdb; 4438 4439 … … 4458 4459 $sql .= "(post_status = 'publish'"; 4459 4460 4460 if ( current_user_can( $cap ) ) { 4461 // Does the user have the capability to view private posts? Guess so. 4462 $sql .= " OR post_status = 'private'"; 4463 } elseif ( is_user_logged_in() ) { 4464 // Users can view their own private posts. 4465 $id = (int) $user_ID; 4466 if ( null === $post_author || ! $full ) { 4467 $sql .= " OR post_status = 'private' AND post_author = $id"; 4468 } elseif ( $id == (int) $post_author ) { 4461 // Only need to check the cap if $public_only is false 4462 if ( false === $public_only ) { 4463 if ( current_user_can( $cap ) ) { 4464 // Does the user have the capability to view private posts? Guess so. 4469 4465 $sql .= " OR post_status = 'private'"; 4466 } elseif ( is_user_logged_in() ) { 4467 // Users can view their own private posts. 4468 $id = (int) $user_ID; 4469 if ( null === $post_author || ! $full ) { 4470 $sql .= " OR post_status = 'private' AND post_author = $id"; 4471 } elseif ( $id == (int) $post_author ) { 4472 $sql .= " OR post_status = 'private'"; 4473 } // else none 4470 4474 } // else none 4471 } // else none4475 } 4472 4476 4473 4477 $sql .= ')'; -
trunk/wp-includes/user.php
r22248 r22386 167 167 * @param array $users Array of user IDs. 168 168 * @param string $post_type Optional. Post type to check. Defaults to post. 169 * @param bool $public_only Optional. Only return counts for public posts. Defaults to false. 169 170 * @return array Amount of posts each user has written. 170 171 */ 171 function count_many_users_posts( $users, $post_type = 'post' ) {172 function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { 172 173 global $wpdb; 173 174 … … 177 178 178 179 $userlist = implode( ',', array_map( 'absint', $users ) ); 179 $where = get_posts_by_author_sql( $post_type );180 $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); 180 181 181 182 $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
Note: See TracChangeset
for help on using the changeset viewer.