Skip to content

Conversation

@peterwilsoncc
Copy link
Contributor

@peterwilsoncc peterwilsoncc commented Sep 18, 2025

What?

Follow up to earlier PR fixing this bug to do the filtering on the pre_get_comments filter.

This is preferable than messing around with the database WHERE clause directly.

I've also added a bunch of unit tests to ensure that the code is working as expected.

Closes #71711
Follow up to #71712

Why?

Messing around with the database query clauses is flakier than using the query variables.

How?

Moves the changes back to the previous hook.

Testing Instructions

  1. Create and publish a post
  2. Write two block comments on the post via editor
  3. Write two actual comments on the post via the front end
  4. Approve the front end comments if required by your moderation settings
  5. Run the following in wp shell, replacing the post ID with the ID created above
wp> get_comments( ['post_id' => 89, 'fields' => 'ids'] );
// Ensure the resulting IDs do not include the block comments
wp> get_comments( ['post_id' => 89, 'fields' => 'ids', 'type' => 'block_comment'] );
// Ensure the resulting IDs include the block comments and not the front end comments

Testing Instructions for Keyboard

N/A

Screenshots or screencast

N/A

@andrewserong
Copy link
Contributor

Closes #71727

I think you might mean #71711? 😄

@peterwilsoncc peterwilsoncc marked this pull request as ready for review September 18, 2025 03:14
@github-actions
Copy link

github-actions bot commented Sep 18, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@peterwilsoncc peterwilsoncc added [Type] Bug An existing feature does not function as intended Collaborative Workflows Phase 3 of the Gutenberg roadmap around all-things related to collaborative workflows labels Sep 18, 2025
Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

I figure the least I could do after commenting is to take this PR for a spin!

This is testing well for me and looks like a good logical change to filter pre_get_comments rather than dealing with the SQL query 👍

✅ Querying get_comments or running wp comment list defaults to only showing actual comments, excluding block comments
✅ Calling get_comments with block_comment type reveals just the block comments
✅ Test coverage looks good

LGTM! 🚀

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

@peterwilsoncc, I think we don't need to prepare a core backport PR, as this feature is still experimental.

Edit: Sorry, I was mistaken, the core backports only have unit tests, so that's fine.

}

/**
* Test that block comments are not excluded when explicitly queried.
Copy link
Member

Choose a reason for hiding this comment

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

nice to have: another test that confirms that query is unchanged when block comments are explicitly excluded (type__not_in).

@peterwilsoncc
Copy link
Contributor Author

@adamsilverstein Added in 265b4c2, is that what you were after?

@adamsilverstein
Copy link
Member

Looks good, thanks @peterwilsoncc!

@t-hamano
Copy link
Contributor

Can we merge this PR?

@Mamaduka
Copy link
Member

I was working on a different issue and noticed that the exclude_block_comments_from_admin filter still affects some sub-queries. Currently, it prevents the generation of embeddable children links in REST API responses.

The $comment->get_children returns nothing for the block_comment type. If I remove the filter it's working correctly.

@peterwilsoncc
Copy link
Contributor Author

peterwilsoncc commented Sep 28, 2025 via email

@Mamaduka
Copy link
Member

Mamaduka commented Sep 30, 2025

Thanks for the pointer, @peterwilsoncc!

I pushed the changes for the parent query vars. Unfortunately, that turned out to be just one part of the puzzle.

Now response returns the correct link for the children embedding, but the URL itself returns no results. I can only get that URL working if I specify type: 'block_comment' and status: 'all'.

This is due to the default collection values for these arguments. We'll probably have to make changes there without breaking backward compatibility. That's outside of the scope here.

// Children embed URL, that doesn't work.
wp.data.select( 'core' ).getEntityRecords( 'root', 'comment', {
  parent: 240,
} )

// Modified query that works.
wp.data.select( 'core' ).getEntityRecords( 'root', 'comment', {
  type: 'block_comment',
  status: 'all',
  parent: 240,
} )

@t-hamano t-hamano added [Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting and removed Collaborative Workflows Phase 3 of the Gutenberg roadmap around all-things related to collaborative workflows labels Oct 4, 2025
$types_not_in = array_filter( $types_not_in );

// If 'block_comment' is already included in the types to include or exclude, do nothing.
if ( in_array( 'block_comment', array_merge( $types_in, $types_not_in ), true ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

The comment type was changed to match the final feature name. Ref: ##72310.

@t-hamano
Copy link
Contributor

Based on this feedback, we added type__not_in directly to the WP_Comments_List_Table class, rather than directly manipulating the database WHERE clause.

Can we apply a similar approach to this PR? In other words, we should be able to use the comments_list_table_query_args hook.

@Mamaduka
Copy link
Member

I just tested the filter. It works for the list table items, but the Menu indicator and list filters still display the count.

Screenshot

CleanShot 2025-10-15 at 18 32 25

@t-hamano
Copy link
Contributor

t-hamano commented Oct 15, 2025

I just tested the filter. It works for the list table items, but the Menu indicator and list filters still display the count.

@Mamaduka You're right. Additionally, there appear to be other items that need to be addressed.

cc @swissspidy

comment

@t-hamano
Copy link
Contributor

Based on this feedback, we added type__not_in directly to the WP_Comments_List_Table class, rather than directly manipulating the database WHERE clause.

Can we apply a similar approach to this PR? In other words, we should be able to use the comments_list_table_query_args hook.

I just tested the filter. It works for the list table items, but the Menu indicator and list filters still display the count.

In the core backport PR, I was able to address this issue by adding a type__not_in query in the get_comment_coint() function.

https://github.com/WordPress/wordpress-develop/pull/10280/files#diff-2b8fe4b1429ba7f3a26288d345bbffe07feed5bd7ee515ad139f844a1d3c14a2R420

However, the query parameters of the get_comment_count() function are not filterable, so using pre_get_comments might be our only option in Gutenberg 🤔

@swissspidy swissspidy changed the title Fast follow: Ensure block comments filter does not affect susequent queries. Fast follow: Ensure block comments filter does not affect subsequent queries Oct 18, 2025
@jeffpaul jeffpaul added the Backport to WP 6.9 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 27, 2025
@t-hamano
Copy link
Contributor

t-hamano commented Nov 3, 2025

As I understand it, this PR is an improvement for the Gutenberg plugin and does not affect the core, so I will remove the Backport to WP 6.9 Beta/RC label.

@peterwilsoncc @adamsilverstein I have resolved the conflicts for now, but I would like to confirm whether this PR is still valid.

@t-hamano t-hamano added Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts and removed Backport to WP 6.9 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Nov 3, 2025
@t-hamano
Copy link
Contributor

t-hamano commented Nov 5, 2025

This is an issue within the Gutenberg plugin, so let's address it in a point update.

@Mamaduka
Copy link
Member

Mamaduka commented Nov 5, 2025

The plugin-specific issues don't have to be in WP-specific milestones.

@jeffpaul
Copy link
Member

@Mamaduka reminder ping on this PR as something impacting the Gutenberg plugin specifically (i.e. not needed for WP 6.9 as not impacting WP Core)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Bug An existing feature does not function as intended

Projects

Status: 🐛 Punted to 6.9.1

Development

Successfully merging this pull request may close these issues.

exclude_block_comments_from_admin filter affects subsquent queries.

7 participants