131808ed |
1 | <?php |
2 | |
3 | defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
4 | |
5 | /* |
6 | Plugin Name: danixland asciinema shortcode |
7 | Description: A simple shortcode plugin to embed videos from <a href="https://asciinema.org">asciinema.org</a> |
8 | Plugin URI: http://danixland.net/?p=3525 |
9 | Version: 0.1 |
10 | Author: Danilo 'danix' Macrì |
11 | Author URI: http://danixland.net |
12 | License: GPL2 |
13 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
14 | */ |
15 | |
16 | /* |
17 | * The actual video displayed using a shortcode |
18 | * @since 0.1 |
19 | */ |
20 | function dnxasc_display_video( $atts ) { |
21 | // Attributes |
22 | extract( shortcode_atts( |
23 | array( |
24 | 'video' => '22124', |
25 | 'time' => '0', |
26 | 'autoplay' => false, |
27 | 'loop' => false, |
28 | 'speed' => 1, |
29 | 'theme' => 'monokai' |
30 | ), $atts ) |
31 | ); |
32 | |
33 | $autoplay = ( 0 != $time ) ? true : false; |
34 | $videoscript = '<script type="text/javascript" src="https://asciinema.org/a/'; |
35 | $videoscript .= $video . '.js" id="asciicast-' . $video . '" async '; |
36 | $videoscript .= 'data-t="' . $time . '" data-autoplay="' . $autoplay . '" '; |
37 | $videoscript .= 'data-loop="' . $loop . '" data-speed="' . $speed . '" data-theme="' . $theme . '">'; |
38 | $videoscript .= '</script>'; |
39 | |
40 | return $videoscript; |
41 | } |
42 | add_shortcode( 'asciinema', 'dnxasc_display_video' ); |