Skip to content

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Sep 14, 2025

See WordPress/gutenberg#71271

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


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@adamsilverstein adamsilverstein changed the title Add/comment rest api types support Comment REST API route: add support for status as array Sep 15, 2025
@adamsilverstein adamsilverstein marked this pull request as ready for review September 15, 2025 05:18
Copy link

github-actions bot commented Sep 15, 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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein, swissspidy, timothyblynjacobs, mukesh27, wildworks.

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

@adamsilverstein adamsilverstein changed the title Comment REST API route: add support for status as array Comment REST API route: add support multiple statuses Sep 15, 2025
@t-hamano
Copy link

We might not need to extend the REST API itself. See WordPress/gutenberg#71271 (comment)

Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
@adamsilverstein
Copy link
Member Author

adamsilverstein commented Sep 15, 2025

We might not need to extend the REST API itself. See WordPress/gutenberg#71271 (comment)

Good point; that said its probably worth adding as its a simple change and reflects what the underlying core comments class already supports (so it feels like a bug or oversight that it isn't supported already). While we don't need it yet, I could easily see us or a plugin wanting this.

$query_params['status'] = array(
'default' => 'approve',
'description' => __( 'Limit result set to comments assigned a specific status. Requires authorization.' ),
'sanitize_callback' => 'sanitize_key',
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 an issue since it only does anything for strings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I'll expand this to handle arrays based on what we do in posts. Should be straightforward to recuse existing code for each item.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added handling in 5fba5f6 calling sanitize_key for each status.

Copy link
Member Author

@adamsilverstein adamsilverstein Sep 15, 2025

Choose a reason for hiding this comment

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

Actually @TimothyBJacobs I'm not sure we need this -

  • sanitization only called when creating or updating a comment - in this case we should still only accept a single status value, right? sanitize_key would throw an error, maybe thats what we want?

Also, while writing tests, I noticed as far as I can see we already strictly enforce status values from a list in WP_Test_REST_Comments_Controller::handle_status_param. Shouldn't the endpoint accept custom status values like 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.

handle_status_param is for the writes though, right? This is the arg list for the query parameters so they'd be a bit different.

Are custom comment status really supported by Core? wp_get_comment_status makes it seem like the list is fixed.

We should probably have an enum keyword with all of the supported statuses I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the feedback @TimothyBJacobs

We don't need this immediately so I am deprioritizing it for the moment.

…roller.php

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
@adamsilverstein adamsilverstein changed the title Comment REST API route: add support multiple statuses [WIP] Comment REST API route: add support multiple statuses Sep 18, 2025
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.

5 participants