PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 1.0.21
WDesignKit – AI Templates, Widget Builder & MCP Workflow v1.0.21
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 1.0.17 All 128 releases
wdesignkit / includes / admin / class-wdkit-enqueue.php

class-wdkit-enqueue.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow 1.0.21, at includes/admin/class-wdkit-enqueue.php

244 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
104 $action = ! empty( $_GET['action'] ) ? $_GET['action'] : '';
105
106 if( $current_screen->is_block_editor() ){
107
108 if ( array_key_exists('action', $_GET) && isset( $action ) ) {
109 if ( 'elementor' === $action ) {
110 $editor = 'elementor';
111 } else if ( 'edit' === $action ) {
112 $editor = 'gutenberg';
113 }
114 } else {
115 $editor = 'gutenberg';
116 }
117 } else {
118 if ( 'elementor' === $action ) {
119 $editor = 'elementor';
120 }
121 }
122
123 return $editor;
124 }
125
126 /**
127 * Load Admin Scripts.
128 *
129 * @since 1.0.0
130 */
131 public function wdkit_elementor_scripts() {
132 $this->wdkit_admin_scripts( 'elementor' );
133 }
134
135 /**
136 * Elementor Preview Style Loaded
137 *
138 * @since 1.0.0
139 */
140 public function wdkit_elementor_preview_style() {
141 wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_preview_styles.css', array(), WDKIT_VERSION );
142 }
143
144 /**
145 * Enqueue Scripts admin area.
146 *
147 * @since 1.0.0
148 *
149 * @param string $hook use for check page type.
150 */
151 public function wdkit_admin_scripts( $hook ) {
152 if ( ! in_array( $hook, array( 'toplevel_page_wdesign-kit', 'elementor', 'post-new.php', 'post.php' ), true ) ) {
153 return;
154 }
155
156 $this->wdkit_enqueue_scripts( $hook );
157 $this->wdkit_enqueue_styles();
158 }
159
160 /**
161 * Enqueue Styles admin area.
162 *
163 * @since 1.0.0
164 */
165 public function wdkit_enqueue_styles() {
166 wp_enqueue_style( 'wdkit-editor-css', WDKIT_URL . 'build/index.css', array(), WDKIT_VERSION );
167 }
168
169 /**
170 * Register the JavaScript for the admin area.
171 *
172 * @param string $hook give builder name.
173 * @since 1.0.0
174 */
175 public function wdkit_enqueue_scripts( $hook ) {
176 wp_enqueue_script( 'wdkit-editor-js', WDKIT_URL . 'build/index.js', array( 'wp-i18n', 'wp-element', 'wp-components' ), WDKIT_VERSION, true );
177
178 $onbording_end = get_option( $this->wdkit_onbording_end );
179
180 wp_localize_script(
181 'wdkit-editor-js',
182 'wdkitData',
183 array(
184 'ajax_url' => admin_url( 'admin-ajax.php' ),
185 'WDKIT_PATH' => WDKIT_PATH,
186 'WDKIT_URL' => WDKIT_URL,
187 'WDKIT_ASSETS' => WDKIT_ASSETS,
188 'wdkit_server_url' => WDKIT_SERVER_SITE_URL,
189 'home_url' => esc_url( home_url( '/' ) ),
190 'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ),
191 'post_id' => get_the_ID(),
192 'post_type' => get_post_type(),
193 'text_domain' => WDKIT_TEXT_DOMAIN,
194 'use_editor' => $this->wdkit_use_editor(),
195 'post_type_list' => $this->wdkit_get_post_type_list(),
196 'WDKIT_onbording_end' => $onbording_end,
197
198 /** Widget Builder Path */
199 'WDKIT_SITE_URL' => WDKIT_GET_SITE_URL,
200 'WDKIT_SERVER_PATH' => WDKIT_SERVER_PATH,
201 'WDKIT_BUILDER_PATH' => WDKIT_BUILDER_PATH,
202 'WDKIT_VERSION' => WDKIT_VERSION,
203
204 'gutenberg_template' => Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_template', 'template' ),
205 )
206 );
207
208 /**Ace Editor files for Widget-builder */
209 if ( 'toplevel_page_wdesign-kit' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'builder', 'widget' ) ) {
210 wp_enqueue_script( 'widgetBuilder-script-editor-js', WDKIT_URL . 'assets/js/extra/ace.min.js', array( 'wp-element' ), WDKIT_VERSION, true );
211 wp_enqueue_script( 'widgetBuilder-script-editor-cobalt', WDKIT_URL . 'assets/js/extra/theme-cobalt.js', array( 'wp-element' ), WDKIT_VERSION, true );
212 wp_enqueue_script( 'widgetBuilder-script-editor-html', WDKIT_URL . 'assets/js/extra//mode-html.js', array( 'wp-element' ), WDKIT_VERSION, true );
213 }
214
215 if ( 'elementor' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor_template', 'template' ) ) {
216 wp_enqueue_script( 'wdkit-frontend-editor', WDKIT_ASSETS . '/js/main/elementor/elementor-editor.js', array( 'jquery', 'wp-i18n' ), WDKIT_VERSION, true );
217 }
218 }
219
220 /**
221 * Add Menu Page WdKit.
222 *
223 * @since 1.0.0
224 */
225 public function wdkit_admin_menu() {
226 $capability = 'manage_options';
227 if ( current_user_can( $capability ) ) {
228 $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' );
229 }
230 }
231
232 /**
233 * Load wdkit page content.
234 *
235 * @since 1.0.0
236 */
237 public function wdkit_menu_page_template() {
238 echo '<div id="wdesignkit-app"></div>';
239 }
240 }
241
242 Wdkit_Enqueue::get_instance();
243 }
244