| 1 |
<?php |
| 2 |
namespace Enteraddons\Core\Base; |
| 3 |
/** |
| 4 |
* Enteraddons admin class |
| 5 |
* |
| 6 |
* @package Enteraddons |
| 7 |
* @author ThemeLooks |
| 8 |
* @copyright 2022 ThemeLooks |
| 9 |
* @license GPL-2.0-or-later |
| 10 |
* |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
if( !defined( 'WPINC' ) ) { |
| 15 |
die; |
| 16 |
} |
| 17 |
|
| 18 |
if( !class_exists('Widgets_Base') ) { |
| 19 |
|
| 20 |
class Widgets_Base { |
| 21 |
|
| 22 |
private static $instance = null; |
| 23 |
|
| 24 |
function __construct() { |
| 25 |
$this->init_hooks(); |
| 26 |
} |
| 27 |
|
| 28 |
// |
| 29 |
public static function getInstance() { |
| 30 |
|
| 31 |
if( is_null( self::$instance ) ) { |
| 32 |
self::$instance = new self(); |
| 33 |
} |
| 34 |
return self::$instance; |
| 35 |
} |
| 36 |
|
| 37 |
public function init_hooks() { |
| 38 |
add_action( 'elementor/elements/categories_registered', [ $this, 'registered_category'] ); |
| 39 |
// Register New Widgets |
| 40 |
add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] ); |
| 41 |
} |
| 42 |
|
| 43 |
// |
| 44 |
public function registered_category() { |
| 45 |
\Elementor\Plugin::instance()->elements_manager->add_category( 'enteraddons-elements-category', [ |
| 46 |
'title' => esc_html__( 'Enteraddons', 'enteraddons' ), |
| 47 |
], 1 ); |
| 48 |
\Elementor\Plugin::instance()->elements_manager->add_category( 'enteraddons-header-footer-category', [ |
| 49 |
'title' => esc_html__( 'Enteraddons Header Footer', 'enteraddons' ), |
| 50 |
], 1 ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Widgets Register |
| 55 |
* |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
* |
| 59 |
* @access public |
| 60 |
*/ |
| 61 |
|
| 62 |
public function register_widgets( $widgets_manager ) { |
| 63 |
|
| 64 |
$widgets = new \Enteraddons\Inc\Widgets_List(); |
| 65 |
$activeWidget = get_option( ENTERADDONS_OPTION_KEY ); |
| 66 |
if( !empty( $activeWidget['widgets'] ) && is_array( $activeWidget['widgets'] ) ) { |
| 67 |
foreach( $widgets->getAllElements() as $widget ) { |
| 68 |
if( !empty( $widget['name'] ) && in_array( $widget['name'], $activeWidget['widgets'] ) ) { |
| 69 |
$widgetName = $widget['name']; |
| 70 |
$prepareClassName = $this->class_name_prepare( $widgetName ); |
| 71 |
$namespace = !empty( $widget['is_pro'] ) && $widget['is_pro'] == true ? 'EnteraddonsPro' : 'Enteraddons'; |
| 72 |
$className = '\\'.$namespace.'\Widgets\\'.$prepareClassName.'\\'.$prepareClassName; |
| 73 |
if( class_exists( $className ) ) { |
| 74 |
$widgets_manager->register( new $className ); |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* File name prepare |
| 83 |
* From widgets list |
| 84 |
* |
| 85 |
* @since 1.0.0 |
| 86 |
* |
| 87 |
* @access public |
| 88 |
*/ |
| 89 |
public function file_name_prepare( $name ) { |
| 90 |
return str_replace( ['_', ' '], '-', $name ); |
| 91 |
} |
| 92 |
/** |
| 93 |
* Class name prepare |
| 94 |
* From widgets list |
| 95 |
* |
| 96 |
* @since 1.0.0 |
| 97 |
* |
| 98 |
* @access public |
| 99 |
*/ |
| 100 |
public function class_name_prepare( $name ) { |
| 101 |
return ucwords( str_replace( ['-', ' '], '_', $name ), '_' ); |
| 102 |
} |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
} |
| 107 |
|