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 / bricks / class-wdkit-bricks-files-load.php

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

136 lines 3.3 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.1
7 *
8 * @package Wdesignkit
9 * @subpackage Wdesignkit/includes/bricks
10 * */
11
12 /**
13 * Exit if accessed directly.
14 */
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 if ( ! class_exists( 'Wdkit_Bricks_Files_Load' ) ) {
20
21 /**
22 * This class used for only bricks widget load
23 *
24 * @since 1.0.1
25 */
26 class Wdkit_Bricks_Files_Load {
27
28 /**
29 * Instance
30 *
31 * @since 1.0.1
32 * @var \Bricks\Plugin The single instance of the class.
33 */
34 private static $instance = null;
35
36 /**
37 * Instance
38 *
39 * Ensures only one instance of the class is loaded or can be loaded.
40 *
41 * @since 1.0.1
42 * @return \Bricks\Plugin An instance of the class.
43 */
44 public static function instance() {
45 if ( is_null( self::$instance ) ) {
46 self::$instance = new self();
47 }
48 return self::$instance;
49 }
50
51 /**
52 * Perform some compatibility checks to make sure basic requirements are meet.
53 *
54 * @since 1.0.1
55 */
56 public function __construct() {
57 add_action( 'init', array( $this, 'wdkit_init' ), 99 );
58 }
59
60 /**
61 * Initialize
62 *
63 * Load the addons functionality only after bricks is initialized.
64 *
65 * Fired by `bricks/init` action hook.
66 *
67 * @since 1.0.1
68 */
69 public function wdkit_init() {
70 $dir = trailingslashit( WDKIT_BUILDER_PATH ) . '/bricks/';
71
72 if ( ! is_dir( $dir ) ) {
73 return false;
74 }
75
76 $list = ! empty( $dir ) ? scandir( $dir ) : array();
77 if ( empty( $list ) || count( $list ) <= 2 ) {
78 return false;
79 }
80
81 $get_db_widget = get_option( 'wkit_deactivate_widgets', [] );
82 $server_w_unique = array_column($get_db_widget, 'w_unique');
83
84 foreach ( $list as $key => $value ) {
85 if ( in_array( $value, array( '..', '.' ), true ) ) {
86 continue;
87 }
88
89 if (! is_dir( trailingslashit( $dir ) . $value ) ){
90 return false;
91 }
92
93 if ( ! strpos( $value, '.' ) ) {
94 $sub_dir = scandir( trailingslashit( $dir ) . $value );
95
96 foreach ( $sub_dir as $sub_dir_value ) {
97 if ( in_array( $sub_dir_value, array( '..', '.' ), true ) ) {
98 continue;
99 }
100
101 $file = new SplFileInfo( $sub_dir_value );
102 $check_ext = $file->getExtension();
103 $ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
104
105 if ( 'php' === $ext ) {
106 $json_file = str_replace( '.php', '.json', $sub_dir_value );
107 $str_replace = str_replace( '.php', '', $sub_dir_value );
108 $str_replace = str_replace( '-', '_', $str_replace );
109
110 $json_path = trailingslashit( WDKIT_BUILDER_PATH ) . "bricks/{$value}/{$json_file}";
111 $json_data = wp_json_file_decode( $json_path );
112 $w_type = ! empty( $json_data->widget_data->widgetdata->publish_type ) ? $json_data->widget_data->widgetdata->publish_type : '';
113 $widget_id = ! empty( $json_data->widget_data->widgetdata->widget_id ) ? $json_data->widget_data->widgetdata->widget_id : '';
114
115 if ( ! empty( $w_type ) && 'Publish' === $w_type ) {
116
117 if( ! in_array( $widget_id , $server_w_unique ) ){
118
119 $file = trailingslashit( WDKIT_BUILDER_PATH ) . "/bricks/{$value}/{$sub_dir_value}";
120
121 if ( class_exists( 'Bricks\Elements' ) ) {
122 Bricks\Elements::register_element( $file );
123 }
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131
132 }
133
134 Wdkit_Bricks_Files_Load::instance();
135 }
136