Make WordPress Core

Opened 5 weeks ago

Last modified 4 weeks ago

#60783 accepted defect (bug)

plugins_api() and parameters

Reported by: juliobox's profile juliobox Owned by: audrasjb's profile audrasjb
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: Plugins Keywords: needs-patch good-first-bug
Focuses: docs Cc:

Description

Hello there, (running WP6.5+, might be useless to say)
By reading the doc for plugins_api() you can read that some fields are included or not in the response, the doc says "$fields: Array of fields which should or should not be returned." and then you have a list of fields, some true some false by default.
Let's try it, this is my simple request on my plugin on repo:

<?php
require ABSPATH . 'wp-admin/includes/plugin-install.php';
$api = plugins_api(
        'plugin_information',
        array(
                'slug'   => 'secupress',
                'fields' => []
        )
);

Since the doc says "@type bool $contributors Whether to return the list of contributors. Default false." I should not receive this field.
Let see the response:

<?php
object(stdClass)#1010 (32) {
  ["name"]=>
  string(37) "SecuPress Free — WordPress Security"
  ["slug"]=>
  string(9) "secupress"
  ["version"]=>
  string(7) "2.2.5.1"
  ["author"]=>
  string(44) "SecuPress"
  ["author_profile"]=>
  string(41) "https://profiles.wordpress.org/secupress/"
  ["contributors"]=>
  array(4) {
...

There is. Same for those params that are "false" by default but still included: "sections", "versions", "reviews", "banners", "active_installs" (I don't know for "group", can't get the thing).

Also there is one param that is not affected by the arguments passed and always returned: "num_ratings".

Finally there is some fields that are always returned where the doc can't help, I tried to use they array keys to cancel them, no chance, this is : "author', "author_profile" (those 2 may be forced, that's ok), "support_threads", "support_threads_resolved", "upgrade_notice", and "requires_plugin" (I know it's new, but don't forget it)

The patch may have to be done on w.org since this is the site that add too much data and to not respect the passed parameters.

Thanks for your time

Change History (2)

#1 @audrasjb
5 weeks ago

  • Keywords good-first-bug added
  • Milestone changed from Awaiting Review to 6.6
  • Owner set to audrasjb
  • Status changed from new to accepted
  • Version trunk deleted

Thanks for the ticket, markking as good-first-bug for new contributors.

#2 @dd32
4 weeks ago

Just noting that the underlying API is fairly stable; but the default returned parameters differ between API endpoint requested (version + action), some are dependant upon one another, others will be returned no matter what the client specifies, some are dependant upon the WP version, etc

The API in question is bootstrapped by this code which manages the fields parameter:
https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api-request.php

The API may change in behaviour (including fields returned, and the format of them) if WordPress gracefully handles the new data (and in the case of extra fields, it's never an issue).

Note: See TracTickets for help on using tickets.