Skip to content

oEmbed: Prevent PHP warnings when a registered provider is malformed#48077

Merged
tbradsha merged 2 commits intotrunkfrom
fix/jetpack/prevent_warnings_with_malformed_oembed_providers
Apr 14, 2026
Merged

oEmbed: Prevent PHP warnings when a registered provider is malformed#48077
tbradsha merged 2 commits intotrunkfrom
fix/jetpack/prevent_warnings_with_malformed_oembed_providers

Conversation

@tbradsha
Copy link
Copy Markdown
Contributor

@tbradsha tbradsha commented Apr 13, 2026

Proposed changes

There was a site generating about 10% of Jetpack-related PHP warnings on WP Cloud, all looking like this:

PHP Warning: Undefined array key 0 in /wordpress/plugins/jetpack/15.8-a.1/_inc/lib/class.media-extractor.php on line 352
PHP Warning: Undefined array key 1 in /wordpress/plugins/jetpack/15.8-a.1/_inc/lib/class.media-extractor.php on line 352

As it turned out, they had a plugin that was registering the oEmbed providers like so:

 [provider_key] => Array
    (
        [url] => some_url_regex
        [endpoint] => https://some_site/api/oembed
    )

Instead, it should have been like this:

[some_url_regex] => Array
    (
        [0] => https://some_site/api/oembed
        [1] => 1
    )

This PR adds a continue if index 0 is not set, and uses false for index 1 if not set.

Related product discussion/links

Does this pull request change what data or activity we track or use?

Testing instructions

First, add an mu-plugin:

add_filter(
	'oembed_providers',
	function ( $providers ) {
		$providers['bad_provider'] = array(
			'url'      => '#https?://example\.site/.*#i',
			'endpoint' => 'https://example.site/api/oembed',
		);
		return $providers;
	}
);
  1. Go to a new post page.
  2. Paste a URL that doesn't have an oEmbed, e.g. https://en.wikipedia.org/wiki/Rickrolling
  3. Do NOT click "Convert to link".
  4. Save the post.
  5. Visit the post on the front end.

On `trunk, you'll get an error from Jetpack. On this branch you will not.

Note that refreshing the editor will show a warning from Core; that's reported here:
https://core.trac.wordpress.org/ticket/65068

@tbradsha tbradsha requested review from a team and whyisjake April 13, 2026 21:04
@tbradsha tbradsha self-assigned this Apr 13, 2026
@tbradsha tbradsha added the [Status] Needs Review This PR is ready for review. label Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/jetpack/prevent_warnings_with_malformed_oembed_providers branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/jetpack/prevent_warnings_with_malformed_oembed_providers

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: May 5, 2026
    • Code freeze: May 4, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Apr 13, 2026
@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/_inc/lib/class.media-extractor.php 209/245 (85.31%) -0.29% 1 ❤️‍🩹

Full summary · PHP report · JS report

Copy link
Copy Markdown
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. Haven't tested.

@tbradsha tbradsha merged commit 9cad918 into trunk Apr 14, 2026
76 checks passed
@tbradsha tbradsha deleted the fix/jetpack/prevent_warnings_with_malformed_oembed_providers branch April 14, 2026 18:36
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Apr 14, 2026
@github-actions github-actions bot added this to the jetpack/15.8 milestone Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants