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

WPcom: adjust filter for comment counts used in Calypso #24512

Merged
merged 13 commits into from
Jun 7, 2022

Conversation

villanovachile
Copy link
Contributor

@villanovachile villanovachile commented May 25, 2022

Currently certain comment types, comment, pingback, and trackback are whitelisted for being displayed in the comments list. Comment counts, on the other hand are calculated by excluding the comment types order_note, webhook_delivery, review, action_log.

This is done using the jetpack_api_exclude_comment_types_count filter, and does not take into account other comment types that may be used by third-party plugins. As a result, there can be a discrepancy between the comments listed, and the comment count that are displayed.

After discussing this further with @samiff we decided that it may be best to deprecate jetpack_api_exclude_comment_types_count, and instead introduce jetpack_api_include_comment_types_count, which will bring parity to the comment types displayed, and the comment types counted, defaulting to including comment, pingback, and trackback comment types.

Fixes #63872

Changes proposed in this Pull Request:

  • deprecate jetpack_api_exclude_comment_types_count and introduce jetpack_api_include_comment_types_count
  • The database is now queried for comment_types WHERE comment_type IN matching those specified in the array

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • Create several comments on a post/page
  • Go to the wp_comments table, and edit the comment_type to something other than comment, pingback, trackback
  • Go to https://wordpress.com/comments/{domain}
  • The comment counts should match the number of comments actually listed

Daniel Rodriguez added 2 commits May 25, 2022 16:12
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello villanovachile! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D81537-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label May 25, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 25, 2022

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: July 5, 2022.
  • Scheduled code freeze: June 28, 2022.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 25, 2022
@villanovachile villanovachile added the [Status] Needs Team Review Obsolete. Use Needs Review instead. label May 25, 2022
Copy link
Contributor

@samiff samiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just have a couple thoughts. On the wpcom side, there may need some tests that need to be updated as well, but we can look at that when the time comes.

@samiff samiff removed the [Status] Needs Team Review Obsolete. Use Needs Review instead. label May 26, 2022
@samiff samiff changed the title Add/jetpack api include comment types count WPcom: adjust filter for comment counts used in Calypso May 26, 2022
villanovachile and others added 2 commits May 26, 2022 12:14
…ment-types-count

Co-authored-by: Samiff <samiff@users.noreply.github.com>
@villanovachile villanovachile requested a review from samiff May 26, 2022 20:25
@villanovachile
Copy link
Contributor Author

Thanks, Sami! I've gone ahead and committed the suggestions.

samiff
samiff previously requested changes May 26, 2022
Copy link
Contributor

@samiff samiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just a few tiny suggestions 👍

villanovachile and others added 4 commits May 26, 2022 13:54
Co-authored-by: Samiff <samiff@users.noreply.github.com>
Co-authored-by: Samiff <samiff@users.noreply.github.com>
Co-authored-by: Samiff <samiff@users.noreply.github.com>
@villanovachile villanovachile force-pushed the add/jetpack-api-include-comment-types-count branch from 5ab6ab2 to 33f69e1 Compare May 26, 2022 21:04
@villanovachile villanovachile requested a review from samiff May 26, 2022 21:05
@samiff
Copy link
Contributor

samiff commented May 26, 2022

I'm a bit confused on the failing TC tests for the wpcom diff. We are touching the /sites/%s/comment-counts endpoint but I'm seeing failures for the /comments endpoint in a couple TC tests 🤔 I'll have another look at this Monday.

@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] WPCOM API [Pri] Normal labels Jun 7, 2022
*
* @param array Array of comment types to exclude (default: 'order_note', 'webhook_delivery', 'review', 'action_log')
*/
$exclude = apply_filters_deprecated( 'jetpack_api_exclude_comment_types_count', array( 'order_note', 'webhook_delivery', 'review', 'action_log' ), 'jetpack-11.0', 'jetpack_api_include_comment_types_count' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$exclude = apply_filters_deprecated( 'jetpack_api_exclude_comment_types_count', array( 'order_note', 'webhook_delivery', 'review', 'action_log' ), 'jetpack-11.0', 'jetpack_api_include_comment_types_count' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$exclude = apply_filters_deprecated( 'jetpack_api_exclude_comment_types_count', array( 'order_note', 'webhook_delivery', 'review', 'action_log' ), 'jetpack-$$next-version$$', 'jetpack_api_include_comment_types_count' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anomiex Should the replace-next-version-tag script be catching this already, or would it need to be adjusted?

[plugins/jetpack 4:17.704] === Updating $$next-version$$ ===
[plugins/jetpack 4:17.704] 
[plugins/jetpack 4:19.232] Processing projects/plugins/jetpack/class.json-api.php
[plugins/jetpack 4:19.243] ::error file=projects/plugins/jetpack/class.json-api.php,line=1032::Unexpected `$$next-version$$` token.

Copy link
Member

@jeherve jeherve Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I expected the script to catch this indeed, my bad.
52f4c59

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably should, but currently doesn't. It only handles _deprecated_function, _deprecated_constructor, _deprecated_file, _deprecated_argument, and _deprecated_hook.

Handling apply_filters_deprecated may not be entirely straightforward, since it seems likely enough that phpcs might wind up wrapping that onto multiple lines. Maybe it's time to just replace $$next-version$$ everywhere and hope that never manages to collide with anything unexpected.

villanovachile and others added 2 commits June 7, 2022 08:37
Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
@villanovachile villanovachile requested a review from jeherve June 7, 2022 15:38
jeherve
jeherve previously approved these changes Jun 7, 2022
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well for me now, I think it should be good to go. 🚢

@jeherve jeherve added this to the jetpack/11.1 milestone Jun 7, 2022
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jun 7, 2022
@jeherve jeherve dismissed samiff’s stale review June 7, 2022 16:17

Changes have been addressed

@samiff samiff merged commit 393da16 into master Jun 7, 2022
@samiff samiff deleted the add/jetpack-api-include-comment-types-count branch June 7, 2022 16:33
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Jun 7, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2022

Great news! One last step: head over to your WordPress.com diff, D81537-code, and deploy it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@samiff
Copy link
Contributor

samiff commented Jun 7, 2022

r246959-wpcom

matticbot pushed a commit to Automattic/jetpack-production that referenced this pull request Jun 7, 2022
* Deprecates jetpack_api_include_comment_types_count and introduces jetpack_api_include_comment_types_count

* changelog

* Update projects/plugins/jetpack/changelog/add-jetpack-api-include-comment-types-count

Co-authored-by: Samiff <samiff@users.noreply.github.com>

* [not verified] Added doc blocks and switched existing apply_filters to apply_filters_deprecated

* Update projects/plugins/jetpack/class.json-api.php

Co-authored-by: Samiff <samiff@users.noreply.github.com>

* Update projects/plugins/jetpack/class.json-api.php

Co-authored-by: Samiff <samiff@users.noreply.github.com>

* Update projects/plugins/jetpack/class.json-api.php

Co-authored-by: Samiff <samiff@users.noreply.github.com>

* Re-added 'since' tag to deprecated filter doc block

* Update projects/plugins/jetpack/class.json-api.php

Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>

* Update projects/plugins/jetpack/class.json-api.php

Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>

* Update to final version

See Automattic/jetpack#24512 (comment)

Co-authored-by: Daniel Rodriguez <daniel.r@a8c.com>
Co-authored-by: Samiff <samiff@users.noreply.github.com>
Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/2456039741
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WPCOM API [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: My Site > Comments counting incompatible comment_type
5 participants