| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor integration bootstrap for the WpStream widgets. |
| 4 |
* |
| 5 |
* This file is required only after WpStream_Elementor_Base::init() has confirmed |
| 6 |
* that Elementor is present and meets the minimum version. It defines the |
| 7 |
* singleton that loads each WpStream Elementor widget, registers those widget |
| 8 |
* types with Elementor, and adds the "WpStream Widgets" category to the editor |
| 9 |
* panel. |
| 10 |
* |
| 11 |
* @package Wpstream |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace ElementorWpStream; |
| 15 |
|
| 16 |
/** |
| 17 |
* Class Plugin |
| 18 |
* |
| 19 |
* Main Plugin class |
| 20 |
* @since 1.2.0 |
| 21 |
*/ |
| 22 |
class Plugin_Base { |
| 23 |
|
| 24 |
/** |
| 25 |
* Instance |
| 26 |
* |
| 27 |
* @since 1.2.0 |
| 28 |
* @access private |
| 29 |
* @static |
| 30 |
* |
| 31 |
* @var Plugin The single instance of the class. |
| 32 |
*/ |
| 33 |
// @var Plugin_Base|null Holds the one and only instance; null until first requested. |
| 34 |
private static $_instance = null; |
| 35 |
|
| 36 |
/** |
| 37 |
* Instance |
| 38 |
* |
| 39 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 40 |
* |
| 41 |
* @since 1.2.0 |
| 42 |
* @access public |
| 43 |
* |
| 44 |
* @return Plugin An instance of the class. |
| 45 |
*/ |
| 46 |
public static function instance() { |
| 47 |
// Lazily construct the singleton the first time it is asked for. |
| 48 |
if ( is_null( self::$_instance ) ) { |
| 49 |
// No instance yet, so create one (the constructor wires up the hooks). |
| 50 |
self::$_instance = new self(); |
| 51 |
} |
| 52 |
// Return the shared instance to every caller. |
| 53 |
return self::$_instance; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* widget_scripts |
| 58 |
* |
| 59 |
* Load required plugin core files. |
| 60 |
* |
| 61 |
* @since 1.2.0 |
| 62 |
* @access public |
| 63 |
*/ |
| 64 |
public function widget_scripts() { |
| 65 |
// Hooked to elementor/frontend/after_register_scripts; no scripts are |
| 66 |
// registered here at present (intentional no-op placeholder). |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Include Widgets files |
| 71 |
* |
| 72 |
* Load widgets files |
| 73 |
* |
| 74 |
* @since 1.2.0 |
| 75 |
* @access private |
| 76 |
*/ |
| 77 |
private function include_widgets_files() { |
| 78 |
// Pull in the standard (Video.js) player widget definition. |
| 79 |
require_once( __DIR__ . '/widgets/player.php' ); |
| 80 |
// Pull in the live chat widget definition. |
| 81 |
require_once( __DIR__ . '/widgets/wpstream_chat.php' ); |
| 82 |
// Pull in the low-latency player widget definition. |
| 83 |
require_once( __DIR__ . '/widgets/player-lowlatency.php' ); |
| 84 |
// Pull in the "start streaming" / go-live widget definition. |
| 85 |
require_once( __DIR__ . '/widgets/start_streaming.php' ); |
| 86 |
// Pull in the widget that lists live channels. |
| 87 |
require_once( __DIR__ . '/widgets/media_list_channels.php' ); |
| 88 |
// Pull in the widget that lists VOD entries. |
| 89 |
require_once( __DIR__ . '/widgets/media_list_vod.php' ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Register Widgets |
| 94 |
* |
| 95 |
* Register new Elementor widgets. |
| 96 |
* |
| 97 |
* @since 1.2.0 |
| 98 |
* @access public |
| 99 |
*/ |
| 100 |
public function register_widgets() { |
| 101 |
// Its is now safe to include Widgets files |
| 102 |
// Load each widget's class file before instantiating it below. |
| 103 |
$this->include_widgets_files(); |
| 104 |
|
| 105 |
// Register Widgets |
| 106 |
// Hand a fresh instance of each widget to Elementor's widgets manager |
| 107 |
// so they appear in the editor and can render on the front end. |
| 108 |
|
| 109 |
// Register the standard player widget. |
| 110 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Player_Base() ); |
| 111 |
// Register the live chat widget. |
| 112 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Chat_Base() ); |
| 113 |
// Register the low-latency player widget (note: class name spelled "LowLatecy"). |
| 114 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Player_LowLatecy_Base() ); |
| 115 |
// Register the go-live / start streaming widget. |
| 116 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Start_Streaming_Base() ); |
| 117 |
// Register the live channel listing widget. |
| 118 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Media_List_Channel() ); |
| 119 |
// Register the VOD listing widget. |
| 120 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Media_List_Vod() ); |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
/** |
| 127 |
* Add the WpStream category to the Elementor editor panel. |
| 128 |
* |
| 129 |
* Hooked to elementor/elements/categories_registered so that all WpStream |
| 130 |
* widgets are grouped together under a "WpStream Widgets" heading. |
| 131 |
* |
| 132 |
* @since 1.2.0 |
| 133 |
* @access public |
| 134 |
* |
| 135 |
* @param \Elementor\Elements_Manager $elements_manager Elementor's category registry. |
| 136 |
*/ |
| 137 |
public function add_elementor_widget_categories($elements_manager){ |
| 138 |
// Declare a new widget category keyed 'wpstream' with a label and icon. |
| 139 |
$elements_manager->add_category( |
| 140 |
'wpstream', |
| 141 |
[ |
| 142 |
// Human-readable heading shown in the editor's widget panel. |
| 143 |
'title' => __( 'WpStream Widgets', 'hello-wpstream' ), |
| 144 |
// Font Awesome icon used for the category. |
| 145 |
'icon' => 'fa fa-home', |
| 146 |
] |
| 147 |
); |
| 148 |
|
| 149 |
|
| 150 |
} |
| 151 |
/** |
| 152 |
* Plugin class constructor. |
| 153 |
* |
| 154 |
* Registers the Elementor action hooks that load scripts, register the |
| 155 |
* widgets, and add the widget category. |
| 156 |
* |
| 157 |
* @since 1.2.0 |
| 158 |
* @access public |
| 159 |
*/ |
| 160 |
public function __construct() { |
| 161 |
|
| 162 |
// Register widget scripts |
| 163 |
// When Elementor registers front-end scripts, give us a chance to enqueue ours. |
| 164 |
add_action( 'elementor/frontend/after_register_scripts', [ $this, 'widget_scripts' ] ); |
| 165 |
|
| 166 |
// Register widgets |
| 167 |
// When Elementor collects widget types, register the WpStream widgets. |
| 168 |
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_widgets' ] ); |
| 169 |
|
| 170 |
// When Elementor builds its category list, add the WpStream category. |
| 171 |
add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_widget_categories' ] ); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
// Instantiate Plugin Class |
| 176 |
// Kick off the singleton, which registers all Elementor hooks on construction. |
| 177 |
Plugin_Base::instance(); |