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

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

175 lines 4.6 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.2
7 *
8 * @package Wdesignkit
9 * @subpackage Wdesignkit/includes/gutenberg
10 * */
11
12 /**
13 * Exit if accessed directly.
14 */
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 if ( ! class_exists( 'Wdkit_Gutenberg_Files_Load' ) ) {
20
21 /**
22 * This class used for only gutenberg widget load
23 *
24 * @since 1.0.2
25 */
26 class Wdkit_Gutenberg_Files_Load {
27
28 /**
29 * Instance
30 *
31 * @since 1.0.2
32 * @var 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.2
42 * @return 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.2
55 */
56 public function __construct() {
57 add_action( 'enqueue_block_editor_assets', array( $this, 'editor_assets' ) );
58 $this->wdkit_register_gutenberg_widgets();
59 }
60
61 /**
62 * Load Gutenburg Builder js and css for controller.
63 *
64 * @since 1.0.2
65 */
66 public function editor_assets() {
67
68 $wp_localize_tpgb = array(
69 'category' => 'tpgb',
70 'admin_url' => esc_url( admin_url() ),
71 'home_url' => home_url(),
72 'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
73 );
74
75 global $pagenow;
76 $scripts_dep = array( 'wp-blocks', 'wp-i18n', 'wp-plugins', 'wp-element', 'wp-components', 'wp-api-fetch', 'media-upload', 'media-editor' );
77 if ( 'widgets.php' !== $pagenow && 'customize.php' !== $pagenow ) {
78 $scripts_dep = array_merge( $scripts_dep, array( 'wp-editor', 'wp-edit-post' ) );
79 wp_enqueue_script( 'wkit-editor-block-pmgc', WDKIT_URL . '/assets/js/main/gutenberg/wkit_g_pmgc.js', $scripts_dep, WDKIT_VERSION, false );
80 wp_localize_script( 'wkit-editor-block-pmgc', 'wdkit_blocks_load', $wp_localize_tpgb );
81 }
82 }
83
84 /**
85 * Here is Register Gutenberg Widgets
86 *
87 * @since 1.0.2
88 */
89 public function wdkit_register_gutenberg_widgets() {
90 $dir = trailingslashit( WDKIT_BUILDER_PATH ) . '/gutenberg/';
91
92 if ( ! is_dir( $dir ) ) {
93 return false;
94 }
95
96 $list = ! empty( $dir ) ? scandir( $dir ) : array();
97 if ( empty( $list ) || count( $list ) <= 2 ) {
98 return false;
99 }
100
101 $get_db_widget = get_option( 'wkit_deactivate_widgets', [] );
102 $server_w_unique = array_column($get_db_widget, 'w_unique');
103
104 foreach ( $list as $key => $value ) {
105 if ( in_array( $value, array( '..', '.' ), true ) ) {
106 continue;
107 }
108
109 if ( ! is_dir( trailingslashit( $dir ) . $value ) ) {
110 continue;
111 }
112
113 if ( ! strpos( $value, '.' ) ) {
114 $sub_dir = scandir( trailingslashit( $dir ) . '/' . $value );
115
116 foreach ( $sub_dir as $sub_dir_value ) {
117 if ( in_array( $sub_dir_value, array( '..', '.' ), true ) ) {
118 continue;
119 }
120
121 $file = new SplFileInfo( $sub_dir_value );
122 $check_ext = $file->getExtension();
123 $ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
124
125 if ( 'php' === $ext ) {
126 $json_file = str_replace( '.php', '.json', $sub_dir_value );
127 $str_replace = str_replace( '.php', '', $sub_dir_value );
128
129 $json_path = trailingslashit( WDKIT_BUILDER_PATH ) . "/gutenberg/{$value}/{$json_file}";
130 $json_data = wp_json_file_decode( $json_path );
131
132 $w_type = ! empty( $json_data->widget_data->widgetdata->publish_type ) ? $json_data->widget_data->widgetdata->publish_type : '';
133 $widget_id = ! empty( $json_data->widget_data->widgetdata->widget_id ) ? $json_data->widget_data->widgetdata->widget_id : '';
134 if ( ! empty( $w_type ) && 'Publish' === $w_type ) {
135 if( ! in_array( $widget_id , $server_w_unique ) ){
136 include trailingslashit( WDKIT_BUILDER_PATH ) . "/gutenberg/{$value}/{$sub_dir_value}";
137 }
138 }
139 }
140 }
141 }
142 }
143 }
144 }
145
146 add_filter( 'block_categories_all', 'wdkit_register_block_category', 9999992, 1 );
147
148 /**
149 * Gutenberg block category for The Plus Addon.
150 *
151 * @since 1.0.2
152 *
153 * @param array $categories Block categories.
154 */
155 function wdkit_register_block_category( $categories ) {
156 $category_list = get_option( 'wkit_builder', array() );
157 $new_categories = array();
158
159 if ( empty( $category_list ) || ! is_array( $category_list ) ) {
160 return $categories;
161 }
162
163 foreach ( $category_list as $value ) {
164 $new_categories[] = array(
165 'slug' => $value,
166 'title' => esc_html( $value ),
167 );
168 }
169
170 return array_merge( $new_categories, $categories );
171 }
172
173 Wdkit_Gutenberg_Files_Load::instance();
174 }
175