Skip to content

Commit

Permalink
Merge pull request #461 from rebeccahum/guest_author_count_table
Browse files Browse the repository at this point in the history
Guest Author Counts are more accurate
  • Loading branch information
sboisvert authored Nov 13, 2017
2 parents ef47e04 + c8456e6 commit dfc3951
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions co-authors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,15 @@ function filter_count_user_posts( $count, $user_id ) {
$user = $this->get_coauthor_by( 'user_nicename', $user->user_nicename );

$term = $this->get_author_term( $user );
// Only modify the count if the author already exists as a term
if ( $term && ! is_wp_error( $term ) ) {
$guest_term = get_term_by( 'slug', 'cap-' . $user->user_nicename, $this->coauthor_taxonomy );
// Only modify the count if it has a linked account with posts or the author exists as a term
if ( $user->linked_account && $guest_term->count ) {
if ( $term && ! is_wp_error( $term )) {
$count = $guest_term->count + $term->count;
} else {
$count = $guest_term->count;
}
} elseif ( $term && ! is_wp_error( $term ) ) {
$count = $term->count;
}

Expand Down
5 changes: 4 additions & 1 deletion php/class-coauthors-wp-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ function column_linked_account( $item ) {
function column_posts( $item ) {
global $coauthors_plus;
$term = $coauthors_plus->get_author_term( $item );
if ( $term ) {
$guest_term = get_term_by( 'slug', 'cap-' . $item->user_nicename, $coauthors_plus->coauthor_taxonomy );
if ( ! empty( $item->linked_account ) && $guest_term->count ) {
$count = count_user_posts( get_user_by( 'slug', $item->linked_account )->ID );
} elseif ( $term ) {
$count = $term->count;
} else {
$count = 0;
Expand Down

0 comments on commit dfc3951

Please sign in to comment.