-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Attachments Controller: Allow strings as media_type #73626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
What I can see is that #73029 was never backported to Gutenberg But that only has a bearing on whether arrays AND strings are accepted for If a site is running WordPress 6.8 then strings are fine. |
BTW we should do this cc @tellthemachines ? |
| $params['media_type'] = array( | ||
| 'default' => null, | ||
| 'description' => __( 'Limit result set to attachments of a particular media type or media types.' ), | ||
| 'type' => 'array', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this convo over in the Core patch: WordPress/wordpress-develop#10054 (comment)
Incoming strings will be coerced to arrays. This code matches Core so it should be okay.
Did you manage to reproduce the bug anywhere in Core?
| $params['mime_type'] = array( | ||
| 'default' => null, | ||
| 'description' => __( 'Limit result set to attachments of a particular MIME type or MIME types.' ), | ||
| 'type' => 'array', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
|
Thanks @mikachan for getting this PR up so quickly ❤️ Did you manage to reproduce the bug in Core? If so, could you share the testing steps. I'm struggling to reproduce
Withdraw that please! It was only PHP files and nothing to do with packages. |
I'm unable to reproduce either. At least in theory, we shouldn't need to check whether it's a string, as the schema should be handling the coercion to an array. I.e. in core, for an array in the schema, rest_validate_array_value_from_schema handles sanitizing the value, which calls rest_sanitize_array, which handles wrapping / parsing into a list via wp_parse_list.... so by the time we're in |
|
Thanks so much @ramonjd and @andrewserong for testing this and reporting back in such detail. I'm also struggling to reproduce this bug.
Based on this, I don't think we need this PR at all. Sorry for the false alarm! |
Can we close this PR? |

What?
In #73029, we introduced
arrayas amedia_type. This is a breaking change, as previously these were only allowed as astring, breaking any existing implementations. This PR allows bothstringandarrayformedia_type.Do we need to make any changes elsewhere to support this? Also, I assume this will need to be backported to WP 6.9.
Why?
Allow backwards compatibility.
How?
Allow for both arrays and strings.
Testing Instructions