PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.7.0
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.7.0
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 1.0.16 All 129 releases
← All changes | includes/admin/class-wdkit-enqueue.php +524 -229 1.0.10 → 2.7.0 View file →
@@ -1,229 +1,524 @@
1 -<?php
2 -/**
3 - * This file specifically loads JavaScript and CSS dependencies.
4 - *
5 - * @link https://posimyth.com/
6 - * @since 1.0.0
7 - *
8 - * @package Wdesignkit
9 - */
10 -
11 -namespace wdkit\WdKit_enqueue;
12 -
13 -use wdkit\Wdkit_Wdesignkit;
14 -
15 -if ( ! defined( 'ABSPATH' ) ) {
16 - exit; // Exit if accessed directly.
17 -}
18 -
19 -if ( ! class_exists( 'Wdkit_Enqueue' ) ) {
20 -
21 - /**
22 - * Here Enqueue all js and css script
23 - */
24 - class Wdkit_Enqueue {
25 - /**
26 - * Member Variable
27 - *
28 - * @var instance
29 - */
30 - private static $instance;
31 -
32 - /**
33 - * Member Variable
34 - *
35 - * @var staring wdkit_onbording_end
36 - */
37 - public $wdkit_onbording_end = 'wkit_onbording_end';
38 -
39 - /**
40 - * Initiator
41 - */
42 - public static function get_instance() {
43 - if ( ! isset( self::$instance ) ) {
44 - self::$instance = new self();
45 - }
46 - return self::$instance;
47 - }
48 -
49 - /**
50 - * Initialize the class and set its properties.
51 - *
52 - * @since 1.0.0
53 - */
54 - public function __construct() {
55 - add_action( 'admin_menu', array( $this, 'wdkit_admin_menu' ) );
56 -
57 - add_action( 'admin_enqueue_scripts', array( $this, 'wdkit_admin_scripts' ), 10, 1 );
58 - add_action( 'enqueue_block_editor_assets', array( $this, 'wdkit_admin_scripts' ), 10, 1 );
59 - add_action( 'enqueue_block_editor_assets', array( $this, 'wdkit_enqueue_styles' ), 10 );
60 -
61 - if ( class_exists( '\Elementor\Plugin' ) ) {
62 - add_action( 'elementor/preview/enqueue_styles', array( $this, 'wdkit_elementor_preview_style' ) );
63 - add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'wdkit_elementor_scripts' ) );
64 - }
65 - }
66 -
67 - /**
68 - * This function is used to retrieve all post types in WordPress and store them in an array.
69 - *
70 - * @since 1.0.0
71 - */
72 - public function wdkit_get_post_type_list() {
73 - $args = array(
74 - 'public' => true,
75 - 'show_ui' => true,
76 - );
77 -
78 - $post_types = get_post_types( $args, 'objects' );
79 - $options = array();
80 - foreach ( $post_types as $post_type ) {
81 - $exclude = array( 'attachment' );
82 - if ( true === in_array( $post_type->name, $exclude, true ) ) {
83 - continue;
84 - }
85 -
86 - if ( ! empty( $post_type->name ) && ( 'post' === $post_type->name || 'page' === $post_type->name || 'elementor_library' === $post_type->name || 'nxt_builder' === $post_type->name ) ) {
87 - $options[ $post_type->name ] = $post_type->label;
88 - }
89 - }
90 -
91 - return $options;
92 - }
93 -
94 - /**
95 - * Get Editor Use.
96 - *
97 - * @since 1.0.0
98 - */
99 - protected function wdkit_use_editor() {
100 - global $current_screen;
101 -
102 - $editor = 'wdkit';
103 - if ( isset( $_GET['action'] ) && 'elementor' === $_GET['action'] ) {
104 - $editor = 'elementor';
105 - }
106 -
107 - if ( $current_screen->is_block_editor() && isset( $_GET['action'] ) && 'elementor' !== $_GET['action'] ) {
108 - $editor = 'gutenberg';
109 - }
110 -
111 - return $editor;
112 - }
113 -
114 - /**
115 - * Load Admin Scripts.
116 - *
117 - * @since 1.0.0
118 - */
119 - public function wdkit_elementor_scripts() {
120 - $this->wdkit_admin_scripts( 'elementor' );
121 - }
122 -
123 - /**
124 - * Elementor Preview Style Loaded
125 - *
126 - * @since 1.0.0
127 - */
128 - public function wdkit_elementor_preview_style() {
129 - wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_preview_styles.css', array(), WDKIT_VERSION );
130 - }
131 -
132 - /**
133 - * Enqueue Scripts admin area.
134 - *
135 - * @since 1.0.0
136 - *
137 - * @param string $hook use for check page type.
138 - */
139 - public function wdkit_admin_scripts( $hook ) {
140 - if ( ! in_array( $hook, array( 'toplevel_page_wdesign-kit', 'elementor', 'post-new.php', 'post.php' ), true ) ) {
141 - return;
142 - }
143 -
144 - $this->wdkit_enqueue_scripts( $hook );
145 - $this->wdkit_enqueue_styles();
146 - }
147 -
148 - /**
149 - * Enqueue Styles admin area.
150 - *
151 - * @since 1.0.0
152 - */
153 - public function wdkit_enqueue_styles() {
154 - wp_enqueue_style( 'wdkit-editor-css', WDKIT_URL . 'build/index.css', array(), WDKIT_VERSION );
155 - }
156 -
157 - /**
158 - * Register the JavaScript for the admin area.
159 - *
160 - * @param string $hook give builder name.
161 - * @since 1.0.0
162 - */
163 - public function wdkit_enqueue_scripts( $hook ) {
164 - wp_enqueue_script( 'wdkit-editor-js', WDKIT_URL . 'build/index.js', array( 'wp-i18n', 'wp-element', 'wp-components' ), WDKIT_VERSION, true );
165 -
166 - $onbording_end = get_option( $this->wdkit_onbording_end );
167 -
168 - wp_localize_script(
169 - 'wdkit-editor-js',
170 - 'wdkitData',
171 - array(
172 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
173 - 'WDKIT_PATH' => WDKIT_PATH,
174 - 'WDKIT_URL' => WDKIT_URL,
175 - 'WDKIT_ASSETS' => WDKIT_ASSETS,
176 - 'wdkit_server_url' => WDKIT_SERVER_SITE_URL,
177 - 'home_url' => esc_url( home_url( '/' ) ),
178 - 'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ),
179 - 'post_id' => get_the_ID(),
180 - 'post_type' => get_post_type(),
181 - 'text_domain' => WDKIT_TEXT_DOMAIN,
182 - 'use_editor' => $this->wdkit_use_editor(),
183 - 'post_type_list' => $this->wdkit_get_post_type_list(),
184 - 'WDKIT_onbording_end'=> $onbording_end,
185 -
186 - /** Widget Builder Path */
187 - 'WDKIT_SITE_URL' => WDKIT_GET_SITE_URL,
188 - 'WDKIT_SERVER_PATH' => WDKIT_SERVER_PATH,
189 - 'WDKIT_BUILDER_PATH' => WDKIT_BUILDER_PATH,
190 - 'WDKIT_VERSION' => WDKIT_VERSION,
191 - )
192 - );
193 -
194 - /**Ace Editor files for Widget-builder */
195 - if ( 'toplevel_page_wdesign-kit' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'builder' ) ) {
196 - wp_enqueue_script( 'widgetBuilder-script-editor-js', WDKIT_URL . 'assets/js/extra/ace.min.js', array( 'wp-element' ), WDKIT_VERSION, true );
197 - wp_enqueue_script( 'widgetBuilder-script-editor-cobalt', WDKIT_URL . 'assets/js/extra/theme-cobalt.js', array( 'wp-element' ), WDKIT_VERSION, true );
198 - wp_enqueue_script( 'widgetBuilder-script-editor-html', WDKIT_URL . 'assets/js/extra//mode-html.js', array( 'wp-element' ), WDKIT_VERSION, true );
199 - }
200 -
201 - if ( 'elementor' === $hook ) {
202 - wp_enqueue_script( 'wdkit-frontend-editor', WDKIT_ASSETS . '/js/main/elementor/elementor-editor.js', array( 'jquery', 'wp-i18n' ), WDKIT_VERSION, true );
203 - }
204 - }
205 -
206 - /**
207 - * Add Menu Page WdKit.
208 - *
209 - * @since 1.0.0
210 - */
211 - public function wdkit_admin_menu() {
212 - $capability = 'manage_options';
213 - if ( current_user_can( $capability ) ) {
214 - $hook = add_menu_page( __( 'WDesignKit', 'wdesignkit' ), __( 'WDesignKit', 'wdesignkit' ), 'manage_options', 'wdesign-kit', array( $this, 'wdkit_menu_page_template' ), WDKIT_ASSETS . 'images/svg/logo-icon.svg' );
215 - }
216 - }
217 -
218 - /**
219 - * Load wdkit page content.
220 - *
221 - * @since 1.0.0
222 - */
223 - public function wdkit_menu_page_template() {
224 - echo '<div id="wdesignkit-app"></div>';
225 - }
226 - }
227 -
228 - Wdkit_Enqueue::get_instance();
229 -}
1 +<?php
2 +/**
3 + * This file specifically loads JavaScript and CSS dependencies.
4 + *
5 + * @link https://posimyth.com/
6 + * @since 1.0.0
7 + *
8 + * @package Wdesignkit
9 + */
10 +
11 +namespace wdkit\WdKit_enqueue;
12 +
13 +use wdkit\Wdkit_Wdesignkit;
14 +
15 +if ( ! defined( 'ABSPATH' ) ) {
16 + exit; // Exit if accessed directly.
17 +}
18 +
19 +if ( ! class_exists( 'Wdkit_Enqueue' ) ) {
20 +
21 + /**
22 + * Here Enqueue all js and css script
23 + */
24 + class Wdkit_Enqueue {
25 + /**
26 + * Member Variable
27 + *
28 + * @var instance
29 + */
30 + private static $instance;
31 +
32 + /**
33 + * Member Variable
34 + *
35 + * @var staring wdkit_onbording_end
36 + */
37 + public $wdkit_onbording_end = 'wkit_onbording_end';
38 +
39 + /**
40 + * Initiator
41 + */
42 + public static function get_instance() {
43 + if ( ! isset( self::$instance ) ) {
44 + self::$instance = new self();
45 + }
46 + return self::$instance;
47 + }
48 +
49 + /**
50 + * Initialize the class and set its properties.
51 + *
52 + * @since 1.0.0
53 + */
54 + public function __construct() {
55 + add_action( 'admin_menu', array( $this, 'wdkit_admin_menu' ) );
56 +
57 + add_action( 'admin_enqueue_scripts', array( $this, 'wdkit_enqueue_styles_library' ), 10 );
58 +
59 + add_action( 'admin_enqueue_scripts', array( $this, 'wdkit_admin_scripts' ), 10, 1 );
60 + add_action( 'enqueue_block_editor_assets', array( $this, 'wdkit_admin_scripts' ), 10, 1 );
61 + add_action( 'enqueue_block_editor_assets', array( $this, 'wdkit_enqueue_styles' ), 10 );
62 +
63 + // Gutenberg editor styles
64 + add_action( 'enqueue_block_editor_assets', array( $this, 'wdkit_gutenberg_editor_style' ), 10 );
65 +
66 + if ( class_exists( '\Elementor\Plugin' ) ) {
67 + add_action( 'elementor/editor/before_enqueue_styles', array( $this, 'wdkit_elementor_editor_style' ) );
68 + add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'wdkit_elementor_hide_help_tab' ) );
69 + add_action( 'elementor/preview/enqueue_styles', array( $this, 'wdkit_elementor_preview_style' ) );
70 + add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'wdkit_elementor_scripts' ) );
71 + }
72 +
73 + // Bricks editor styles
74 + add_action( 'wp_enqueue_scripts', array( $this, 'wdkit_bricks_editor_style' ), 10, 1 );
75 + }
76 +
77 +
78 + /**
79 + * Enqueue the WDesignKit font library styles.
80 + *
81 + * This function loads the custom font styles for the WDesignKit plugin,
82 + * including the icon font definitions and styling.
83 + *
84 + * @since 1.0.0
85 + * @return void
86 + */
87 + public function wdkit_enqueue_styles_library( $hook = '' ) {
88 + // Hooked on admin_enqueue_scripts with no screen check at all, so this loaded the icon
89 + // font on every wp-admin screen (ClickUp 86d41cnze). admin_enqueue_scripts passes the
90 + // screen hook as its first argument, so the same guard wdkit_admin_scripts() uses can
91 + // apply here. Kept as a separate handle from 'wdkit-library-preview' — both point at the
92 + // same stylesheet, and deduplicating the handles is a separate change.
93 + $is_nexter_page = isset( $_GET['page'] ) && sanitize_key( wp_unslash( $_GET['page'] ) ) === 'nxt_code_snippets';
94 + $is_theme_builder_page = ( isset( $_GET['post_type'] ) && sanitize_key( wp_unslash( $_GET['post_type'] ) ) === 'nxt_builder' ) || ( isset( $_GET['page'] ) && sanitize_key( wp_unslash( $_GET['page'] ) ) === 'nxt_builder' );
95 +
96 + if ( ! in_array( $hook, array( 'toplevel_page_wdesign-kit', 'elementor', 'post-new.php', 'post.php' ), true ) && ! $is_nexter_page && ! $is_theme_builder_page ) {
97 + return;
98 + }
99 +
100 + wp_enqueue_style( 'wdkit-library', WDKIT_URL . 'assets/fonts/style.css', array(), WDKIT_VERSION, false );
101 + }
102 +
103 + /**
104 + * This function is used to retrieve all post types in WordPress and store them in an array.
105 + *
106 + * @since 1.0.0
107 + */
108 + public function wdkit_get_post_type_list() {
109 + $args = array(
110 + 'public' => true,
111 + 'show_ui' => true,
112 + );
113 +
114 + $post_types = get_post_types( $args, 'objects' );
115 + $options = array();
116 + foreach ( $post_types as $post_type ) {
117 + $exclude = array( 'attachment' );
118 + if ( true === in_array( $post_type->name, $exclude, true ) ) {
119 + continue;
120 + }
121 +
122 + if ( ! empty( $post_type->name ) && ( 'post' === $post_type->name || 'page' === $post_type->name || 'elementor_library' === $post_type->name || 'nxt_builder' === $post_type->name ) ) {
123 + $options[ $post_type->name ] = $post_type->label;
124 + }
125 + }
126 +
127 + return $options;
128 + }
129 +
130 + /**
131 + * Get Editor Use.
132 + *
133 + * @since 1.0.0
134 + */
135 + protected function wdkit_use_editor() {
136 + global $current_screen;
137 +
138 + $editor = 'wdkit';
139 +
140 + $action = ! empty( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
141 +
142 + if ( $current_screen && $current_screen->is_block_editor() ) {
143 +
144 + if ( array_key_exists( 'action', $_GET ) && isset( $action ) ) {
145 + if ( 'elementor' === $action ) {
146 + $editor = 'elementor';
147 + } elseif ( 'edit' === $action ) {
148 + $editor = 'gutenberg';
149 + }
150 + } else {
151 + $editor = 'gutenberg';
152 + }
153 + } elseif ( 'elementor' === $action ) {
154 + $editor = 'elementor';
155 + }
156 +
157 + return $editor;
158 + }
159 +
160 + /**
161 + * Load Admin Scripts.
162 + *
163 + * @since 1.0.0
164 + */
165 + public function wdkit_elementor_scripts() {
166 + $this->wdkit_admin_scripts( 'elementor' );
167 + }
168 +
169 + /**
170 + * Elementor Editor Panel Style Loaded
171 + */
172 + public function wdkit_elementor_editor_style() {
173 + wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION );
174 +
175 + // Hide WDesignKit logo icon when white label is enabled
176 + $white_label = get_option( 'wkit_white_label', false );
177 + if ( ! empty( $white_label['help_link'] ) ) {
178 + wp_add_inline_style( 'wdkit-elementor-editor-css', '.elementor-element .icon i.tpae-wdkit-logo:after { display: none !important; }' );
179 + }
180 + }
181 +
182 + /**
183 + * Bricks Editor Panel Style Loaded
184 + */
185 + public function wdkit_bricks_editor_style() {
186 + // Only load in Bricks editor
187 + if ( function_exists( 'bricks_is_builder' ) && bricks_is_builder() ) {
188 + wp_enqueue_style( 'wdkit-bricks-editor-css', WDKIT_URL . 'assets/css/bricks/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION );
189 + // Cross-domain copy/paste for Bricks is marked "Coming Soon" — do not enqueue yet.
190 +
191 + // Hide WDesignKit logo icon when white label is enabled
192 + $white_label = get_option( 'wkit_white_label', false );
193 + if ( ! empty( $white_label['help_link'] ) ) {
194 + wp_add_inline_style( 'wdkit-bricks-editor-css', '.element-data .element-icon i.tpae-wdkit-logo:after { display: none !important; } .bricks-panel-controls .control-group[data-control-group*="Need"]{display:none!important;}' );
195 + }
196 + }
197 + }
198 +
199 + /**
200 + * Gutenberg Editor Panel Style Loaded
201 + */
202 + public function wdkit_gutenberg_editor_style() {
203 + wp_enqueue_style( 'wdkit-gutenberg-editor-css', WDKIT_URL . 'assets/css/gutenberg/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION );
204 + $this->wdkit_cross_copy_paste_script( 'gutenberg' );
205 +
206 + // Hide WDesignKit logo icon + Need Help panel when white label is enabled
207 + $white_label = get_option( 'wkit_white_label', false );
208 + if ( ! empty( $white_label['help_link'] ) ) {
209 + wp_add_inline_style( 'wdkit-gutenberg-editor-css', '.block-editor-block-types-list__list-item .block-editor-block-icon i.tpae-wdkit-logo:after, .tpgb-head-panel-tabs .components-panel__body.wdkit-panel-need-help { display: none !important; }' );
210 + }
211 + }
212 +
213 + /**
214 + * Elementor Preview Style Loaded
215 + *
216 + * @since 1.0.0
217 + */
218 + public function wdkit_elementor_preview_style() {
219 + wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_preview_styles.css', array(), WDKIT_VERSION );
220 + }
221 +
222 + /**
223 + * Enqueue Scripts admin area.
224 + *
225 + * @since 1.0.0
226 + *
227 + * @param string $hook use for check page type.
228 + */
229 + public function wdkit_admin_scripts( $hook ) {
230 +
231 + // Deliberately BEFORE the screen guard below: this 1.4 KB stylesheet contains nothing but
232 + // #adminmenu rules for the WDesignKit menu item, and the admin menu is rendered on every
233 + // admin screen. Gating it to WDesignKit's own screens leaves the menu icon unstyled
234 + // everywhere else — the masked-SVG ::before never applies, so the raw <img> shows through.
235 + // Do not "optimise" this into the guard (ClickUp 86d41cnze).
236 + wp_enqueue_style( 'wdkit-out-dashborad', WDKIT_URL . 'assets/css/dashborad/wdkit-dashborad.css', array(), WDKIT_VERSION, false );
237 +
238 + $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
239 + $ptype = isset( $_GET['post_type'] ) ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) : '';
240 +
241 + // Check if we're on a Nexter Extension page
242 + $is_nexter_page = isset( $_GET['page'] ) && sanitize_key( wp_unslash( $_GET['page'] ) ) === 'nxt_code_snippets';
243 +
244 + // Check if we're on a Theme Builder page (via post_type or page parameter)
245 + $is_theme_builder_page = ( isset( $_GET['post_type'] ) && sanitize_key( wp_unslash( $_GET['post_type'] ) ) === 'nxt_builder' ) || ( isset( $_GET['page'] ) && sanitize_key( wp_unslash( $_GET['page'] ) ) === 'nxt_builder' );
246 +
247 + if ( ! in_array( $hook, array( 'toplevel_page_wdesign-kit', 'elementor', 'post-new.php', 'post.php' ), true ) && !$is_nexter_page && !$is_theme_builder_page ) {
248 + return;
249 + }
250 +
251 + // Moved BELOW the screen guard: this is the 9 KB WDesignKit icon font, used only by
252 + // WDesignKit's own UI (no #adminmenu rules in it), yet it was enqueued on every wp-admin
253 + // screen — dashboard, posts list, media library, plugins page (ClickUp 86d41cnze).
254 + // The admin-menu stylesheet is NOT gated here; see the note at the top of this method.
255 + wp_enqueue_style( 'wdkit-library-preview', WDKIT_URL . 'assets/fonts/style.css', array(), WDKIT_VERSION, false );
256 +
257 + wp_enqueue_media();
258 +
259 + $this->wdkit_enqueue_scripts( $hook );
260 + $this->wdkit_enqueue_styles();
261 + }
262 +
263 + /**
264 + * Enqueue Styles admin area.
265 + *
266 + * @since 1.0.0
267 + */
268 + public function wdkit_enqueue_styles() {
269 + wp_enqueue_style( 'wdkit-editor-css', WDKIT_URL . 'build/index.css', array(), WDKIT_VERSION );
270 +
271 + /**
272 + * The build emits a right-to-left stylesheet (build/index-rtl.css) because the
273 + * source CSS uses physical left/right properties. WordPress does not auto-load
274 + * the -rtl variant; registering it here makes core swap in index-rtl.css on RTL
275 + * locales (Arabic, Hebrew, Farsi, Urdu) so the admin layout mirrors correctly.
276 + */
277 + wp_style_add_data( 'wdkit-editor-css', 'rtl', 'replace' );
278 + }
279 +
280 + /**
281 + * Register the JavaScript for the admin area.
282 + *
283 + * @param string $hook give builder name.
284 + * @since 1.0.0
285 + */
286 + public function wdkit_enqueue_scripts( $hook ) {
287 + $asset_file = WDKIT_PATH . 'build/index.min.asset.php';
288 + $asset = file_exists( $asset_file ) ? require $asset_file : array( 'dependencies' => array( 'wp-i18n', 'wp-element', 'wp-components' ), 'version' => WDKIT_VERSION );
289 +
290 + /**
291 + * JS translations catalog.
292 + *
293 + * The app ships as a large minified bundle (build/index.min.js) which
294 + * `wp i18n make-pot` skips (all *.min.js are skipped) and could not parse
295 + * within WordPress.org's budget anyway. build/wdk-i18n-strings.js is a
296 + * small, readable catalog of every translatable JS string (generated from
297 + * src/ by bin/generate-i18n-strings.js). WordPress.org extracts strings
298 + * from it and builds the per-locale JSON keyed to this handle; loading it
299 + * here populates the shared wp.i18n store so the whole React app is
300 + * translated. It is a dependency of the app bundle so it (and its inline
301 + * translation data) load first.
302 + */
303 + $script_deps = $asset['dependencies'];
304 + if ( file_exists( WDKIT_PATH . 'build/wdk-i18n-strings.js' ) ) {
305 + wp_enqueue_script( 'wdkit-editor-i18n', WDKIT_URL . 'build/wdk-i18n-strings.js', array( 'wp-i18n' ), $asset['version'], array( 'in_footer' => true, 'strategy' => 'defer' ) );
306 + wp_set_script_translations( 'wdkit-editor-i18n', 'wdesignkit' );
307 + $script_deps = array_merge( $script_deps, array( 'wdkit-editor-i18n' ) );
308 + }
309 +
310 + wp_enqueue_script( 'wdkit-editor-js', WDKIT_URL . 'build/index.min.js', $script_deps, $asset['version'], array( 'in_footer' => true, 'strategy' => 'defer' ) );
311 + wp_set_script_translations( 'wdkit-editor-js', 'wdesignkit' );
312 +
313 + $onbording_end = get_option( $this->wdkit_onbording_end );
314 + $white_label = get_option( 'wkit_white_label', false );
315 + $dark_mode = get_option( 'wdkit_dark_mode', 'light' );
316 +
317 + wp_localize_script(
318 + 'wdkit-editor-js',
319 + 'wdkitData',
320 + array(
321 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
322 + // Mirrors the PHP side's WP_DEBUG gate on its own import timing/diagnostic
323 + // error_log() calls, so the JS import flow's console diagnostics follow the
324 + // same convention instead of always printing in every visitor's console.
325 + 'debug' => (bool) ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
326 + 'WDKIT_URL' => WDKIT_URL,
327 + 'WDKIT_ASSETS' => WDKIT_ASSETS,
328 + 'wdkit_server_url' => WDKIT_SERVER_SITE_URL,
329 + 'wdkit_site_api_url' => WDKIT_SERVER_API_URL,
330 + 'wdkit_wp_version' => get_bloginfo( 'version' ),
331 + 'home_url' => esc_url( home_url( '/' ) ),
332 + 'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ),
333 +
334 + /* Kit Import engine switch. 'yes' => the wizard drives the PHP runner in four
335 + * stage calls; anything else => it falls back to its original ~25-call
336 + * orchestration, which is still fully present. Flip with the
337 + * `wdkit_use_php_runner` filter.
338 + *
339 + * Deliberately 'yes'/'no' rather than a boolean. wp_localize_script() casts
340 + * booleans to "1" and "", and while "" is falsy in JS, relying on that is the
341 + * same PHP/JS truthiness trap that bites elsewhere in the importer — a switch
342 + * that silently failed to switch OFF would be the worst outcome for a
343 + * rollback path. An explicit string compares the same in both languages.
344 + *
345 + * Fully qualified: this file is namespaced, and an unqualified reference here
346 + * resolved to wdkit\WdKit_enqueue\Wdkit_Import_Wizard and fatalled. */
347 + 'use_php_runner' => ( class_exists( '\\Wdkit_Import_Wizard' ) && \Wdkit_Import_Wizard::is_enabled() ) ? 'yes' : 'no',
348 + 'post_id' => get_the_ID(),
349 + 'post_type' => get_post_type(),
350 + 'text_domain' => WDKIT_TEXT_DOMAIN,
351 + 'use_editor' => $this->wdkit_use_editor(),
352 + 'post_type_list' => $this->wdkit_get_post_type_list(),
353 + 'WDKIT_onbording_end' => $onbording_end,
354 + 'wdkit_white_label' => $white_label,
355 + 'WDKIT_dark_mode' => $dark_mode,
356 + /** Widget Builder — public URL only, no server filesystem paths */
357 + 'WDKIT_SITE_URL' => WDKIT_GET_SITE_URL,
358 + 'WDKIT_DOC_URL' => WDKIT_DOCUMENT,
359 + 'WDKIT_SERVER_PATH' => WDKIT_SERVER_PATH,
360 + 'WDKIT_VERSION' => WDKIT_VERSION,
361 +
362 + 'gutenberg_template' => Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_template', 'template' ),
363 +
364 + /**
365 + * Data Sharing switcher, Settings panel.
366 + *
367 + * Read as a SITE option — the consent is one answer per install, not per blog. The
368 + * class guard matches the one in wdesignkit.php: on a white-labelled install, or when
369 + * a sibling POSIMYTH plugin's SDK copy won the loader, the tracker class is never
370 + * declared and the constant reference would fatal.
371 + *
372 + * Both references are root-namespaced. This file lives in wdkit\WdKit_enqueue while
373 + * the SDK class is declared in the global namespace: a string class name is always
374 + * global so the guard passed either way, but an unprefixed `Posimyth_Tracker_WDK::`
375 + * resolves against THIS namespace and fatals on every admin page load.
376 + */
377 + 'wdkit_data_sharing' => class_exists( '\Posimyth_Tracker_WDK' ) ? (bool) get_site_option( \Posimyth_Tracker_WDK::OPT_IN_OPTION, false ) : false,
378 + 'wdkit_consent_nonce' => wp_create_nonce( 'posimyth_consent_wdk' ),
379 +
380 + /**
381 + * Whether the Data Sharing card may be shown at all.
382 + *
383 + * Tracks the tracker class rather than the white-label flag: a rebranded install now
384 + * keeps the feature (see wdesignkit.php), so this is false only when the SDK genuinely
385 + * failed to load — a sibling POSIMYTH plugin winning the loader with a diverged copy.
386 + * Rendering a switch in that case would offer a save with no handler behind it.
387 + *
388 + * Separate from wdkit_data_sharing on purpose: that one is false both when sharing is
389 + * off and when the feature is absent, which cannot tell the two apart.
390 + */
391 + 'wdkit_data_sharing_available' => class_exists( '\Posimyth_Tracker_WDK' ),
392 +
393 + /**
394 + * Reseller's product name, for the Data Sharing copy that would otherwise say
395 + * "WDesignKit" on a plugin they have rebranded as their own.
396 + */
397 + 'wdkit_data_sharing_name' => ! empty( $white_label['plugin_name'] ) ? $white_label['plugin_name'] : 'WDesignKit',
398 +
399 + /** help_link is the reseller's "hide POSIMYTH documentation links" switch. */
400 + 'wdkit_data_sharing_docs' => empty( $white_label['help_link'] ) ? WDKIT_DOCUMENT . 'data-sharing/' : ''
401 + )
402 + );
403 +
404 + /**Ace Editor files for Widget-builder */
405 + if ( 'toplevel_page_wdesign-kit' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'builder', 'widget' ) ) {
406 + wp_enqueue_script( 'widgetBuilder-script-editor-js', WDKIT_URL . 'assets/js/extra/ace.min.js', array( 'wp-element' ), WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) );
407 + wp_enqueue_script( 'widgetBuilder-script-editor-cobalt', WDKIT_URL . 'assets/js/extra/theme-cobalt.js', array( 'wp-element' ), WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) );
408 + wp_enqueue_script( 'widgetBuilder-script-editor-html', WDKIT_URL . 'assets/js/extra/mode-html.js', array( 'wp-element' ), WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) );
409 + }
410 +
411 + if ( 'elementor' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor_template', 'template' ) ) {
412 + wp_enqueue_script( 'wdkit-frontend-editor', WDKIT_ASSETS . 'js/main/elementor/elementor-editor.js', array( 'jquery', 'wp-i18n' ), WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) );
413 + wp_set_script_translations( 'wdkit-frontend-editor', 'wdesignkit' );
414 + $this->wdkit_cross_copy_paste_script( 'elementor' );
415 + }
416 + }
417 +
418 + /**
419 + * Enqueue cross-domain copy/paste support for active builders.
420 + *
421 + * @since 1.0.0
422 + */
423 + public function wdkit_cross_copy_paste_script( $builder = '' ) {
424 + $settings = get_option( 'wkit_settings_panel', array() );
425 + $enabled = array(
426 + 'elementor' => ! empty( $settings['cross_copy_paste_elementor'] ) || ! empty( $settings['cross_copy_paste'] ),
427 + 'gutenberg' => ! empty( $settings['cross_copy_paste_gutenberg'] ) || ! empty( $settings['cross_copy_paste'] ),
428 + // Bricks support is "Coming Soon" — force-disabled regardless of saved setting.
429 + 'bricks' => false,
430 + );
431 +
432 + if ( empty( array_filter( $enabled ) ) ) {
433 + return;
434 + }
435 +
436 + if ( ! empty( $builder ) && empty( $enabled[ $builder ] ) ) {
437 + return;
438 + }
439 +
440 + if ( wp_script_is( 'wdkit-cross-copy-paste', 'enqueued' ) ) {
441 + return;
442 + }
443 +
444 + $deps = array( 'wp-i18n' );
445 + // Gutenberg SlotFill needs these so the block toolbar's
446 + // "Options" menu can host our "WDesignKit Copy / Paste" items.
447 + if ( ! empty( $enabled['gutenberg'] ) ) {
448 + $deps[] = 'wp-plugins';
449 + $deps[] = 'wp-element';
450 + $deps[] = 'wp-components';
451 + $deps[] = 'wp-block-editor';
452 + $deps[] = 'wp-data';
453 + $deps[] = 'wp-blocks';
454 + $deps[] = 'wp-dom-ready';
455 + }
456 +
457 + wp_enqueue_script( 'wdkit-cross-copy-paste', WDKIT_ASSETS . 'js/main/wdkit-cross-copy-paste.js', $deps, WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) );
458 + wp_set_script_translations( 'wdkit-cross-copy-paste', 'wdesignkit' );
459 + wp_localize_script(
460 + 'wdkit-cross-copy-paste',
461 + 'wdkitCrossCopyPaste',
462 + array(
463 + 'enabled' => true,
464 + 'version' => WDKIT_VERSION,
465 + 'site' => esc_url( home_url( '/' ) ),
466 + 'builders' => $enabled,
467 + // Direct AJAX access — the editor pages don't always
468 + // load the dashboard wdkitData global. Needed for the
469 + // wdkit_cp_check_widgets endpoint.
470 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
471 + // WDesignKit dashboard (hash-router) page. Missing widgets
472 + // are installed by loading its /create/widget/:w_unique
473 + // route inside a hidden iframe.
474 + 'dashboard_url' => admin_url( 'admin.php?page=wdesign-kit' ),
475 + 'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ),
476 + )
477 + );
478 + }
479 +
480 + /**
481 + * Add Menu Page WdKit.
482 + *
483 + * @since 1.0.0
484 + */
485 + public function wdkit_admin_menu() {
486 + $capability = 'manage_options';
487 +
488 + $options = get_option( 'wkit_white_label' );
489 + $setting_name = ! empty( $options['plugin_name'] ) ? $options['plugin_name'] : __( 'WDesignKit', 'wdesignkit' );
490 + $setting_logo = ! empty( $options['plugin_logo'] ) ? $options['plugin_logo'] : WDKIT_ASSETS . 'images/svg/logo-icon.svg';
491 +
492 + if ( current_user_can( $capability ) ) {
493 + $hook = add_menu_page( $setting_name, $setting_name, 'manage_options', 'wdesign-kit', array( $this, 'wdkit_menu_page_template' ), $setting_logo, 67 );
494 + }
495 + }
496 +
497 + /**
498 + * Load wdkit page content.
499 + *
500 + * @since 1.0.0
501 + */
502 + public function wdkit_menu_page_template() {
503 + echo '<div id="wdesignkit-app"></div>';
504 + }
505 +
506 + /**
507 + * Hide "Need Help" tab in Elementor widgets section when white label is enabled
508 + *
509 + * @since 2.2.4
510 + */
511 + public function wdkit_elementor_hide_help_tab() {
512 + $white_label = get_option( 'wkit_white_label', false );
513 +
514 + if ( ! empty( $white_label['help_link'] ) ) {
515 + wp_add_inline_style(
516 + 'elementor-editor',
517 + '.elementor-control.elementor-control-Need.Help.elementor-control-type-section{display:none!important;}'
518 + );
519 + }
520 + }
521 + }
522 +
523 + Wdkit_Enqueue::get_instance();
524 +}