oEmbed: Fix PHP warnings when a registered provider is malformed#11568
oEmbed: Fix PHP warnings when a registered provider is malformed#11568Sukhendu2002 wants to merge 10 commits intoWordPress:trunkfrom
Conversation
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| list( $providerurl, $regex ) = $data; | ||
| $providerurl = $data[0]; | ||
| $regex = $data[1] ?? false; |
There was a problem hiding this comment.
I think this can be reverted.
There was a problem hiding this comment.
I kept the defensive $data[0] / $data[1] ?? false instead of reverting to list(). In PHP 8+, list($a, $b) = array('url') throws a warning for undefined offsets. Since $this->providers is a public property, external code (and our own test_get_provider_handles_provider_without_regex_flag) can directly assign single-element arrays to it.
There was a problem hiding this comment.
Well, in that case who's to say that $data[0] even exists or that it is an array?
There was a problem hiding this comment.
I suggest adding a new private method, like get_provider( $data ) which returns either array{ endpoint: string, is_regex: bool } or else null if it was too malformed to format. This can take care of (bool) ( $data[1] ?? false ) as well as checking if the data is an array and the first argument is a string. This same method can be used both here and when populating the variable with the return of the oembed_providers filter.
Then the list() can still be eliminated asn we can just access $provider['endpoint'] and $provider['is_regex'] as opposed to creating new variables.
There was a problem hiding this comment.
er, get_provider is a bad name because it is used already! Maybe sanitize_provider() or format_provider() or prepare_provider() or something.
There was a problem hiding this comment.
Good point! Added a private sanitize_provider() method.
Trac ticket: https://core.trac.wordpress.org/ticket/65068
Use of AI Tools
AI assistance: No
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.