| 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() { |
| 88 |
wp_enqueue_style( 'wdkit-library', WDKIT_URL . 'assets/fonts/style.css', array(), WDKIT_VERSION, false ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* This function is used to retrieve all post types in WordPress and store them in an array. |
| 93 |
* |
| 94 |
* @since 1.0.0 |
| 95 |
*/ |
| 96 |
public function wdkit_get_post_type_list() { |
| 97 |
$args = array( |
| 98 |
'public' => true, |
| 99 |
'show_ui' => true, |
| 100 |
); |
| 101 |
|
| 102 |
$post_types = get_post_types( $args, 'objects' ); |
| 103 |
$options = array(); |
| 104 |
foreach ( $post_types as $post_type ) { |
| 105 |
$exclude = array( 'attachment' ); |
| 106 |
if ( true === in_array( $post_type->name, $exclude, true ) ) { |
| 107 |
continue; |
| 108 |
} |
| 109 |
|
| 110 |
if ( ! empty( $post_type->name ) && ( 'post' === $post_type->name || 'page' === $post_type->name || 'elementor_library' === $post_type->name || 'nxt_builder' === $post_type->name ) ) { |
| 111 |
$options[ $post_type->name ] = $post_type->label; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
return $options; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Get Editor Use. |
| 120 |
* |
| 121 |
* @since 1.0.0 |
| 122 |
*/ |
| 123 |
protected function wdkit_use_editor() { |
| 124 |
global $current_screen; |
| 125 |
|
| 126 |
$editor = 'wdkit'; |
| 127 |
|
| 128 |
$action = ! empty( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : ''; |
| 129 |
|
| 130 |
if ( $current_screen && $current_screen->is_block_editor() ) { |
| 131 |
|
| 132 |
if ( array_key_exists( 'action', $_GET ) && isset( $action ) ) { |
| 133 |
if ( 'elementor' === $action ) { |
| 134 |
$editor = 'elementor'; |
| 135 |
} elseif ( 'edit' === $action ) { |
| 136 |
$editor = 'gutenberg'; |
| 137 |
} |
| 138 |
} else { |
| 139 |
$editor = 'gutenberg'; |
| 140 |
} |
| 141 |
} elseif ( 'elementor' === $action ) { |
| 142 |
$editor = 'elementor'; |
| 143 |
} |
| 144 |
|
| 145 |
return $editor; |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Load Admin Scripts. |
| 150 |
* |
| 151 |
* @since 1.0.0 |
| 152 |
*/ |
| 153 |
public function wdkit_elementor_scripts() { |
| 154 |
$this->wdkit_admin_scripts( 'elementor' ); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Elementor Editor Panel Style Loaded |
| 159 |
*/ |
| 160 |
public function wdkit_elementor_editor_style() { |
| 161 |
wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); |
| 162 |
|
| 163 |
// Hide WDesignKit logo icon when white label is enabled |
| 164 |
$white_label = get_option( 'wkit_white_label', false ); |
| 165 |
if ( ! empty( $white_label['help_link'] ) ) { |
| 166 |
wp_add_inline_style( 'wdkit-elementor-editor-css', '.elementor-element .icon i.tpae-wdkit-logo:after { display: none !important; }' ); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Bricks Editor Panel Style Loaded |
| 172 |
*/ |
| 173 |
public function wdkit_bricks_editor_style() { |
| 174 |
// Only load in Bricks editor |
| 175 |
if ( function_exists( 'bricks_is_builder' ) && bricks_is_builder() ) { |
| 176 |
wp_enqueue_style( 'wdkit-bricks-editor-css', WDKIT_URL . 'assets/css/bricks/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); |
| 177 |
// Cross-domain copy/paste for Bricks is marked "Coming Soon" — do not enqueue yet. |
| 178 |
|
| 179 |
// Hide WDesignKit logo icon when white label is enabled |
| 180 |
$white_label = get_option( 'wkit_white_label', false ); |
| 181 |
if ( ! empty( $white_label['help_link'] ) ) { |
| 182 |
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;}' ); |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Gutenberg Editor Panel Style Loaded |
| 189 |
*/ |
| 190 |
public function wdkit_gutenberg_editor_style() { |
| 191 |
wp_enqueue_style( 'wdkit-gutenberg-editor-css', WDKIT_URL . 'assets/css/gutenberg/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); |
| 192 |
$this->wdkit_cross_copy_paste_script( 'gutenberg' ); |
| 193 |
|
| 194 |
// Hide WDesignKit logo icon + Need Help panel when white label is enabled |
| 195 |
$white_label = get_option( 'wkit_white_label', false ); |
| 196 |
if ( ! empty( $white_label['help_link'] ) ) { |
| 197 |
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; }' ); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Elementor Preview Style Loaded |
| 203 |
* |
| 204 |
* @since 1.0.0 |
| 205 |
*/ |
| 206 |
public function wdkit_elementor_preview_style() { |
| 207 |
wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_preview_styles.css', array(), WDKIT_VERSION ); |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* Enqueue Scripts admin area. |
| 212 |
* |
| 213 |
* @since 1.0.0 |
| 214 |
* |
| 215 |
* @param string $hook use for check page type. |
| 216 |
*/ |
| 217 |
public function wdkit_admin_scripts( $hook ) { |
| 218 |
|
| 219 |
wp_enqueue_style( 'wdkit-library-preview', WDKIT_URL . 'assets/fonts/style.css', array(), WDKIT_VERSION, false ); |
| 220 |
wp_enqueue_style( 'wdkit-out-dashborad', WDKIT_URL . 'assets/css/dashborad/wdkit-dashborad.css', array(), WDKIT_VERSION, false ); |
| 221 |
|
| 222 |
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; |
| 223 |
$ptype = isset( $_GET['post_type'] ) ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) : ''; |
| 224 |
|
| 225 |
// Check if we're on a Nexter Extension page |
| 226 |
$is_nexter_page = isset( $_GET['page'] ) && sanitize_key( wp_unslash( $_GET['page'] ) ) === 'nxt_code_snippets'; |
| 227 |
|
| 228 |
// Check if we're on a Theme Builder page (via post_type or page parameter) |
| 229 |
$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' ); |
| 230 |
|
| 231 |
if ( ! in_array( $hook, array( 'toplevel_page_wdesign-kit', 'elementor', 'post-new.php', 'post.php' ), true ) && !$is_nexter_page && !$is_theme_builder_page ) { |
| 232 |
return; |
| 233 |
} |
| 234 |
|
| 235 |
wp_enqueue_media(); |
| 236 |
|
| 237 |
$this->wdkit_enqueue_scripts( $hook ); |
| 238 |
$this->wdkit_enqueue_styles(); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Enqueue Styles admin area. |
| 243 |
* |
| 244 |
* @since 1.0.0 |
| 245 |
*/ |
| 246 |
public function wdkit_enqueue_styles() { |
| 247 |
wp_enqueue_style( 'wdkit-editor-css', WDKIT_URL . 'build/index.css', array(), WDKIT_VERSION ); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Register the JavaScript for the admin area. |
| 252 |
* |
| 253 |
* @param string $hook give builder name. |
| 254 |
* @since 1.0.0 |
| 255 |
*/ |
| 256 |
public function wdkit_enqueue_scripts( $hook ) { |
| 257 |
$asset_file = WDKIT_PATH . 'build/index.asset.php'; |
| 258 |
$asset = file_exists( $asset_file ) ? require $asset_file : array( 'dependencies' => array( 'wp-i18n', 'wp-element', 'wp-components' ), 'version' => WDKIT_VERSION ); |
| 259 |
wp_enqueue_script( 'wdkit-editor-js', WDKIT_URL . 'build/index.js', $asset['dependencies'], $asset['version'], true ); |
| 260 |
wp_set_script_translations( 'wdkit-editor-js', 'wdesignkit' ); |
| 261 |
|
| 262 |
$onbording_end = get_option( $this->wdkit_onbording_end ); |
| 263 |
$white_label = get_option( 'wkit_white_label', false ); |
| 264 |
$dark_mode = get_option( 'wdkit_dark_mode', 'light' ); |
| 265 |
|
| 266 |
wp_localize_script( |
| 267 |
'wdkit-editor-js', |
| 268 |
'wdkitData', |
| 269 |
array( |
| 270 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 271 |
'WDKIT_URL' => WDKIT_URL, |
| 272 |
'WDKIT_ASSETS' => WDKIT_ASSETS, |
| 273 |
'wdkit_server_url' => WDKIT_SERVER_SITE_URL, |
| 274 |
'wdkit_site_api_url' => WDKIT_SERVER_API_URL, |
| 275 |
'wdkit_wp_version' => get_bloginfo( 'version' ), |
| 276 |
'home_url' => esc_url( home_url( '/' ) ), |
| 277 |
'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ), |
| 278 |
'post_id' => get_the_ID(), |
| 279 |
'post_type' => get_post_type(), |
| 280 |
'text_domain' => WDKIT_TEXT_DOMAIN, |
| 281 |
'use_editor' => $this->wdkit_use_editor(), |
| 282 |
'post_type_list' => $this->wdkit_get_post_type_list(), |
| 283 |
'WDKIT_onbording_end' => $onbording_end, |
| 284 |
'wdkit_white_label' => $white_label, |
| 285 |
'WDKIT_dark_mode' => $dark_mode, |
| 286 |
/** Widget Builder — public URL only, no server filesystem paths */ |
| 287 |
'WDKIT_SITE_URL' => WDKIT_GET_SITE_URL, |
| 288 |
'WDKIT_DOC_URL' => WDKIT_DOCUMENT, |
| 289 |
'WDKIT_SERVER_PATH' => WDKIT_SERVER_PATH, |
| 290 |
'WDKIT_VERSION' => WDKIT_VERSION, |
| 291 |
|
| 292 |
'gutenberg_template' => Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_template', 'template' ) |
| 293 |
) |
| 294 |
); |
| 295 |
|
| 296 |
/**Ace Editor files for Widget-builder */ |
| 297 |
if ( 'toplevel_page_wdesign-kit' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'builder', 'widget' ) ) { |
| 298 |
wp_enqueue_script( 'widgetBuilder-script-editor-js', WDKIT_URL . 'assets/js/extra/ace.min.js', array( 'wp-element' ), WDKIT_VERSION, true ); |
| 299 |
wp_enqueue_script( 'widgetBuilder-script-editor-cobalt', WDKIT_URL . 'assets/js/extra/theme-cobalt.js', array( 'wp-element' ), WDKIT_VERSION, true ); |
| 300 |
wp_enqueue_script( 'widgetBuilder-script-editor-html', WDKIT_URL . 'assets/js/extra/mode-html.js', array( 'wp-element' ), WDKIT_VERSION, true ); |
| 301 |
} |
| 302 |
|
| 303 |
if ( 'elementor' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor_template', 'template' ) ) { |
| 304 |
wp_enqueue_script( 'wdkit-frontend-editor', WDKIT_ASSETS . '/js/main/elementor/elementor-editor.js', array( 'jquery', 'wp-i18n' ), WDKIT_VERSION, true ); |
| 305 |
$this->wdkit_cross_copy_paste_script( 'elementor' ); |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
/** |
| 310 |
* Enqueue cross-domain copy/paste support for active builders. |
| 311 |
* |
| 312 |
* @since 1.0.0 |
| 313 |
*/ |
| 314 |
public function wdkit_cross_copy_paste_script( $builder = '' ) { |
| 315 |
$settings = get_option( 'wkit_settings_panel', array() ); |
| 316 |
$enabled = array( |
| 317 |
'elementor' => ! empty( $settings['cross_copy_paste_elementor'] ) || ! empty( $settings['cross_copy_paste'] ), |
| 318 |
'gutenberg' => ! empty( $settings['cross_copy_paste_gutenberg'] ) || ! empty( $settings['cross_copy_paste'] ), |
| 319 |
// Bricks support is "Coming Soon" — force-disabled regardless of saved setting. |
| 320 |
'bricks' => false, |
| 321 |
); |
| 322 |
|
| 323 |
if ( empty( array_filter( $enabled ) ) ) { |
| 324 |
return; |
| 325 |
} |
| 326 |
|
| 327 |
if ( ! empty( $builder ) && empty( $enabled[ $builder ] ) ) { |
| 328 |
return; |
| 329 |
} |
| 330 |
|
| 331 |
if ( wp_script_is( 'wdkit-cross-copy-paste', 'enqueued' ) ) { |
| 332 |
return; |
| 333 |
} |
| 334 |
|
| 335 |
$deps = array( 'wp-i18n' ); |
| 336 |
// Gutenberg SlotFill needs these so the block toolbar's |
| 337 |
// "Options" menu can host our "WDesignKit Copy / Paste" items. |
| 338 |
if ( ! empty( $enabled['gutenberg'] ) ) { |
| 339 |
$deps[] = 'wp-plugins'; |
| 340 |
$deps[] = 'wp-element'; |
| 341 |
$deps[] = 'wp-components'; |
| 342 |
$deps[] = 'wp-block-editor'; |
| 343 |
$deps[] = 'wp-data'; |
| 344 |
$deps[] = 'wp-blocks'; |
| 345 |
$deps[] = 'wp-dom-ready'; |
| 346 |
} |
| 347 |
|
| 348 |
wp_enqueue_script( 'wdkit-cross-copy-paste', WDKIT_ASSETS . '/js/main/wdkit-cross-copy-paste.js', $deps, WDKIT_VERSION, true ); |
| 349 |
wp_localize_script( |
| 350 |
'wdkit-cross-copy-paste', |
| 351 |
'wdkitCrossCopyPaste', |
| 352 |
array( |
| 353 |
'enabled' => true, |
| 354 |
'version' => WDKIT_VERSION, |
| 355 |
'site' => esc_url( home_url( '/' ) ), |
| 356 |
'builders' => $enabled, |
| 357 |
// Direct AJAX access — the editor pages don't always |
| 358 |
// load the dashboard wdkitData global. Needed for the |
| 359 |
// wdkit_cp_check_widgets endpoint. |
| 360 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 361 |
'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ), |
| 362 |
) |
| 363 |
); |
| 364 |
} |
| 365 |
|
| 366 |
/** |
| 367 |
* Add Menu Page WdKit. |
| 368 |
* |
| 369 |
* @since 1.0.0 |
| 370 |
*/ |
| 371 |
public function wdkit_admin_menu() { |
| 372 |
$capability = 'manage_options'; |
| 373 |
|
| 374 |
$options = get_option( 'wkit_white_label' ); |
| 375 |
$setting_name = ! empty( $options['plugin_name'] ) ? $options['plugin_name'] : __( 'WDesignKit', 'wdesignkit' ); |
| 376 |
$setting_logo = ! empty( $options['plugin_logo'] ) ? $options['plugin_logo'] : WDKIT_ASSETS . 'images/svg/logo-icon.svg'; |
| 377 |
|
| 378 |
if ( current_user_can( $capability ) ) { |
| 379 |
$hook = add_menu_page( $setting_name, $setting_name, 'manage_options', 'wdesign-kit', array( $this, 'wdkit_menu_page_template' ), $setting_logo, 67 ); |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Load wdkit page content. |
| 385 |
* |
| 386 |
* @since 1.0.0 |
| 387 |
*/ |
| 388 |
public function wdkit_menu_page_template() { |
| 389 |
echo '<div id="wdesignkit-app"></div>'; |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Hide "Need Help" tab in Elementor widgets section when white label is enabled |
| 394 |
* |
| 395 |
* @since 2.2.4 |
| 396 |
*/ |
| 397 |
public function wdkit_elementor_hide_help_tab() { |
| 398 |
$white_label = get_option( 'wkit_white_label', false ); |
| 399 |
|
| 400 |
if ( ! empty( $white_label['help_link'] ) ) { |
| 401 |
wp_add_inline_style( |
| 402 |
'elementor-editor', |
| 403 |
'.elementor-control.elementor-control-Need.Help.elementor-control-type-section{display:none!important;}' |
| 404 |
); |
| 405 |
} |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
Wdkit_Enqueue::get_instance(); |
| 410 |
} |