Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#45142 closed defect (bug) (fixed)

Filter HTML response in oEmbed proxy controller

Reported by: swissspidy's profile swissspidy Owned by: danielbachhuber's profile danielbachhuber
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: Embeds Keywords: has-patch has-unit-tests fixed-5.0
Focuses: rest-api Cc:

Description

Related: #43136, https://github.com/WordPress/gutenberg/pull/4226 (especially https://github.com/WordPress/gutenberg/pull/4226#pullrequestreview-91060412)

The Gutenberg plugin currently contains a custom gutenberg_filter_oembed_result() function that alters the response from WP_oEmbed_Controller::get_proxy_item() so that the response is correctly filtered and embeds work properly in the block editor.

For WordPress 5.0, the code from that function needs to be moved directly to WP_oEmbed_Controller::get_proxy_item() in order to fix that behavior.

Attachments (3)

45142.diff (4.6 KB) - added by swissspidy 6 years ago.
45142.2.diff (13.2 KB) - added by swissspidy 6 years ago.
45142.3.diff (15.7 KB) - added by danielbachhuber 6 years ago.

Download all attachments as: .zip

Change History (16)

This ticket was mentioned in Slack in #core-restapi by swissspidy. View the logs.


6 years ago

@swissspidy
6 years ago

#3 @swissspidy
6 years ago

  • Focuses rest-api added
  • Keywords has-patch dev-feedback added; needs-patch removed

In 45142.diff:

  • Extract most logic from wp_filter_pre_oembed_result() into new get_oembed_response_data_for_url() function so it can be more easily reused.
  • Short-circuit proxy response for internal URLs using get_oembed_response_data_for_url()
  • Add same oembed_result filter as for other embeds

@pento @imath would love to get your thoughts on this.

This ticket was mentioned in Slack in #core-restapi by danielbachhuber. View the logs.


6 years ago

#5 @swissspidy
6 years ago

  • Keywords needs-testing needs-unit-tests added

#6 @imath
6 years ago

Hi @swissspidy

Thanks a lot for the ping. I've just tested the patch using branch 5.0 & Gutenberg master.

  • I've first tested without it: a self embed post is working as expected
  • then I've tested with it, running grunt build as grunt watch wasn't applying the part of the patch involving src/wp-includes/class-wp-oembed-controller.php: it worked as expected too.

The only weird thing for both tests were the huge place taken by the block's placeholder > https://cloudup.com/iAIcSlHQMfj But I guess it's not related to this ticket.

About my thoughts: I think it's a good idea, correct me if I'm wrong but this means having the new get_oembed_response_data_for_url() would make it directly usable with a WordPress URL, right ? It seems very interesting :)

Thanks a lot for your work on this.

This ticket was mentioned in Slack in #core-restapi by desrosj. View the logs.


6 years ago

@swissspidy
6 years ago

#8 follow-up: @swissspidy
6 years ago

About my thoughts: I think it's a good idea, correct me if I'm wrong but this means having the new get_oembed_response_data_for_url() would make it directly usable with a WordPress URL, right ? It seems very interesting :)

Yep, that is an intended nice effect of that patch :-)


As for the patch, I tried to add some tests in 45142.2.diff, but since it's already late here I couldn't make the last test work that should verify the newly added oembed_result filter in the proxy endpoint.

#9 in reply to: ↑ 8 @danielbachhuber
6 years ago

  • Keywords has-unit-tests added; needs-testing needs-unit-tests removed

Replying to swissspidy:

As for the patch, I tried to add some tests in 45142.2.diff, but since it's already late here I couldn't make the last test work that should verify the newly added oembed_result filter in the proxy endpoint.

@swissspidy I'm not quite sure what you mean by this because 45142.2.diff included:

$this->markTestIncomplete( 'Need to test that the resulting HTML is passed through the oembed_dataparse filter' );

Note: oembed_dataparse instead of oembed_result.

In 45142.3.diff, I've added some assertions around the expected calls to oembed_result. I also fixed the PHPDoc for oembed_result, because $data can be false.

Tests running in https://github.com/WordPress/wordpress-develop/pull/26

#10 @danielbachhuber
6 years ago

  • Owner set to danielbachhuber
  • Resolution set to fixed
  • Status changed from new to closed

In 43810:

Embeds: Filter HTML response in oEmbed proxy controller.

Adapts the response from WP_oEmbed_Controller::get_proxy_item() so that the response is correctly filtered and embeds work properly in JavaSccript editors. Introduces new get_oembed_response_data_for_url() function for preparing internal oEmbed responses.

Props danielbachhuber, imath, swissspidy.
Fixes #45142.

#11 @danielbachhuber
6 years ago

  • Keywords fixed-5.0 added; dev-feedback removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for merge to trunk.

#12 @notnownikki
6 years ago

@imath

The only weird thing for both tests were the huge place taken by the block's placeholder > https://cloudup.com/iAIcSlHQMfj But I guess it's not related to this ticket.

And it's fixed by https://github.com/WordPress/gutenberg/pull/10985 :)

#13 @pento
6 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 44154:

Embeds: Filter HTML response in oEmbed proxy controller.

Adapts the response from WP_oEmbed_Controller::get_proxy_item() so that the response is correctly filtered and embeds work properly in JavaSccript editors. Introduces new get_oembed_response_data_for_url() function for preparing internal oEmbed responses.

Merges [43810] from the 5.0 branch to trunk.

Props danielbachhuber, imath, swissspidy.
Fixes #45142.

Note: See TracTickets for help on using tickets.