Skip to content

Plugin Directory: Validate the required parameter for the bulk stats update endpoint#579

Closed
obenland wants to merge 1 commit intotrunkfrom
fix/internal-stats-plugins-arg-validation
Closed

Plugin Directory: Validate the required parameter for the bulk stats update endpoint#579
obenland wants to merge 1 commit intotrunkfrom
fix/internal-stats-plugins-arg-validation

Conversation

@obenland
Copy link
Copy Markdown
Member

Summary

  • The /plugins/v1/update-stats endpoint didn't define any argument requirements, so requests missing the plugins parameter would reach the callback and trigger a PHP warning when iterating over a null value.
  • Adds a schema definition that validates the shape and types of the incoming data at the REST API layer, rejecting invalid requests before the callback runs.

Test plan

  • Confirm valid requests with a plugins object still work as expected
  • Confirm requests missing plugins return a REST API validation error instead of triggering a PHP warning

🤖 Generated with Claude Code

…update endpoint.

The endpoint didn't define any argument requirements, so requests
missing the expected data would reach the callback and trigger a
PHP warning when iterating over a null value.

Adds a schema definition that validates the shape and types of the
incoming data at the REST API layer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 31, 2026 15:14
@github-actions
Copy link
Copy Markdown

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 obenland.

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds REST API request-argument validation for the internal plugin stats bulk update endpoint (/plugins/v1/update-stats) so that requests missing the required plugins payload are rejected by the REST layer before the callback executes.

Changes:

  • Defines args for the route and marks plugins as required.
  • Adds a basic JSON-schema-style shape/type definition for each plugin’s stats object (e.g., active_installs, usage, support thread counts).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@obenland obenland requested a review from dd32 March 31, 2026 15:23
@obenland
Copy link
Copy Markdown
Member Author

@dd32 Could I ask for a sanity check for these changes? It doesn't look like the two places calling this endpoint should be bothered by getting an error returned when plugins is empty, but I wanted to double check.

This fixes:

E_WARNING: foreach() argument must be of type array|object, null given in wp-content/plugins/plugin-directory/api/routes/class-internal-stats.php:48
foreach() argument must be of type array|object, null given

$data = $request['plugins'];
foreach ( $data as $plugin_slug => $stats ) {

@bazza bazza closed this Mar 31, 2026
@bazza bazza deleted the fix/internal-stats-plugins-arg-validation branch March 31, 2026 20:12
Copilot AI added a commit to obenland/wordpress.org that referenced this pull request Mar 31, 2026
… and capability fixes

Agent-Logs-Url: https://github.com/obenland/wordpress.org/sessions/96f2f701-fe73-444a-829b-7bb3a541fbea

Co-authored-by: obenland <1398304+obenland@users.noreply.github.com>
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.

3 participants