Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions inc/shortcodes/class-livestream.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public static function get_shortcode_ui_args() {
'type' => 'text',
'description' => esc_html__( 'Full URL to the Livestream', 'shortcake-bakery' ),
),
array(
'label' => esc_html__( 'Disable autoplay?', 'shortcake-bakery' ),
'attr' => 'disableautoplay',
'type' => 'checkbox',
'description' => esc_html__( 'Livestream embeds autoplay by default.', 'shortcake-bakery' ),
),
),
);
}
Expand Down Expand Up @@ -50,6 +56,11 @@ public static function callback( $attrs, $content = '' ) {
if ( false === stripos( substr( $attrs['url'], strlen( $attrs['url'] ) - 8 ), '/player' ) ) {
$attrs['url'] = rtrim( $attrs['url'], '/' ) . '/player/';
}

if ( ! empty( $attrs['disableautoplay'] ) ) {
$attrs['url'] = add_query_arg( 'autoPlay', 'false', $attrs['url'] );
}

return sprintf( '<iframe class="shortcake-bakery-responsive" width="560" height="315" src="%s" frameborder="0"></iframe>', esc_url( $attrs['url'] ) );
}

Expand Down
6 changes: 6 additions & 0 deletions tests/test-livestream-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ public function test_post_display() {
$this->assertContains( '<iframe class="shortcake-bakery-responsive" width="560" height="315" src="http://new.livestream.com/accounts/9035483/events/3424523/videos/64460770/player/" frameborder="0"></iframe>', apply_filters( 'the_content', $post->post_content ) );
}

public function test_post_display_no_autoplay() {
$post_id = $this->factory->post->create( array( 'post_content' => '[livestream url="http://new.livestream.com/accounts/9035483/events/3424523/videos/64460770/" disableautoplay="true" ]' ) );
$post = get_post( $post_id );
$this->assertContains( '<iframe class="shortcake-bakery-responsive" width="560" height="315" src="http://new.livestream.com/accounts/9035483/events/3424523/videos/64460770/player/?autoPlay=false" frameborder="0"></iframe>', apply_filters( 'the_content', $post->post_content ) );
}

public function test_embed_reversal() {
$old_content = <<<EOT

Expand Down