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 21 commits into
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. |
westonruter
left a comment
There was a problem hiding this comment.
Thank you. Let's queue this up for commit in 7.1 once trunk is unfrozen.
This reverts commit 539c53a.
|
Review from Claude: I have enough to finalize. Let me verify one convention point: Here's my review of PR #11568. Review SummaryThe change adds validation/normalization of oEmbed providers (a new Findings1. Constructor narrows the provider tuple shape — drops extra data plugins may have stored ( 2. 3. Test mutates the shared oEmbed singleton without cleanup ( 4. Malformed providers added post-construction are silently skipped, no 5. Dead reassignment ( No correctness/crash bugs survived — the validation logic itself (empty-string checks, |
Mutate a local instance rather than the shared singleton returned by _wp_oembed_get_object(), which is a function-static that is not reset between tests. This prevents the test provider from leaking into subsequent tests in the same process. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This isn't really a concern. Any extra array items will be dropped from being stored in the
True, but since
Fixed in f51d63e.
Adding providers in this way is non-standard, and emitting
This is invalid. We're using the value returned by the sanitize method in case it does any other mutations in the future. |
A plugin may register an oEmbed provider through the `oembed_providers` filter using a malformed structure, such as an associative array rather than the expected tuple of a provider endpoint URL string at index 0 and an optional boolean regex flag at index 1. This previously produced `Undefined array key` PHP warnings when `WP_oEmbed::get_provider()` destructured the entry. Introduce a private `sanitize_provider()` method that validates the match pattern and provider data, normalizing the optional regex flag to a boolean. The constructor now skips malformed entries and reports each one via `_doing_it_wrong()`, and `get_provider()` likewise ignores any invalid entries it encounters at runtime. Developed in #11568. Props sukhendu2002, westonruter, bradshawtm, rollybueno. Fixes #65068. git-svn-id: https://develop.svn.wordpress.org/trunk@62501 602fd350-edb4-49c9-b593-d223f7449a82
A plugin may register an oEmbed provider through the `oembed_providers` filter using a malformed structure, such as an associative array rather than the expected tuple of a provider endpoint URL string at index 0 and an optional boolean regex flag at index 1. This previously produced `Undefined array key` PHP warnings when `WP_oEmbed::get_provider()` destructured the entry. Introduce a private `sanitize_provider()` method that validates the match pattern and provider data, normalizing the optional regex flag to a boolean. The constructor now skips malformed entries and reports each one via `_doing_it_wrong()`, and `get_provider()` likewise ignores any invalid entries it encounters at runtime. Developed in WordPress/wordpress-develop#11568. Props sukhendu2002, westonruter, bradshawtm, rollybueno. Fixes #65068. Built from https://develop.svn.wordpress.org/trunk@62501 git-svn-id: http://core.svn.wordpress.org/trunk@61782 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.