-
Notifications
You must be signed in to change notification settings - Fork 2
/
class-cloudflare-stream-shortcode.php
91 lines (83 loc) · 1.8 KB
/
class-cloudflare-stream-shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Cloudflare Stream Shortcode class
*
* Legacy support for WordPress shortcodes.
*
* @package cloudflare-stream
* @since 1.0.0
*/
/**
* Cloudflare_Stream_Shortcode
*
* @usage [cloudflare_stream uid="86432b92bb2d5c02ea57d9d78639f059"]
*/
class Cloudflare_Stream_Shortcode {
/**
* Define and register singleton
*
* @var $instance The singleton instance of the class.
*/
private static $instance = false;
/**
* Singleton
*
* @since 1.0.0
*/
public static function instance() {
if ( ! self::$instance ) {
self::$instance = new self();
self::$instance->setup();
}
return self::$instance;
}
/**
* Constructor
*
* @since 1.0.0
*/
private function __construct() { }
/**
* Clone
*
* @since 1.0.0
*/
private function __clone() { }
/**
* Add actions and filters
*
* @uses add_action, add_filter
* @since 1.0.0
*/
private function setup() {
add_shortcode( 'cloudflare_stream', array( $this, 'video_shortcode_handler' ) );
}
/**
* Cloudflare Stream Shortcode Handler
*
* @param array $atts Video attributes.
* @since 1.0.0
*/
public function video_shortcode_handler( $atts ) {
$attributes = shortcode_atts(
array(
'uid' => '',
'controls' => 'true',
'autoplay' => 'false',
'loop' => 'false',
'preload' => 'false',
'muted' => 'false',
),
$atts
);
foreach ( $attributes as $attr ) {
if ( $attr === $attributes['uid'] ) {
continue; } // Do nothing more with the UID.
$attr = ( filter_var( $attr, FILTER_VALIDATE_BOOLEAN ) ) ? 'true' : 'false'; // Filter to string based boolean.
}
$stream_api = Cloudflare_Stream_API::instance();
$response_text = $stream_api->get_video_embed( $attributes['uid'], $attributes );
return $response_text;
}
}
Cloudflare_Stream_Shortcode::instance();