Ticket #18791: 18791-2.patch
File 18791-2.patch, 3.9 KB (added by , 10 years ago) |
---|
-
src/wp-includes/author-template.php
336 336 'orderby' => 'name', 'order' => 'ASC', 'number' => '', 337 337 'optioncount' => false, 'exclude_admin' => true, 338 338 'show_fullname' => false, 'hide_empty' => true, 339 'feed' => '', 'feed_image' => '', 'feed_type' => '', ' echo' => true,339 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'post_type' => '', 'echo' => true, 340 340 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => '' 341 341 ); 342 342 … … 348 348 $query_args['fields'] = 'ids'; 349 349 $authors = get_users( $query_args ); 350 350 351 if( is_array( $post_type ) ) { 352 353 $post_type = 'post_type IN ( ' . implode( ',', array_map( 'sanitize_key', $args['post_type'] ) ) . ' )'; 354 355 } else { 356 357 $post_type = 'post_type = ' . sanitize_key( $args['post_type'] ); 358 359 } 360 351 361 $author_count = array(); 352 foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) {362 foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE $post_type " . get_private_posts_cap_sql( 'any' ) . " GROUP BY post_author" ) as $row ) { 353 363 $author_count[$row->post_author] = $row->count; 354 364 } 355 365 foreach ( $authors as $author_id ) { … … 440 450 global $wpdb; 441 451 442 452 if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) { 443 $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_ type = 'post' AND post_status = 'publish' LIMIT 2");453 $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status = 'publish' LIMIT 2"); 444 454 $is_multi_author = 1 < count( $rows ) ? 1 : 0; 445 455 set_transient( 'is_multi_author', $is_multi_author ); 446 456 } -
src/wp-includes/post.php
5217 5217 * @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user. Default is false. 5218 5218 * @return string SQL WHERE code that can be added to a query. 5219 5219 */ 5220 function get_posts_by_author_sql( $post_type , $full = true, $post_author = null, $public_only = false ) {5220 function get_posts_by_author_sql( $post_type = 'post', $full = true, $post_author = null, $public_only = false ) { 5221 5221 global $wpdb; 5222 5222 5223 5223 // Private posts … … 5238 5238 $cap = $post_type_obj->cap->read_private_posts; 5239 5239 } 5240 5240 5241 if( is_array( $post_type ) ) { 5242 5243 $post_type_where = 'post_type IN ( ' . implode( ',', array_map( 'sanitize_key', $post_type ) ) . ' )'; 5244 5245 } else { 5246 5247 $post_type_where = 'post_type = ' . sanitize_key( $post_type ); 5248 5249 } 5250 5241 5251 if ( $full ) { 5242 5252 if ( null === $post_author ) { 5243 $sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type );5253 $sql = $wpdb->prepare( 'WHERE %s AND ', $post_type_where ); 5244 5254 } else { 5245 $sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type );5255 $sql = $wpdb->prepare( 'WHERE post_author = %d AND %s AND ', $post_author, $post_type_where ); 5246 5256 } 5247 5257 } else { 5248 5258 $sql = ''; -
src/wp-includes/user.php
256 256 * @param int $userid User ID. 257 257 * @return int Amount of posts user has written. 258 258 */ 259 function count_user_posts( $userid) {259 function count_user_posts( $userid, $post_type = false ) { 260 260 global $wpdb; 261 261 262 $where = get_posts_by_author_sql( 'post', true, $userid);262 $where = get_posts_by_author_sql( $post_type, true, $userid ); 263 263 264 264 $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); 265 265