Fixing double posts counts for users with linked accounts #567
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #561.
On a correct, up-to-date CAP installation, posts counts for authors with guest authors profile are absolutely off - basically, they are double what they should.
This is an example with CAP enabled - clearly off since the

Mine
posts is more than the total:With CAP disabled:

Prior to this PR, the code which filtered the WP posts count was this:
Both
$term
and$guest_term
are considered, guessing that$term
would hold the non-prefixed version of the CAP author term, while$guest_term
the prefixedcap-
one. The counts are later summed under the assumption that they are complementary. The flaw is that$this->get_author_term()
already fetches the one term that exists, giving priority to the prefixedcap-
version of it. So what happens is that, ifcap-$username
exists, both$term
and$guest_term
will contain its content, and$count
will then be doubled.The fix is thus to get rid of the
$guest_term
var and only retain the final conditional:But aren't we losing some counts on the way? Aren't we discarding the non-prefixed version of the term? Is it just useless? No, we don't lose counts; No, we are discarding it, and no, it is not useless. The pivot is
$this->update_author_term()
: it will update any of the terms that exist, also suggesting that it should never happen that they co-exist: either there is the prefixedcap-
term, or the non-prefixed one. In any case,get_author_term()
will fetch the one that exists for the author, which will already contain the total count, and we don't need to sum anything to it.(I think we should also think about migrating terms to all having the
cap-
prefix, but this is another issue #566)