PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.14.0
WpStream – Live Streaming, Video on Demand, Pay Per View v4.14.0
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / includes / class-wpstream-elementor-widgets.php

class-wpstream-elementor-widgets.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.14.0, at includes/class-wpstream-elementor-widgets.php

175 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor integration for the WpStream plugin.
4 *
5 * One class owns the whole Elementor layer: it verifies on plugins_loaded that
6 * Elementor is active and meets the minimum Elementor/PHP versions, shows an
7 * admin notice when a requirement fails, and otherwise loads the plugin's
8 * widget classes from widgets/ and registers them with Elementor under the
9 * "WpStream Widgets" category.
10 *
11 * The widget files are required here rather than autoloaded because they
12 * extend Elementor\Widget_Base, which only exists once Elementor has loaded.
13 *
14 * @package Wpstream
15 * @subpackage Wpstream/includes
16 */
17
18 // Block direct access: ABSPATH is only defined when running inside WordPress.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Requirement gate and widget registrar for Elementor.
25 */
26 final class Wpstream_Elementor_Widgets {
27
28 /**
29 * Elementor must be at least this version. 3.5.0 introduced the
30 * `elementor/widgets/register` hook and `Widgets_Manager::register()`
31 * that this class relies on.
32 *
33 * @var string
34 */
35 const MINIMUM_ELEMENTOR_VERSION = '3.5.0';
36
37 /**
38 * PHP must be at least this version (matches the plugin header).
39 *
40 * @var string
41 */
42 const MINIMUM_PHP_VERSION = '7.1';
43
44 /**
45 * Defer the requirement checks until every plugin has had a chance to load.
46 */
47 public function __construct() {
48 add_action( 'plugins_loaded', array( $this, 'init' ) );
49 }
50
51 /**
52 * Check the requirements; schedule a notice on failure, wire the widgets on success.
53 *
54 * @return void
55 */
56 public function init() {
57 // Elementor not active: 'elementor/loaded' never fired.
58 if ( ! did_action( 'elementor/loaded' ) ) {
59 add_action( 'admin_notices', array( $this, 'admin_notice_missing_elementor' ) );
60 return;
61 }
62
63 // Elementor too old for the registration API used below.
64 if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
65 add_action( 'admin_notices', array( $this, 'admin_notice_minimum_elementor_version' ) );
66 return;
67 }
68
69 // PHP too old.
70 if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
71 add_action( 'admin_notices', array( $this, 'admin_notice_minimum_php_version' ) );
72 return;
73 }
74
75 // Requirements met: add the panel category and register the widgets when Elementor asks for them.
76 add_action( 'elementor/elements/categories_registered', array( $this, 'add_widget_category' ) );
77 add_action( 'elementor/widgets/register', array( $this, 'register_widgets' ) );
78 }
79
80 /**
81 * Add the "WpStream Widgets" category to the Elementor editor panel.
82 *
83 * @param \Elementor\Elements_Manager $elements_manager Elementor's category registry.
84 * @return void
85 */
86 public function add_widget_category( $elements_manager ) {
87 $elements_manager->add_category(
88 'wpstream',
89 array(
90 'title' => __( 'WpStream Widgets', 'wpstream' ),
91 'icon' => 'fa fa-home',
92 )
93 );
94 }
95
96 /**
97 * Load the widget classes and hand one instance of each to Elementor.
98 *
99 * @param \Elementor\Widgets_Manager $widgets_manager Elementor's widget registry.
100 * @return void
101 */
102 public function register_widgets( $widgets_manager ) {
103 $widgets_dir = dirname( __DIR__ ) . '/widgets/';
104
105 // Widget files extend Elementor\Widget_Base, so they are only safe to include here.
106 require_once $widgets_dir . 'player.php';
107 require_once $widgets_dir . 'start_streaming.php';
108 require_once $widgets_dir . 'media_list.php';
109
110 $widgets_manager->register( new \ElementorWpStream\Widgets\Wpstream_Player_Base() );
111 $widgets_manager->register( new \ElementorWpStream\Widgets\Wpstream_Start_Streaming_Base() );
112 $widgets_manager->register( new \ElementorWpStream\Widgets\Wpstream_Media_List_Channel() );
113 $widgets_manager->register( new \ElementorWpStream\Widgets\Wpstream_Media_List_Vod() );
114 }
115
116 /**
117 * Admin notice: Elementor is not installed or not active.
118 *
119 * @return void
120 */
121 public function admin_notice_missing_elementor() {
122 $message = sprintf(
123 /* translators: 1: Plugin name 2: Elementor */
124 esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'wpstream' ),
125 '<strong>' . esc_html__( 'WpStream Elementor', 'wpstream' ) . '</strong>',
126 '<strong>' . esc_html__( 'Elementor', 'wpstream' ) . '</strong>'
127 );
128 $this->print_notice( $message );
129 }
130
131 /**
132 * Admin notice: the installed Elementor is older than the minimum.
133 *
134 * @return void
135 */
136 public function admin_notice_minimum_elementor_version() {
137 $message = sprintf(
138 /* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */
139 esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'wpstream' ),
140 '<strong>' . esc_html__( 'WpStream Elementor', 'wpstream' ) . '</strong>',
141 '<strong>' . esc_html__( 'Elementor', 'wpstream' ) . '</strong>',
142 esc_html( self::MINIMUM_ELEMENTOR_VERSION )
143 );
144 $this->print_notice( $message );
145 }
146
147 /**
148 * Admin notice: the running PHP is older than the minimum.
149 *
150 * @return void
151 */
152 public function admin_notice_minimum_php_version() {
153 $message = sprintf(
154 /* translators: 1: Plugin name 2: PHP 3: Required PHP version */
155 esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'wpstream' ),
156 '<strong>' . esc_html__( 'WpStream Elementor', 'wpstream' ) . '</strong>',
157 '<strong>' . esc_html__( 'PHP', 'wpstream' ) . '</strong>',
158 esc_html( self::MINIMUM_PHP_VERSION )
159 );
160 $this->print_notice( $message );
161 }
162
163 /**
164 * Print an already-escaped message as a dismissible warning notice.
165 *
166 * @param string $message Escaped HTML message.
167 * @return void
168 */
169 private function print_notice( $message ) {
170 // Hide WordPress's "Plugin activated" message so it is not shown beside the warning.
171 unset( $_GET['activate'] );
172 printf( '<div class="notice notice-warning is-dismissible"><p>%s</p></div>', $message ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped when built.
173 }
174 }
175