Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove audio & video methods from Post #2750

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 0 additions & 44 deletions src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1892,50 +1892,6 @@ public function gallery($html = true)
return apply_filters('get_post_gallery', $gallery, $this->ID, $galleries);
}

/**
* Returns audio tags embedded in the post鈥檚 content.
*
* @api
* @example
* ```twig
* {{ post.audio }}
* ```
* @return bool|array A list of found HTML embeds.
*/
public function audio()
{
$audio = false;

// Only get audio from the content if a playlist isn鈥檛 present.
if (!str_contains($this->content(), 'wp-playlist-script')) {
$audio = get_media_embedded_in_content($this->content(), ['audio']);
}

return $audio;
}

/**
* Returns video tags embedded in the post鈥檚 content.
*
* @api
* @example
* ```twig
* {{ post.video }}
* ```
* @return bool|array A list of found HTML embeds.
*/
public function video()
{
$video = false;

// Only get video from the content if a playlist isn't present.
if (!str_contains($this->content(), 'wp-playlist-script')) {
$video = get_media_embedded_in_content($this->content(), ['video', 'object', 'embed', 'iframe']);
}

return $video;
}

protected function get_entity_name()
{
return 'post';
Expand Down
68 changes: 0 additions & 68 deletions tests/test-timber-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1075,74 +1075,6 @@ public function testPostWithoutGallery()
$this->assertSame(false, $post->gallery());
}

public function testPostWithoutAudio()
{
$pid = $this->factory->post->create();
$post = Timber::get_post($pid);

$this->assertEquals([], $post->audio());
}

public function testPostWithAudio()
{
$quote = 'Named must your fear be before banish it you can.';
$quote .= '[embed]http://www.noiseaddicts.com/samples_1w72b820/280.mp3[/embed]';
$quote .= "No, try not. Do or do not. There is no try.";

$pid = $this->factory->post->create([
'post_content' => $quote,
]);
$post = Timber::get_post($pid);
$expected = 'http://www.noiseaddicts.com/samples_1w72b820/280.mp3';

$this->assertStringContainsString($expected, $post->audio()[0]);
$this->assertStringStartsWith('<audio', $post->audio()[0]);
}

public function testPostWithAudioCustomField()
{
$quote = 'Named must your fear be before banish it you can.';
$quote .= '[embed]http://www.noiseaddicts.com/samples_1w72b820/280.mp3[/embed]';
$quote .= "No, try not. Do or do not. There is no try.";

$pid = $this->factory->post->create([
'post_content' => $quote,
]);
update_post_meta($pid, 'audio', 'foo');
$expected = 'http://www.noiseaddicts.com/samples_1w72b820/280.mp3';
$post = Timber::get_post($pid);
$this->assertStringContainsString($expected, $post->audio()[0]);
$this->assertStringStartsWith('<audio', $post->audio()[0]);
}

public function testPostWithoutVideo()
{
$pid = $this->factory->post->create();
$post = Timber::get_post($pid);

$this->assertEquals([], $post->video());
}

public function testPostWithVideo()
{
$quote = 'Named must your fear be before banish it you can.';
$quote .= '[embed]https://www.youtube.com/watch?v=Jf37RalsnEs[/embed]';
$quote .= "No, try not. Do or do not. There is no try.";

$pid = $this->factory->post->create([
'post_content' => $quote,
]);
$post = Timber::get_post($pid);

$video = $post->video();
if (is_array($video)) {
$video = array_shift($video);
}
$expected = '/<iframe [^>]+ src="https:\/\/www\.youtube\.com\/embed\/Jf37RalsnEs\?feature=oembed" [^>]+>/i';
$this->assertMatchesRegularExpression($expected, $video);
;
}

public function testPathAndLinkWithPort()
{
/* setUp */
Expand Down