Skip to content

Commit

Permalink
Rename function to allow for non-oembed emebds to be generated
Browse files Browse the repository at this point in the history
  • Loading branch information
srtfisher committed Jul 25, 2024
1 parent f8c037a commit fce40b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/class-block-converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,19 @@ protected function p( DOMNode $node ): ?Block {
if ( \str_contains( $node->textContent, '//x.com' ) || \str_contains( $node->textContent, '//www.x.com' ) ) {
$node->textContent = str_replace( 'x.com', 'twitter.com', $node->textContent );
}

// Instagram and Facebook embeds require an api key to retrieve oEmbed data.
if ( \str_contains( $node->textContent, 'instagram.com' ) ) {
return $this->instagram_embed( $node->textContent );
}

if ( \str_contains( $node->textContent, 'facebook.com' ) ) {
return $this->facebook_embed( $node->textContent );
}

// Check if the URL is an oEmbed URL and return the oEmbed block if it is.
if ( false !== wp_oembed_get( $node->textContent ) ) {
return $this->embed( $node->textContent );
return $this->oembed( $node->textContent );
}
}

Expand Down Expand Up @@ -270,7 +274,7 @@ protected function ol( DOMNode $node ): Block {
* @param string $url The URL.
* @return Block
*/
protected function embed( string $url ): Block {
protected function oembed( string $url ): Block {
// This would probably be better as an internal request to /wp-json/oembed/1.0/proxy?url=...
$data = _wp_oembed_get_object()->get_data( $url, [] );

Expand Down
9 changes: 9 additions & 0 deletions tests/feature/BlockConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ public function test_tiktok_url_to_embed() {
);
}

public function test_non_oembed_embed() {
$converter = new Block_Converter( '<embed type="video/webm" src="/media/mr-arnold.mp4" width="250" height="200" />' );

$this->assertEquals(
'<!-- wp:html --><embed type="video/webm" src="/media/mr-arnold.mp4" width="250" height="200"></embed><!-- /wp:html -->',
$converter->convert(),
);
}

public function test_macroable() {
Block_Converter::macro(
'special-tag',
Expand Down

0 comments on commit fce40b7

Please sign in to comment.