Opened 2 months ago
Closed 2 months ago
#64784 closed defect (bug) (fixed)
Refactor: Remove unnecessary false check in oEmbed data fetching
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Embeds | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
The get_data() method of the WP_oEmbed class contains an unnecessary return:
<?php public function get_data( $url, $args = '' ) { // ... if ( false === $data ) { return false; } return $data; }
We can remove the false check, and only return $data.
Change History (7)
This ticket was mentioned in PR #11126 on WordPress/wordpress-develop by @Soean.
2 months ago
#1
- Keywords has-patch added
#3
@
2 months ago
Tested in latest trunk. Verified YouTube and Vimeo embeds in the block editor and frontend. No regressions, PHP warnings, or console errors observed. Functionality works as expected after the refactor.
This ticket was mentioned in Slack in #core-test by r1k0. View the logs.
2 months ago
#5
@
2 months ago
Patch Testing Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/11126.diff
Environment
- WordPress: 7.0-beta2-20260303.130610
- PHP: 7.4.33
- Server: PHP.wasm
- Database: WP_SQLite_Driver (Server: 8.0.38 / Client: 3.51.0)
- Browser: Firefox 148.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.1
Steps taken
- Created an mu-plugin (
wp-content/mu-plugins/test-oembed-get-data.php) to directly callWP_oEmbed::get_data()and inspect the return values before and after applying the patch.
<?php add_action( 'admin_init', function () { if ( ! isset( $_GET['test-oembed'] ) ) { return; } $oembed = _wp_oembed_get_object(); // Test 1: Valid oEmbed URL. $valid = $oembed->get_data( 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' ); // Test 2: Invalid / non-embeddable URL. $invalid = $oembed->get_data( 'https://example.com/not-embeddable' ); echo '<h2>oEmbed get_data() Test</h2>'; echo '<h3>Test 1 – Valid URL (YouTube)</h3>'; echo '<pre>'; var_dump( $valid ); echo '</pre>'; echo '<h3>Test 2 – Invalid URL</h3>'; echo '<pre>'; var_dump( $invalid ); echo '</pre>'; exit; });
- Visited
wp-admin/?test-oembed=1before the patch and recorded the output. - Applied the patch.
- Visited
wp-admin/?test-oembed=1after the patch and compared.
Expected outcome
- ✅ The patch should keep the return data unchanged.
- ✅ Valid oEmbed URL returns an object with embed data (type, title, html, etc.) — identical before and after.
- ✅ Invalid URL returns
bool(false)— identical before and after. - ✅ No PHP notices, warnings, or errors introduced.
Additional Notes
- This patch is a code simplification only. The removed intermediate variable
$dataand thefalse === $datacheck were redundant since$this->fetch()already returnsfalseon failure. Returning its result directly is functionally identical. - Networking must be available for the valid URL test to succeed (oEmbed fetches an external provider).
Note: See
TracTickets for help on using
tickets.
This pull request makes a small change to the
get_datamethod inclass-wp-oembed.php, simplifying the method by removing an unnecessary conditional check before returning the fetched data.Trac ticket: https://core.trac.wordpress.org/ticket/64784