Automattic / Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
https://wordpress.org/plugins/co-authors-plus/
GNU General Public License v2.0
290 stars 205 forks source link

Incorrect post count for guest authors when they have a linked account #928

Open dhiraj28691 opened 1 year ago

dhiraj28691 commented 1 year ago

Steps to Reproduce.

  1. Create few posts and assign wordpress user as an author.
  2. Create a guest author and link the above wordpress user as a linked account.
  3. Now check the count of the posts in wp-admin/users.php?page=view-guest-authors page

it is showing double / incorrect count.

The reason for this is, linked account posts are considered twice as per the code.

get_guest_author_post_count function is returning only linked account posts if there is a linked account attached with guest author profile.

public function get_guest_author_post_count( $guest_author ) {
        if ( ! is_object( $guest_author ) ) {
            return;
        }
        $term       = $this->get_author_term( $guest_author );
        $guest_term = get_term_by( 'slug', 'cap-' . $guest_author->user_nicename, $this->coauthor_taxonomy );

        if ( is_object( $guest_term )
            && ! empty( $guest_author->linked_account )
            && $guest_term->count ) {
            return count_user_posts( get_user_by( 'login', $guest_author->linked_account )->ID );
        } elseif ( $term ) {
            return $term->count;
        } else {
            return 0;
        }
    }

In the below function which is used to display posts count, it is calculating the posts for that guest author and adding linked account posts.

get_guest_author_post_count is already returning linked account posts.

function column_posts( $item ) {
        global $coauthors_plus;
        $count = $coauthors_plus->get_guest_author_post_count( $item );
        if ( ! empty( $item->linked_account ) ) {
            global $coauthors_plus;
            // Add user term count to guest author term count.
            $term = get_term_by( 'slug', 'cap-' . $item->linked_account, $coauthors_plus->coauthor_taxonomy );
            if ( is_object( $term ) ) {
                $count = $count + $term->count;
            }   
        }
        return '<a href="' . esc_url( add_query_arg( 'author_name', rawurlencode( $item->user_login ), admin_url( 'edit.php' ) ) ) . '">' . $count . '</a>';
    }
photocurio commented 1 year ago

Hello anyone? This is a serious issue.