PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.3.2
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.3.2
2.7.1 2.7.0 2.6.6 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5.0 2.4.0 2.3.3 2.3.2 2.3.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 All 130 releases
wdesignkit / includes / widget-load / elementor / class-wdkit-elementor-files-load.php

class-wdkit-elementor-files-load.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow 2.3.2, at includes/widget-load/elementor/class-wdkit-elementor-files-load.php

180 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Exit if accessed directly.
4 *
5 * @link https://posimyth.com/
6 * @since 1.0.0
7 *
8 * @package Wdesignkit
9 * @subpackage Wdesignkit/includes/elementor
10 * */
11
12 /**
13 * Exit if accessed directly.
14 * */
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 if ( ! class_exists( 'Wdkit_Elementor_Files_Load' ) ) {
20
21 /**
22 * This class used for only elementor widget load
23 *
24 * @since 1.0.0
25 */
26 class Wdkit_Elementor_Files_Load {
27 /**
28 * Instance
29 *
30 * @since 1.0.0
31 * @access private
32 * @static
33 * @var \Elementor_Test_Addon\Plugin The single instance of the class.
34 */
35 private static $instance = null;
36
37 /**
38 * Instance
39 *
40 * Ensures only one instance of the class is loaded or can be loaded.
41 *
42 * @since 1.0.0
43 * @static
44 * @return \Elementor_Test_Addon\Plugin An instance of the class.
45 */
46 public static function instance() {
47 if ( is_null( self::$instance ) ) {
48 self::$instance = new self();
49 }
50
51 return self::$instance;
52 }
53
54 /**
55 * Constructor
56 *
57 * Perform some compatibility checks to make sure basic requirements are meet.
58 * If all compatibility checks pass, initialize the functionality.
59 *
60 * @since 1.0.0
61 */
62 public function __construct() {
63 add_action( 'elementor/init', array( $this, 'wdkit_init' ) );
64 }
65
66 /**
67 * Initialize
68 *
69 * Load the addons functionality only after Elementor is initialized.
70 *
71 * Fired by `elementor/init` action hook.
72 *
73 * @since 1.0.0
74 */
75 public function wdkit_init() {
76 require_once WDKIT_INCLUDES . 'widget-load/elementor/wb-controller.php';
77
78 $this->wdkit_register_categories();
79 add_action( 'elementor/widgets/register', array( $this, 'wdkit_register_widgets' ) );
80 }
81
82 /**
83 *
84 * Add elementor widgets list
85 *
86 * @since 1.0.0
87 *
88 * @param string $widgets_manager elementor widget structure.
89 */
90 public function wdkit_register_widgets( $widgets_manager ) {
91 $dir = trailingslashit( WDKIT_BUILDER_PATH ) . '/elementor/';
92
93 if ( ! is_dir( $dir ) ) {
94 return false;
95 }
96
97 $list = ! empty( $dir ) ? scandir( $dir ) : array();
98 if ( empty( $list ) || count( $list ) <= 2 ) {
99 return false;
100 }
101
102 $get_db_widget = get_option( 'wkit_deactivate_widgets', [] );
103 $server_w_unique = array_column($get_db_widget, 'w_unique');
104
105 foreach ( $list as $key => $value ) {
106 if ( in_array( $value, array( '..', '.' ), true ) ) {
107 continue;
108 }
109
110 if (! is_dir( trailingslashit( $dir ) . $value ) ){
111 // return false;
112 continue;
113 }
114
115 if ( ! strpos( $value, '.' ) ) {
116 $sub_dir = scandir( trailingslashit( $dir ) . $value );
117
118 foreach ( $sub_dir as $sub_dir_value ) {
119 if ( in_array( $sub_dir_value, array( '..', '.' ), true ) ) {
120 continue;
121 }
122
123 $file = new SplFileInfo( $sub_dir_value );
124 $check_ext = $file->getExtension();
125 $ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
126
127 if ( 'php' === $ext ) {
128 $json_file = str_replace( '.php', '.json', $sub_dir_value );
129 $str_replace = str_replace( '.php', '', $sub_dir_value );
130 $str_replace = str_replace( '-', '_', $str_replace );
131
132 $json_path = trailingslashit( WDKIT_BUILDER_PATH ) . "elementor/{$value}/{$json_file}";
133 $json_data = wp_json_file_decode( $json_path );
134
135 $w_type = ! empty( $json_data->widget_data->widgetdata->publish_type ) ? $json_data->widget_data->widgetdata->publish_type : '';
136 $widget_id = ! empty( $json_data->widget_data->widgetdata->widget_id ) ? $json_data->widget_data->widgetdata->widget_id : '';
137
138 if ( ! empty( $w_type ) && 'Publish' === $w_type ) {
139
140 if( ! in_array( $widget_id , $server_w_unique ) ){
141 $class = 'Wdkit_' . sanitize_text_field( $str_replace );
142 require_once trailingslashit( WDKIT_BUILDER_PATH ) . "/elementor/{$value}/{$sub_dir_value}";
143
144 $widgets_manager->register( new $class() );
145 }
146 }
147 }
148 }
149 }
150 }
151 }
152
153 /**
154 *
155 * Add elementor categories list
156 *
157 * @since 1.0.0
158 */
159 public function wdkit_register_categories() {
160 $elementor = \Elementor\Plugin::$instance;
161
162 $category_list = get_option( 'wkit_builder' );
163
164 if ( ! empty( $category_list ) ) {
165 foreach ( $category_list as $value ) {
166 $elementor->elements_manager->add_category(
167 $value,
168 array(
169 'title' => esc_html( $value ),
170 'icon' => 'fa fa-plug',
171 )
172 );
173 }
174 }
175 }
176 }
177
178 Wdkit_Elementor_Files_Load::instance();
179 }
180