Ticket #21431: 21431.diff
| File 21431.diff, 5.2 KB (added by , 13 years ago) |
|---|
-
wp-includes/post.php
4234 4234 * @param string $post_type Post type. 4235 4235 * @param bool $full Optional. Returns a full WHERE statement instead of just an 'andalso' term. 4236 4236 * @param int $post_author Optional. Query posts having a single author ID. 4237 * @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user. Default is false. 4237 4238 * @return string SQL WHERE code that can be added to a query. 4238 4239 */ 4239 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) {4240 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { 4240 4241 global $user_ID, $wpdb; 4241 4242 4242 4243 // Private posts … … 4260 4261 4261 4262 $sql .= "(post_status = 'publish'"; 4262 4263 4263 if ( current_user_can( $cap ) ) { 4264 // Does the user have the capability to view private posts? Guess so. 4265 $sql .= " OR post_status = 'private'"; 4266 } elseif ( is_user_logged_in() ) { 4267 // Users can view their own private posts. 4268 $id = (int) $user_ID; 4269 if ( null === $post_author || ! $full ) { 4270 $sql .= " OR post_status = 'private' AND post_author = $id"; 4271 } elseif ( $id == (int) $post_author ) { 4264 // Only need to check the cap if $public_only is false 4265 if ( false === $public_only ) { 4266 if ( current_user_can( $cap ) ) { 4267 // Does the user have the capability to view private posts? Guess so. 4272 4268 $sql .= " OR post_status = 'private'"; 4269 } elseif ( is_user_logged_in() ) { 4270 // Users can view their own private posts. 4271 $id = (int) $user_ID; 4272 if ( null === $post_author || ! $full ) { 4273 $sql .= " OR post_status = 'private' AND post_author = $id"; 4274 } elseif ( $id == (int) $post_author ) { 4275 $sql .= " OR post_status = 'private'"; 4276 } // else none 4273 4277 } // else none 4274 } // else none4278 } 4275 4279 4276 4280 $sql .= ')'; 4277 4281 -
wp-includes/user.php
167 167 * 168 168 * @param array $users Array of user IDs. 169 169 * @param string|array $post_type Optional. Post type to check. Defaults to post. 170 * @param bool $public_only Optional. Only return counts for public posts. Defaults to false. 170 171 * @return array Amount of posts each user has written. 171 172 */ 172 function count_many_users_posts( $users, $post_type = 'post' ) {173 function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { 173 174 global $wpdb; 174 175 175 176 $count = array(); … … 177 178 return $count; 178 179 179 180 $userlist = implode( ',', array_map( 'absint', $users ) ); 180 $where = get_posts_by_author_sql( $post_type );181 $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); 181 182 182 183 $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); 183 184 foreach ( $result as $row ) { -
wp-content/mu-plugins/widgets/authors.php
152 152 * Widget to display a grid of author avatar images 153 153 * Default size is 32px 154 154 */ 155 function wp_widget_author_grid($args) { 156 global $wpdb; 157 155 function wp_widget_author_grid( $args ) { 156 // This is lame and should go away but we need to do something with the output from get_author_posts_url() 158 157 $cache_bucket = is_ssl() ? 'widget_author_grid_ssl' : 'widget_author_grid'; 159 158 160 159 if ( '%BEG_OF_TITLE%' != $args['before_title'] ) { … … 167 166 $options = get_option('widget_author_grid'); 168 167 $title = empty($options['title']) ? __('Authors') : $options['title']; 169 168 $display_all_authors = $options['all'] ? true : false; 169 $users_of_blog = get_users_of_blog(); 170 foreach ( $users_of_blog as $user ) { 171 $user_ids[] = $user->ID; 172 } 173 $post_counts = count_many_users_posts( $user_ids, 'post', true ); 170 174 171 $query_string = "SELECT user_id, display_name, user_login FROM $wpdb->users, $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '" . $wpdb->prefix . "capabilities'";172 $results = $wpdb->get_results($query_string);173 174 175 $size = $options[ 'avatar_size' ] ? $options[ 'avatar_size' ] : 32; 175 176 176 177 echo $before_widget; 177 178 echo "\t" . $before_title . esc_html($title) . $after_title; 178 179 echo "\t" . '<ul>' . "\n"; 179 180 180 foreach ( $results as $row) {181 $r = new WP_Query("author=$row->user_id&showposts=$query_number&what_to_show=posts&nopaging=0&post_status=publish");181 foreach ( $post_counts as $post_author => $post_count ) { 182 if ( 0 == $post_count && !$display_all_authors ) continue; 182 183 183 if ( !($r->have_posts() || $display_all_authors) ) continue;184 185 184 echo "\t\t" . '<li>' . "\n"; 186 185 187 186 //display avatar 188 echo "\t\t\t" . '<a href="' . get_option('home') . '/author/' . esc_attr($row->user_login) . '/"> ';189 echo get_avatar( $row->user_id, $size, '', true );187 echo "\t\t\t" . '<a href="' . esc_url( get_author_posts_url( $post_author ) ) . '"> '; 188 echo get_avatar( $post_author, $size, '', true ); 190 189 echo '</a>' . "\n"; 191 190 192 191 echo "\t\t" . '</li>' . "\n";