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

230 lines 6.4 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 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 }
230