| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || die(); |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Sellkit_Elementor_Base_Module |
| 7 |
* |
| 8 |
* @since 1.1.0 |
| 9 |
*/ |
| 10 |
abstract class Sellkit_Elementor_Base_Module { |
| 11 |
|
| 12 |
/** |
| 13 |
* The class instance. |
| 14 |
* |
| 15 |
* @var array |
| 16 |
*/ |
| 17 |
public static $instances = []; |
| 18 |
|
| 19 |
/** |
| 20 |
* Get the current class name. |
| 21 |
* |
| 22 |
* @since 1.1.0 |
| 23 |
* @return string |
| 24 |
*/ |
| 25 |
public static function class_name() { |
| 26 |
return get_called_class(); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Gets the instance. |
| 31 |
* |
| 32 |
* @since 1.1.0 |
| 33 |
* @return mixed |
| 34 |
*/ |
| 35 |
public static function get_instance() { |
| 36 |
if ( empty( static::$instances[ static::class_name() ] ) ) { |
| 37 |
static::$instances[ static::class_name() ] = new static(); |
| 38 |
} |
| 39 |
|
| 40 |
return static::$instances[ static::class_name() ]; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* |
| 45 |
* Gets the widgets |
| 46 |
* |
| 47 |
* @since 1.1.0 |
| 48 |
* @return array |
| 49 |
*/ |
| 50 |
public function get_widgets() { |
| 51 |
return []; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Class constructor |
| 56 |
* |
| 57 |
* @since 1.1.0 |
| 58 |
* Sellkit_Elementor_Base_Module constructor. |
| 59 |
*/ |
| 60 |
public function __construct() { |
| 61 |
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_widgets' ] ); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Register widgets. |
| 66 |
* |
| 67 |
* @since 1.1.0 |
| 68 |
* @param object $widgets_manager Widgets manager. |
| 69 |
*/ |
| 70 |
public function register_widgets( $widgets_manager ) { |
| 71 |
foreach ( $this->get_widgets() as $widget_name ) { |
| 72 |
// Prepare class name. |
| 73 |
$class_name = str_replace( '-', ' ', $widget_name ); |
| 74 |
$class_name = str_replace( ' ', '_', ucwords( $class_name ) ); |
| 75 |
$class_name = "Sellkit_Elementor_{$class_name}_Widget"; |
| 76 |
|
| 77 |
// Prepare class path. |
| 78 |
$class_path = "elementor/modules/{$widget_name}/widgets/{$widget_name}"; |
| 79 |
|
| 80 |
// Require. |
| 81 |
sellkit()->load_files( [ $class_path ] ); |
| 82 |
|
| 83 |
// Register. |
| 84 |
if ( $class_name::is_active() ) { |
| 85 |
$widgets_manager->register_widget_type( new $class_name() ); |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Check if the module is active. |
| 92 |
* |
| 93 |
* @since 1.1.0 |
| 94 |
* @return bool |
| 95 |
*/ |
| 96 |
public static function is_active() { |
| 97 |
return true; |
| 98 |
} |
| 99 |
} |
| 100 |
|