| 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/preview/enqueue_styles', array( $this, 'wdkit_elementor_preview_style' ) ); |
| 69 |
add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'wdkit_elementor_scripts' ) ); |
| 70 |
} |
| 71 |
|
| 72 |
// Bricks editor styles |
| 73 |
add_action( 'wp_enqueue_scripts', array( $this, 'wdkit_bricks_editor_style' ), 10, 1 ); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
/** |
| 78 |
* Enqueue the WDesignKit font library styles. |
| 79 |
* |
| 80 |
* This function loads the custom font styles for the WDesignKit plugin, |
| 81 |
* including the icon font definitions and styling. |
| 82 |
* |
| 83 |
* @since 1.0.0 |
| 84 |
* @return void |
| 85 |
*/ |
| 86 |
public function wdkit_enqueue_styles_library() { |
| 87 |
wp_enqueue_style( 'wdkit-library', WDKIT_URL . 'assets/fonts/style.css', array(), WDKIT_VERSION, false ); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* This function is used to retrieve all post types in WordPress and store them in an array. |
| 92 |
* |
| 93 |
* @since 1.0.0 |
| 94 |
*/ |
| 95 |
public function wdkit_get_post_type_list() { |
| 96 |
$args = array( |
| 97 |
'public' => true, |
| 98 |
'show_ui' => true, |
| 99 |
); |
| 100 |
|
| 101 |
$post_types = get_post_types( $args, 'objects' ); |
| 102 |
$options = array(); |
| 103 |
foreach ( $post_types as $post_type ) { |
| 104 |
$exclude = array( 'attachment' ); |
| 105 |
if ( true === in_array( $post_type->name, $exclude, true ) ) { |
| 106 |
continue; |
| 107 |
} |
| 108 |
|
| 109 |
if ( ! empty( $post_type->name ) && ( 'post' === $post_type->name || 'page' === $post_type->name || 'elementor_library' === $post_type->name || 'nxt_builder' === $post_type->name ) ) { |
| 110 |
$options[ $post_type->name ] = $post_type->label; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
return $options; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Get Editor Use. |
| 119 |
* |
| 120 |
* @since 1.0.0 |
| 121 |
*/ |
| 122 |
protected function wdkit_use_editor() { |
| 123 |
global $current_screen; |
| 124 |
|
| 125 |
$editor = 'wdkit'; |
| 126 |
|
| 127 |
$action = ! empty( $_GET['action'] ) ? $_GET['action'] : ''; |
| 128 |
|
| 129 |
if ( $current_screen->is_block_editor() ) { |
| 130 |
|
| 131 |
if ( array_key_exists( 'action', $_GET ) && isset( $action ) ) { |
| 132 |
if ( 'elementor' === $action ) { |
| 133 |
$editor = 'elementor'; |
| 134 |
} elseif ( 'edit' === $action ) { |
| 135 |
$editor = 'gutenberg'; |
| 136 |
} |
| 137 |
} else { |
| 138 |
$editor = 'gutenberg'; |
| 139 |
} |
| 140 |
} elseif ( 'elementor' === $action ) { |
| 141 |
$editor = 'elementor'; |
| 142 |
} |
| 143 |
|
| 144 |
return $editor; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Load Admin Scripts. |
| 149 |
* |
| 150 |
* @since 1.0.0 |
| 151 |
*/ |
| 152 |
public function wdkit_elementor_scripts() { |
| 153 |
$this->wdkit_admin_scripts( 'elementor' ); |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Elementor Editor Panel Style Loaded |
| 158 |
*/ |
| 159 |
public function wdkit_elementor_editor_style() { |
| 160 |
wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Bricks Editor Panel Style Loaded |
| 165 |
*/ |
| 166 |
public function wdkit_bricks_editor_style() { |
| 167 |
// Only load in Bricks editor |
| 168 |
if ( function_exists( 'bricks_is_builder' ) && bricks_is_builder() ) { |
| 169 |
wp_enqueue_style( 'wdkit-bricks-editor-css', WDKIT_URL . 'assets/css/bricks/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Gutenberg Editor Panel Style Loaded |
| 175 |
*/ |
| 176 |
public function wdkit_gutenberg_editor_style() { |
| 177 |
wp_enqueue_style( 'wdkit-gutenberg-editor-css', WDKIT_URL . 'assets/css/gutenberg/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* Elementor Preview Style Loaded |
| 182 |
* |
| 183 |
* @since 1.0.0 |
| 184 |
*/ |
| 185 |
public function wdkit_elementor_preview_style() { |
| 186 |
wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_preview_styles.css', array(), WDKIT_VERSION ); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Enqueue Scripts admin area. |
| 191 |
* |
| 192 |
* @since 1.0.0 |
| 193 |
* |
| 194 |
* @param string $hook use for check page type. |
| 195 |
*/ |
| 196 |
public function wdkit_admin_scripts( $hook ) { |
| 197 |
|
| 198 |
wp_enqueue_style( 'wdkit-library-preview', WDKIT_URL . 'assets/fonts/style.css', array(), WDKIT_VERSION, false ); |
| 199 |
wp_enqueue_style( 'wdkit-out-dashborad', WDKIT_URL . 'assets/css/dashborad/wdkit-dashborad.css', array(), WDKIT_VERSION, false ); |
| 200 |
|
| 201 |
// Check if we're on a Nexter Extension page |
| 202 |
$is_nexter_page = isset( $_GET['page'] ) && $_GET['page'] === 'nxt_code_snippets'; |
| 203 |
|
| 204 |
// Check if we're on a Theme Builder page (via post_type or page parameter) |
| 205 |
$is_theme_builder_page = ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'nxt_builder' ) || ( isset( $_GET['page'] ) && $_GET['page'] === 'nxt_builder' ); |
| 206 |
|
| 207 |
if ( ! in_array( $hook, array( 'toplevel_page_wdesign-kit', 'elementor', 'post-new.php', 'post.php' ), true ) && !$is_nexter_page && !$is_theme_builder_page ) { |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
wp_enqueue_media(); |
| 212 |
|
| 213 |
$this->wdkit_enqueue_scripts( $hook ); |
| 214 |
$this->wdkit_enqueue_styles(); |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Enqueue Styles admin area. |
| 219 |
* |
| 220 |
* @since 1.0.0 |
| 221 |
*/ |
| 222 |
public function wdkit_enqueue_styles() { |
| 223 |
wp_enqueue_style( 'wdkit-editor-css', WDKIT_URL . 'build/index.css', array(), WDKIT_VERSION ); |
| 224 |
} |
| 225 |
|
| 226 |
/** |
| 227 |
* Register the JavaScript for the admin area. |
| 228 |
* |
| 229 |
* @param string $hook give builder name. |
| 230 |
* @since 1.0.0 |
| 231 |
*/ |
| 232 |
public function wdkit_enqueue_scripts( $hook ) { |
| 233 |
wp_enqueue_script( 'wdkit-editor-js', WDKIT_URL . 'build/index.js', array( 'wp-i18n', 'wp-element', 'wp-components' ), WDKIT_VERSION, true ); |
| 234 |
wp_set_script_translations( 'wdkit-editor-js', 'wdesignkit' ); |
| 235 |
|
| 236 |
$onbording_end = get_option( $this->wdkit_onbording_end ); |
| 237 |
$white_label = get_option( 'wkit_white_label', false ); |
| 238 |
$dark_mode = get_option( 'wdkit_dark_mode', 'light' ); |
| 239 |
|
| 240 |
wp_localize_script( |
| 241 |
'wdkit-editor-js', |
| 242 |
'wdkitData', |
| 243 |
array( |
| 244 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 245 |
'WDKIT_PATH' => WDKIT_PATH, |
| 246 |
'WDKIT_URL' => WDKIT_URL, |
| 247 |
'WDKIT_ASSETS' => WDKIT_ASSETS, |
| 248 |
'wdkit_server_url' => WDKIT_SERVER_SITE_URL, |
| 249 |
'wdkit_site_api_url' => WDKIT_SERVER_API_URL, |
| 250 |
'wdkit_wp_version' => get_bloginfo( 'version' ), |
| 251 |
'home_url' => esc_url( home_url( '/' ) ), |
| 252 |
'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ), |
| 253 |
'post_id' => get_the_ID(), |
| 254 |
'post_type' => get_post_type(), |
| 255 |
'text_domain' => WDKIT_TEXT_DOMAIN, |
| 256 |
'use_editor' => $this->wdkit_use_editor(), |
| 257 |
'post_type_list' => $this->wdkit_get_post_type_list(), |
| 258 |
'WDKIT_onbording_end' => $onbording_end, |
| 259 |
'wdkit_white_label' => $white_label, |
| 260 |
'WDKIT_dark_mode' => $dark_mode, |
| 261 |
/** Widget Builder Path */ |
| 262 |
'WDKIT_SITE_URL' => WDKIT_GET_SITE_URL, |
| 263 |
'WDKIT_DOC_URL' => WDKIT_DOCUMENT, |
| 264 |
'WDKIT_SERVER_PATH' => WDKIT_SERVER_PATH, |
| 265 |
'WDKIT_BUILDER_PATH' => WDKIT_BUILDER_PATH, |
| 266 |
'WDKIT_VERSION' => WDKIT_VERSION, |
| 267 |
|
| 268 |
'gutenberg_template' => Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_template', 'template' ) |
| 269 |
) |
| 270 |
); |
| 271 |
|
| 272 |
/**Ace Editor files for Widget-builder */ |
| 273 |
if ( 'toplevel_page_wdesign-kit' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'builder', 'widget' ) ) { |
| 274 |
wp_enqueue_script( 'widgetBuilder-script-editor-js', WDKIT_URL . 'assets/js/extra/ace.min.js', array( 'wp-element' ), WDKIT_VERSION, true ); |
| 275 |
wp_enqueue_script( 'widgetBuilder-script-editor-cobalt', WDKIT_URL . 'assets/js/extra/theme-cobalt.js', array( 'wp-element' ), WDKIT_VERSION, true ); |
| 276 |
wp_enqueue_script( 'widgetBuilder-script-editor-html', WDKIT_URL . 'assets/js/extra//mode-html.js', array( 'wp-element' ), WDKIT_VERSION, true ); |
| 277 |
} |
| 278 |
|
| 279 |
if ( 'elementor' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor_template', 'template' ) ) { |
| 280 |
wp_enqueue_script( 'wdkit-frontend-editor', WDKIT_ASSETS . '/js/main/elementor/elementor-editor.js', array( 'jquery', 'wp-i18n' ), WDKIT_VERSION, true ); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
/** |
| 285 |
* Add Menu Page WdKit. |
| 286 |
* |
| 287 |
* @since 1.0.0 |
| 288 |
*/ |
| 289 |
public function wdkit_admin_menu() { |
| 290 |
$capability = 'manage_options'; |
| 291 |
|
| 292 |
$options = get_option( 'wkit_white_label' ); |
| 293 |
$setting_name = ! empty( $options['plugin_name'] ) ? $options['plugin_name'] : __( 'WDesignKit', 'wdesignkit' ); |
| 294 |
$setting_logo = ! empty( $options['plugin_logo'] ) ? $options['plugin_logo'] : WDKIT_ASSETS . 'images/svg/logo-icon.svg'; |
| 295 |
|
| 296 |
if ( current_user_can( $capability ) ) { |
| 297 |
$hook = add_menu_page( $setting_name, $setting_name, 'manage_options', 'wdesign-kit', array( $this, 'wdkit_menu_page_template' ), $setting_logo, 67 ); |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* Load wdkit page content. |
| 303 |
* |
| 304 |
* @since 1.0.0 |
| 305 |
*/ |
| 306 |
public function wdkit_menu_page_template() { |
| 307 |
echo '<div id="wdesignkit-app"></div>'; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
Wdkit_Enqueue::get_instance(); |
| 312 |
} |