Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guest Author Counts are more accurate #461

Merged
merged 6 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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