Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Not passing args to $wpdb->prepare causes PHP notice to show which breaks API requests #5159

Closed
opr opened this issue Nov 16, 2021 · 0 comments · Fixed by #5471
Closed

Not passing args to $wpdb->prepare causes PHP notice to show which breaks API requests #5159

opr opened this issue Nov 16, 2021 · 0 comments · Fixed by #5471
Assignees
Labels
focus: rest api Work impacting REST api routes. type: bug The issue/PR concerns a confirmed bug. type: good first issue The issue is a good candidate for the first community contribution/for a newcomer to the team.

Comments

@opr
Copy link
Contributor

opr commented Nov 16, 2021

Describe the bug

When you have error reporting turned on, calls to $wpdb->prepare causes notices to print which breaks API requests, for example:

https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/a4602f8be133bcc6072cd691693f2ea0fffca0d1/src/StoreApi/Schemas/ProductCategorySchema.php#L115

is missing 2nd...nth arguments, which causes this error: PHP Notice: Undefined offset: 0 in /var/www/html/wp-includes/wp-db.php on line 1323

We should check usages of this function and make it so we pass additional args to it.

To reproduce

Steps to reproduce the behavior:

  1. Ensure your site is set up to report notices
  2. Try to add a Featured Category block to the editor
  3. Notice the API errors
  4. Check the network log and see the error PHP Notice: Undefined offset: 0 in /var/www/html/wp-includes/wp-db.php on line 1323 printed in the API response.

Expected behavior

No notices should be printed in the API Response.

Screenshots

Environment

Happens in both PHP 8.0 and 7.4

WordPress (please complete the following information):

  • Core version: [e.g. 5.0.3] 5.8.2
  • Gutenberg version (if installed): [e.g. 4.8.0] n/a
  • WooCommerce version: [e.g. 3.5.3] 5.9
  • WooCommerce Blocks version: [e.g. 1.3.1] 6.3.0-dev
  • Site language: en
  • Any other plugins installed: nothing unusual

Desktop (please complete the following information):

  • OS: [e.g. macOS, Windows]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]
@opr opr added type: bug The issue/PR concerns a confirmed bug. focus: rest api Work impacting REST api routes. labels Nov 16, 2021
@opr opr changed the title Not passing args to $wpdb->prepare causes PHP notice to show which breaks API requests Not passing args to $wpdb->prepare causes PHP notice to show which breaks API requests Nov 16, 2021
@Aljullu Aljullu added the type: good first issue The issue is a good candidate for the first community contribution/for a newcomer to the team. label Nov 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: rest api Work impacting REST api routes. type: bug The issue/PR concerns a confirmed bug. type: good first issue The issue is a good candidate for the first community contribution/for a newcomer to the team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants