Ticket #17220: 17220.2.diff
File 17220.2.diff, 3.8 KB (added by , 13 years ago) |
---|
-
wp-includes/post.php
4063 4063 * @param string $post_type currently only supports 'post' or 'page'. 4064 4064 * @return string SQL code that can be added to a where clause. 4065 4065 */ 4066 function get_private_posts_cap_sql( $post_type) {4067 return get_posts_by_author_sql( $post_type, FALSE);4066 function get_private_posts_cap_sql( $post_type ) { 4067 return get_posts_by_author_sql( $post_type, false ); 4068 4068 } 4069 4069 4070 4070 /** … … 4078 4078 * @param int $post_author Optional. Query posts having a single author ID. 4079 4079 * @return string SQL WHERE code that can be added to a query. 4080 4080 */ 4081 function get_posts_by_author_sql( $post_type, $full = TRUE, $post_author = NULL) {4081 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) { 4082 4082 global $user_ID, $wpdb; 4083 4083 4084 4084 // Private posts 4085 if ($post_type == 'post') { 4086 $cap = 'read_private_posts'; 4087 // Private pages 4088 } elseif ($post_type == 'page') { 4089 $cap = 'read_private_pages'; 4090 // Dunno what it is, maybe plugins have their own post type? 4091 } else { 4092 $cap = ''; 4093 $cap = apply_filters('pub_priv_sql_capability', $cap); 4085 $post_type_obj = get_post_type_object( $post_type ); 4086 if ( ! $post_type_obj ) 4087 return ' 1 = 0 '; 4088 $cap = $post_type_obj->cap->read_private_posts; 4094 4089 4095 if (empty($cap)) { 4096 // We don't know what it is, filters don't change anything, 4097 // so set the SQL up to return nothing. 4098 return ' 1 = 0 '; 4099 } 4100 } 4101 4102 if ($full) { 4103 if (is_null($post_author)) { 4104 $sql = $wpdb->prepare('WHERE post_type = %s AND ', $post_type); 4090 if ( $full ) { 4091 if ( null === $post_author ) { 4092 $sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type ); 4105 4093 } else { 4106 $sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type);4094 $sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type ); 4107 4095 } 4108 4096 } else { 4109 4097 $sql = ''; … … 4111 4099 4112 4100 $sql .= "(post_status = 'publish'"; 4113 4101 4114 if ( current_user_can($cap)) {4102 if ( current_user_can( $cap ) ) { 4115 4103 // Does the user have the capability to view private posts? Guess so. 4116 4104 $sql .= " OR post_status = 'private'"; 4117 } elseif ( is_user_logged_in()) {4105 } elseif ( is_user_logged_in() ) { 4118 4106 // Users can view their own private posts. 4119 4107 $id = (int) $user_ID; 4120 if ( is_null($post_author) || !$full) {4108 if ( null === $post_author || ! $full ) { 4121 4109 $sql .= " OR post_status = 'private' AND post_author = $id"; 4122 } elseif ( $id == (int)$post_author) {4110 } elseif ( $id == (int) $post_author ) { 4123 4111 $sql .= " OR post_status = 'private'"; 4124 4112 } // else none 4125 4113 } // else none -
wp-includes/user.php
165 165 * Number of posts written by a list of users. 166 166 * 167 167 * @since 3.0.0 168 * @param array $users User ID number list. 168 * @param array $user_ids Array of user IDs. 169 * @param string|array $post_type Optional. Post type to check. Defaults to post. 169 170 * @return array Amount of posts each user has written. 170 171 */ 171 function count_many_users_posts($users ) {172 function count_many_users_posts($users, $post_type = 'post' ) { 172 173 global $wpdb; 173 174 174 175 $count = array(); 175 if ( ! is_array($users) || empty( $users ) )176 if ( empty( $users ) || ! is_array( $users ) ) 176 177 return $count; 177 178 178 $userlist = implode( ',', $users);179 $where = get_posts_by_author_sql( 'post');179 $userlist = implode( ',', array_map( 'absint', $users ) ); 180 $where = get_posts_by_author_sql( $post_type ); 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 ); 182 183 foreach ( $result as $row ) {