activation-actions.php
4 years ago
build-inline-scripts.php
3 months ago
build-modules.php
1 month ago
build-widgets.php
1 month ago
config-list.php
1 month ago
editor-promotion.php
1 month ago
handler-api.php
3 months ago
handler-widget.php
4 years ago
plugin-unsubscribe.php
2 weeks ago
build-widgets.php
98 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Core; |
| 3 | |
| 4 | use ElementsKit_Lite\Libs\Framework\Attr; |
| 5 | |
| 6 | defined( 'ABSPATH' ) || exit; |
| 7 | |
| 8 | class Build_Widgets { |
| 9 | |
| 10 | /** |
| 11 | * Collection of default widgets. |
| 12 | * |
| 13 | * @since 1.0.0 |
| 14 | * @access private |
| 15 | */ |
| 16 | private $widgets; |
| 17 | |
| 18 | use \ElementsKit_Lite\Traits\Singleton; |
| 19 | |
| 20 | public function __construct() { |
| 21 | |
| 22 | new \ElementsKit_Lite\Widgets\Init\Enqueue_Scripts(); |
| 23 | $this->widgets = \ElementsKit_Lite\Config\Widget_List::instance()->get_list( 'full' ); |
| 24 | |
| 25 | // check if the widget is exists |
| 26 | foreach ( $this->widgets as $widget ) { |
| 27 | $this->add_widget( $widget ); |
| 28 | } |
| 29 | |
| 30 | add_action( 'elementor/widgets/register', array( $this, 'register_widget' ) ); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | public function add_widget( $widget_config ) { |
| 35 | $widget_dir = ( |
| 36 | isset( $widget_config['path'] ) |
| 37 | ? $widget_config['path'] |
| 38 | : \ElementsKit_Lite::widget_dir() . $widget_config['slug'] . '/' |
| 39 | ); |
| 40 | |
| 41 | $widget_file_path = $widget_dir . $widget_config['slug'] . '.php'; |
| 42 | $widget_handler_file_path = $widget_dir . $widget_config['slug'] . '-handler.php'; |
| 43 | if (!file_exists($widget_file_path) && !file_exists($widget_handler_file_path)) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | include $widget_file_path; |
| 48 | include $widget_handler_file_path; |
| 49 | |
| 50 | $base_class_name = ( |
| 51 | ( isset( $widget_config['base_class_name'] ) ) |
| 52 | ? $widget_config['base_class_name'] |
| 53 | : '\Elementor\ElementsKit_Widget_' . \ElementsKit_Lite\Utils::make_classname( $widget_config['slug'] ) |
| 54 | ); |
| 55 | |
| 56 | $handler = $base_class_name . '_Handler'; |
| 57 | $handler_class = new $handler(); |
| 58 | |
| 59 | if ( $handler_class->scripts() != false ) { |
| 60 | add_action( 'wp_enqueue_scripts', array( $handler_class, 'scripts' ) ); |
| 61 | } |
| 62 | |
| 63 | if ( $handler_class->styles() != false ) { |
| 64 | add_action( 'wp_enqueue_scripts', array( $handler_class, 'styles' ) ); |
| 65 | } |
| 66 | |
| 67 | if ( $handler_class->inline_css() != false ) { |
| 68 | wp_add_inline_style( 'elementskit-init-css', $handler_class->inline_css() ); |
| 69 | } |
| 70 | |
| 71 | if ( $handler_class->inline_js() != false ) { |
| 72 | wp_add_inline_script( 'elementskit-init-js', $handler_class->inline_js() ); |
| 73 | } |
| 74 | |
| 75 | if ( $handler_class->register_api() != false ) { |
| 76 | if ( \file_exists( $handler_class->register_api() ) ) { |
| 77 | include_once $handler_class->register_api(); |
| 78 | $api = $base_class_name . '_Api'; |
| 79 | new $api(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if ( $handler_class->wp_init() != false ) { |
| 84 | add_action( 'init', array( $handler_class, 'wp_init' ) ); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
| 89 | public function register_widget( $widgets_manager ) { |
| 90 | foreach ( $this->widgets as $widget_slug => $widget ) { |
| 91 | $class_name = '\Elementor\ElementsKit_Widget_' . \ElementsKit_Lite\Utils::make_classname( $widget_slug ); |
| 92 | if ( class_exists( $class_name ) ) { |
| 93 | $widgets_manager->register( new $class_name() ); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 |