| 1 |
<?php |
| 2 |
namespace ElementorWpStream; |
| 3 |
|
| 4 |
/** |
| 5 |
* Class Plugin |
| 6 |
* |
| 7 |
* Main Plugin class |
| 8 |
* @since 1.2.0 |
| 9 |
*/ |
| 10 |
class Plugin_Base { |
| 11 |
|
| 12 |
/** |
| 13 |
* Instance |
| 14 |
* |
| 15 |
* @since 1.2.0 |
| 16 |
* @access private |
| 17 |
* @static |
| 18 |
* |
| 19 |
* @var Plugin The single instance of the class. |
| 20 |
*/ |
| 21 |
private static $_instance = null; |
| 22 |
|
| 23 |
/** |
| 24 |
* Instance |
| 25 |
* |
| 26 |
* Ensures only one instance of the class is loaded or can be loaded. |
| 27 |
* |
| 28 |
* @since 1.2.0 |
| 29 |
* @access public |
| 30 |
* |
| 31 |
* @return Plugin An instance of the class. |
| 32 |
*/ |
| 33 |
public static function instance() { |
| 34 |
if ( is_null( self::$_instance ) ) { |
| 35 |
self::$_instance = new self(); |
| 36 |
} |
| 37 |
return self::$_instance; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* widget_scripts |
| 42 |
* |
| 43 |
* Load required plugin core files. |
| 44 |
* |
| 45 |
* @since 1.2.0 |
| 46 |
* @access public |
| 47 |
*/ |
| 48 |
public function widget_scripts() { |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Include Widgets files |
| 54 |
* |
| 55 |
* Load widgets files |
| 56 |
* |
| 57 |
* @since 1.2.0 |
| 58 |
* @access private |
| 59 |
*/ |
| 60 |
private function include_widgets_files() { |
| 61 |
require_once( __DIR__ . '/widgets/player.php' ); |
| 62 |
require_once( __DIR__ . '/widgets/wpstream_chat.php' ); |
| 63 |
require_once( __DIR__ . '/widgets/player-lowlatency.php' ); |
| 64 |
require_once( __DIR__ . '/widgets/start_streaming.php' ); |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Register Widgets |
| 70 |
* |
| 71 |
* Register new Elementor widgets. |
| 72 |
* |
| 73 |
* @since 1.2.0 |
| 74 |
* @access public |
| 75 |
*/ |
| 76 |
public function register_widgets() { |
| 77 |
// Its is now safe to include Widgets files |
| 78 |
$this->include_widgets_files(); |
| 79 |
|
| 80 |
// Register Widgets |
| 81 |
|
| 82 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Player_Base() ); |
| 83 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Chat_Base() ); |
| 84 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Player_LowLatecy_Base() ); |
| 85 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgets\Wpstream_Start_Streaming_Base() ); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
/** |
| 91 |
* Plugin class constructor |
| 92 |
* |
| 93 |
* Register plugin action hooks and filters |
| 94 |
* |
| 95 |
* @since 1.2.0 |
| 96 |
* @access public |
| 97 |
*/ |
| 98 |
public function add_elementor_widget_categories($elements_manager){ |
| 99 |
$elements_manager->add_category( |
| 100 |
'wpstream', |
| 101 |
[ |
| 102 |
'title' => __( 'WpStream Widgets', 'wpstream' ), |
| 103 |
'icon' => 'fa fa-home', |
| 104 |
] |
| 105 |
); |
| 106 |
|
| 107 |
|
| 108 |
} |
| 109 |
public function __construct() { |
| 110 |
|
| 111 |
// Register widget scripts |
| 112 |
add_action( 'elementor/frontend/after_register_scripts', [ $this, 'widget_scripts' ] ); |
| 113 |
|
| 114 |
// Register widgets |
| 115 |
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_widgets' ] ); |
| 116 |
|
| 117 |
add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_widget_categories' ] ); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
// Instantiate Plugin Class |
| 122 |
Plugin_Base::instance(); |