PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 1.0.16
WDesignKit – AI Templates, Widget Builder & MCP Workflow v1.0.16
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.16, at includes/admin/class-wdkit-enqueue.php

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