Ticket #10329: 10329.diff
| File 10329.diff, 6.0 KB (added by takaitra, 3 years ago) |
|---|
-
author-template.php
247 247 * or as a string.</li> 248 248 * <li>html (bool) (true): Whether to list the items in html for or plaintext. 249 249 * </li> 250 * <li>orderby (string) ('name'): The sort order of the list.</li> 251 * <li>order (string) ('ASC'): Sort order for authors (either ascending or 252 * descending).</li> 253 * <li>number (int) (NULL): Sets the number of authors to display. This 254 * causes the SQL LIMIT value to be defined. Default to no LIMIT.</li> 255 * <li>min_count (int) (NULL): Sets a minimum post count threshold. Defaults to 256 * no minimum.</li> 250 257 * </ul> 251 258 * 252 259 * @link http://codex.wordpress.org/Template_Tags/wp_list_authors … … 255 262 * @return null|string The output, if echo is set to false. 256 263 */ 257 264 function wp_list_authors($args = '') { 258 global $wpdb ;265 global $wpdb, $blog_id; 259 266 260 267 $defaults = array( 261 268 'optioncount' => false, 'exclude_admin' => true, 262 269 'show_fullname' => false, 'hide_empty' => true, 263 270 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 264 'style' => 'list', 'html' => true 271 'style' => 'list', 'html' => true, 'orderby' => 'name', 272 'order' => 'ASC', 'number' => NULL, 'min_count' => NULL 265 273 ); 266 274 267 275 $r = wp_parse_args( $args, $defaults ); 268 276 extract($r, EXTR_SKIP); 269 277 $return = ''; 270 278 271 /** @todo Move select to get_authors(). */ 272 $users = get_users_of_blog(); 273 $author_ids = array(); 274 foreach ( (array) $users as $user ) 275 $author_ids[] = $user->user_id; 276 if ( count($author_ids) > 0 ) { 277 $author_ids = implode(',', $author_ids ); 278 $authors = $wpdb->get_results( "SELECT ID, user_nicename from $wpdb->users WHERE ID IN($author_ids) " . ($exclude_admin ? "AND user_login <> 'admin' " : '') . "ORDER BY display_name" ); 279 if ( empty($id) ) 280 $id = (int) $blog_id; 281 $blog_prefix = $wpdb->get_blog_prefix($id); 282 283 // Generate appropriate SQL selections and conditions based on the arguments 284 if ( $show_fullname ) { 285 // Select first and last name if they exist. Otherwise, show the display name. 286 $author_name_field = "CASE 287 WHEN TRIM(CONCAT_WS(' ', COALESCE(meta_first_name.meta_value, ''), COALESCE(meta_last_name.meta_value, ''))) <> '' 288 THEN 289 TRIM(CONCAT_WS(' ', COALESCE(meta_first_name.meta_value, ''), COALESCE(meta_last_name.meta_value, ''))) 290 ELSE 291 $wpdb->users.display_name 292 END"; 293 // Joins to support selection of first and last name 294 $author_name_join = " 295 LEFT JOIN $wpdb->usermeta AS meta_first_name ON meta_first_name.user_id = $wpdb->users.ID AND meta_first_name.meta_key = 'first_name' 296 LEFT JOIN $wpdb->usermeta AS meta_last_name ON meta_last_name.user_id = $wpdb->users.ID AND meta_last_name.meta_key = 'last_name' 297 "; 279 298 } else { 280 $authors = array(); 299 // Select display name. No usermeta join needed for first and last name. 300 $author_name_field = "$wpdb->users.display_name"; 301 $author_name_join = ""; 281 302 } 282 303 283 $author_count = array(); 284 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 ) 285 $author_count[$row->post_author] = $row->count; 304 // Order ASC or DESC based on the order and orderby arguments 305 if ( $orderby == 'count' ) { 306 $author_sort = "ORDER BY author_count $order, author_name"; 307 } else { 308 $author_sort = "ORDER BY author_name $order"; 309 } 286 310 311 // Limit the results based on the min_count argument 312 $min_count = intval( $min_count ); 313 if ( $min_count > 0 ) { 314 $author_having = "HAVING author_count >= $min_count"; 315 } else { 316 $author_having = ''; 317 } 318 319 // Limit the results based on the number argument 320 $number = intval( $number ); 321 if ( $number > 0 ) { 322 $author_limit = "LIMIT $number"; 323 } else { 324 $author_limit = ''; 325 } 326 327 // Join to exclude authors from other blogs. Only needed if hide_empty is 328 // false (the INNER JOIN to $wpdb->posts would already exclude other blogs) 329 if ( !$hide_empty ) { 330 $author_cap_join = "JOIN $wpdb->usermeta AS meta_capabilities ON meta_capabilities.user_id = $wpdb->users.ID AND meta_capabilities.meta_key = '{$blog_prefix}capabilities'"; 331 } else { 332 $author_cap_join = ''; 333 } 334 335 // Query the list of users 336 $blog_prefix = $wpdb->get_blog_prefix($blog_id); 337 $authors = $wpdb->get_results(" 338 SELECT $wpdb->users.ID, $wpdb->users.user_nicename, COUNT($wpdb->posts.ID) as author_count, $author_name_field as author_name 339 FROM $wpdb->users 340 " . ( !$hide_empty ? "LEFT " : '' ) . "JOIN $wpdb->posts ON $wpdb->posts.post_author = $wpdb->users.ID 341 $author_name_join 342 $author_cap_join 343 WHERE ($wpdb->posts.post_type = 'post' OR $wpdb->posts.post_type IS NULL) 344 AND ($wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'private' OR $wpdb->posts.post_status IS NULL) " . 345 ( $exclude_admin ? "AND $wpdb->users.user_login <> 'admin' " : '' ) . " 346 GROUP BY $wpdb->users.ID 347 $author_having 348 $author_sort 349 $author_limit 350 "); 351 287 352 foreach ( (array) $authors as $author ) { 288 353 289 354 $link = ''; 290 355 291 $author = get_userdata( $author->ID ); 292 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; 293 $name = $author->display_name; 356 $posts = $author->author_count; 357 $name = $author->author_name; 294 358 295 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )296 $name = "$author->first_name $author->last_name";297 298 359 if( !$html ) { 299 360 if ( $posts == 0 ) { 300 361 if ( ! $hide_empty ) … … 312 373 if ( ! $hide_empty ) 313 374 $link = $name; 314 375 } else { 315 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author-> display_name) ) . '">' . $name . '</a>';376 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->author_name) ) . '">' . $name . '</a>'; 316 377 317 378 if ( (! empty($feed_image)) || (! empty($feed)) ) { 318 379 $link .= ' ';
