Skip to content

Conversation

t-hamano
Copy link

@t-hamano t-hamano commented Oct 15, 2025

This PR updates the core codebase to allow the Notes feature to work properly.

Trac ticket: https://core.trac.wordpress.org/ticket/64096

Note

This PR also includes #9869. Don't forget to add the following prop when committing to core:

Props ristojovanovic, adamsilverstein, jeffpaul.

@t-hamano t-hamano force-pushed the 64096-notes-backport branch from 004f7fb to e08eea2 Compare October 15, 2025 07:35
@t-hamano t-hamano changed the title Notes: Update comments rest API Incorporating foundation of "Notes" feature Oct 15, 2025
@t-hamano
Copy link
Author

Ok, I believe backporting PHP should be all done. Next, I'll try to fix the failing tests.

@Mamaduka
Copy link
Member

Ok, I believe backporting PHP should be all done. Next, I'll try to fix the failing tests.

I think we're missing the Notes-specific unit tests.

$post_id_in = "'" . implode( "', '", $post_id_array ) . "'";

$pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A );
$pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' AND comment_type != 'note' GROUP BY comment_post_ID", ARRAY_A );
Copy link
Member

Choose a reason for hiding this comment

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

There's another PR for get_pending_comments_num changes - #9869.

Just noting for props.

Copy link
Member

Choose a reason for hiding this comment

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

Not a fan of hardcoding comment types. Long term we should think about using a filterable list of comment types to exclude or using (an improved) WP_Comment_Query

Copy link
Member

Choose a reason for hiding this comment

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

100%. I think a long-term solution is to provide proper support for custom comment types, so we can avoid hardcoded patches like we've introduced with the current implementation.

@t-hamano t-hamano force-pushed the 64096-notes-backport branch from 48d0ba7 to b351ddb Compare October 15, 2025 11:15
*/
$dupe_id = apply_filters( 'duplicate_comment_id', $dupe_id, $commentdata );

// Allow duplicate notes for resolution purposes.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this should happen after the apply_filters call. Seems like we'd want to let developers customize behavior here.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, I'd prefer we keep this filterable.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in a43a2b0

*
* @since 6.9.0
*/
function wp_register_notes_metadata() {
Copy link
Member

Choose a reason for hiding this comment

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

I'd model this closer to wp_create_initial_post_meta, so wp_create_initial_comment_meta. Future additions would be added into that one function, instead of splitting each registration into it's own function.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 48cb687

Comment on lines 4131 to 4133
'auth_callback' => function ( $allowed, $meta_key, $object_id ) {
return current_user_can( 'edit_comment', $object_id );
},
Copy link
Member

Choose a reason for hiding this comment

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

This is already the default behavior applied by map_meta_cap, I believe this is just resulting in a duplicate check,

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 278d274

@TimothyBJacobs
Copy link
Member

Ditto all the feedback about wishing we had a fleshed out comment types API about now. But I think this looks pretty reasonable.

@WordPress WordPress deleted a comment from new372957-sudo Oct 15, 2025
'count' => true,
'update_comment_meta_cache' => false,
'orderby' => 'none',
'type__not_in' => array( 'note' ),
Copy link
Author

Choose a reason for hiding this comment

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

This is necessary to filter out Note-type comments from the dashboard. Otherwise, the dashboard shows unintended counts.

Image

@swissspidy
Copy link
Member

Curious, does this work well with WP-CLI out of the box when dealing with comments?

@WordPress WordPress deleted a comment from ziyaab337-eng Oct 16, 2025
@Mamaduka
Copy link
Member

Curious, does this work well with WP-CLI out of the box when dealing with comments?

Do you have any particular concerns, @swissspidy? I've only used WP-CLI to clean up test data or migrate notes after the type change. It worked perfectly.

@t-hamano, what are the remaining blockers here?

@t-hamano
Copy link
Author

@t-hamano, what are the remaining blockers here?

I think I've addressed all the feedback.

@swissspidy swissspidy self-requested a review October 17, 2025 09:40
@Mamaduka Mamaduka requested review from TimothyBJacobs and kadamwhite and removed request for kadamwhite October 17, 2025 13:19
Copy link
Member

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

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

Great!

Left one small comment feedback

Co-authored-by: Adam Silverstein <[email protected]>
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

It seems all the feedback has been addressed.

@t-hamano or @adamsilverstein, are you planning to handle the commit?

@t-hamano
Copy link
Author

I haven't committed to core yet, so I'd be happy if someone could do that 😅 That said, I'd like to set up an SVN environment, understand the core committer workflow, and try my hand at committing within the 6.9 cycle.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants