true, 'show_ui' => true, ); $post_types = get_post_types( $args, 'objects' ); $options = array(); foreach ( $post_types as $post_type ) { $exclude = array( 'attachment' ); if ( true === in_array( $post_type->name, $exclude, true ) ) { continue; } if ( ! empty( $post_type->name ) && ( 'post' === $post_type->name || 'page' === $post_type->name || 'elementor_library' === $post_type->name || 'nxt_builder' === $post_type->name ) ) { $options[ $post_type->name ] = $post_type->label; } } return $options; } /** * Get Editor Use. * * @since 1.0.0 */ protected function wdkit_use_editor() { global $current_screen; $editor = 'wdkit'; $action = ! empty( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : ''; if ( $current_screen && $current_screen->is_block_editor() ) { if ( array_key_exists( 'action', $_GET ) && isset( $action ) ) { if ( 'elementor' === $action ) { $editor = 'elementor'; } elseif ( 'edit' === $action ) { $editor = 'gutenberg'; } } else { $editor = 'gutenberg'; } } elseif ( 'elementor' === $action ) { $editor = 'elementor'; } return $editor; } /** * Load Admin Scripts. * * @since 1.0.0 */ public function wdkit_elementor_scripts() { $this->wdkit_admin_scripts( 'elementor' ); } /** * Elementor Editor Panel Style Loaded */ public function wdkit_elementor_editor_style() { wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); // Hide WDesignKit logo icon when white label is enabled $white_label = get_option( 'wkit_white_label', false ); if ( ! empty( $white_label['help_link'] ) ) { wp_add_inline_style( 'wdkit-elementor-editor-css', '.elementor-element .icon i.tpae-wdkit-logo:after { display: none !important; }' ); } } /** * Bricks Editor Panel Style Loaded */ public function wdkit_bricks_editor_style() { // Only load in Bricks editor if ( function_exists( 'bricks_is_builder' ) && bricks_is_builder() ) { wp_enqueue_style( 'wdkit-bricks-editor-css', WDKIT_URL . 'assets/css/bricks/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); // Cross-domain copy/paste for Bricks is marked "Coming Soon" — do not enqueue yet. // Hide WDesignKit logo icon when white label is enabled $white_label = get_option( 'wkit_white_label', false ); if ( ! empty( $white_label['help_link'] ) ) { 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;}' ); } } } /** * Gutenberg Editor Panel Style Loaded */ public function wdkit_gutenberg_editor_style() { wp_enqueue_style( 'wdkit-gutenberg-editor-css', WDKIT_URL . 'assets/css/gutenberg/wdkit_enqueue_editor_styles.css', array(), WDKIT_VERSION ); $this->wdkit_cross_copy_paste_script( 'gutenberg' ); // Hide WDesignKit logo icon + Need Help panel when white label is enabled $white_label = get_option( 'wkit_white_label', false ); if ( ! empty( $white_label['help_link'] ) ) { 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; }' ); } } /** * Elementor Preview Style Loaded * * @since 1.0.0 */ public function wdkit_elementor_preview_style() { wp_enqueue_style( 'wdkit-elementor-editor-css', WDKIT_URL . 'assets/css/elementor/wdkit_enqueue_preview_styles.css', array(), WDKIT_VERSION ); } /** * Enqueue Scripts admin area. * * @since 1.0.0 * * @param string $hook use for check page type. */ public function wdkit_admin_scripts( $hook ) { // Deliberately BEFORE the screen guard below: this 1.4 KB stylesheet contains nothing but // #adminmenu rules for the WDesignKit menu item, and the admin menu is rendered on every // admin screen. Gating it to WDesignKit's own screens leaves the menu icon unstyled // everywhere else — the masked-SVG ::before never applies, so the raw shows through. // Do not "optimise" this into the guard (ClickUp 86d41cnze). wp_enqueue_style( 'wdkit-out-dashborad', WDKIT_URL . 'assets/css/dashborad/wdkit-dashborad.css', array(), WDKIT_VERSION, false ); $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; $ptype = isset( $_GET['post_type'] ) ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) : ''; // Check if we're on a Nexter Extension page $is_nexter_page = isset( $_GET['page'] ) && sanitize_key( wp_unslash( $_GET['page'] ) ) === 'nxt_code_snippets'; // Check if we're on a Theme Builder page (via post_type or page parameter) $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' ); if ( ! in_array( $hook, array( 'toplevel_page_wdesign-kit', 'elementor', 'post-new.php', 'post.php' ), true ) && !$is_nexter_page && !$is_theme_builder_page ) { return; } // Moved BELOW the screen guard: this is the 9 KB WDesignKit icon font, used only by // WDesignKit's own UI (no #adminmenu rules in it), yet it was enqueued on every wp-admin // screen — dashboard, posts list, media library, plugins page (ClickUp 86d41cnze). // The admin-menu stylesheet is NOT gated here; see the note at the top of this method. wp_enqueue_style( 'wdkit-library-preview', WDKIT_URL . 'assets/fonts/style.css', array(), WDKIT_VERSION, false ); wp_enqueue_media(); $this->wdkit_enqueue_scripts( $hook ); $this->wdkit_enqueue_styles(); } /** * Enqueue Styles admin area. * * @since 1.0.0 */ public function wdkit_enqueue_styles() { wp_enqueue_style( 'wdkit-editor-css', WDKIT_URL . 'build/index.css', array(), WDKIT_VERSION ); /** * The build emits a right-to-left stylesheet (build/index-rtl.css) because the * source CSS uses physical left/right properties. WordPress does not auto-load * the -rtl variant; registering it here makes core swap in index-rtl.css on RTL * locales (Arabic, Hebrew, Farsi, Urdu) so the admin layout mirrors correctly. */ wp_style_add_data( 'wdkit-editor-css', 'rtl', 'replace' ); } /** * Register the JavaScript for the admin area. * * @param string $hook give builder name. * @since 1.0.0 */ public function wdkit_enqueue_scripts( $hook ) { $asset_file = WDKIT_PATH . 'build/index.min.asset.php'; $asset = file_exists( $asset_file ) ? require $asset_file : array( 'dependencies' => array( 'wp-i18n', 'wp-element', 'wp-components' ), 'version' => WDKIT_VERSION ); /** * JS translations catalog. * * The app ships as a large minified bundle (build/index.min.js) which * `wp i18n make-pot` skips (all *.min.js are skipped) and could not parse * within WordPress.org's budget anyway. build/wdk-i18n-strings.js is a * small, readable catalog of every translatable JS string (generated from * src/ by bin/generate-i18n-strings.js). WordPress.org extracts strings * from it and builds the per-locale JSON keyed to this handle; loading it * here populates the shared wp.i18n store so the whole React app is * translated. It is a dependency of the app bundle so it (and its inline * translation data) load first. */ $script_deps = $asset['dependencies']; if ( file_exists( WDKIT_PATH . 'build/wdk-i18n-strings.js' ) ) { wp_enqueue_script( 'wdkit-editor-i18n', WDKIT_URL . 'build/wdk-i18n-strings.js', array( 'wp-i18n' ), $asset['version'], array( 'in_footer' => true, 'strategy' => 'defer' ) ); wp_set_script_translations( 'wdkit-editor-i18n', 'wdesignkit' ); $script_deps = array_merge( $script_deps, array( 'wdkit-editor-i18n' ) ); } wp_enqueue_script( 'wdkit-editor-js', WDKIT_URL . 'build/index.min.js', $script_deps, $asset['version'], array( 'in_footer' => true, 'strategy' => 'defer' ) ); wp_set_script_translations( 'wdkit-editor-js', 'wdesignkit' ); $onbording_end = get_option( $this->wdkit_onbording_end ); $white_label = get_option( 'wkit_white_label', false ); $dark_mode = get_option( 'wdkit_dark_mode', 'light' ); wp_localize_script( 'wdkit-editor-js', 'wdkitData', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'WDKIT_URL' => WDKIT_URL, 'WDKIT_ASSETS' => WDKIT_ASSETS, 'wdkit_server_url' => WDKIT_SERVER_SITE_URL, 'wdkit_site_api_url' => WDKIT_SERVER_API_URL, 'wdkit_wp_version' => get_bloginfo( 'version' ), 'home_url' => esc_url( home_url( '/' ) ), 'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ), 'post_id' => get_the_ID(), 'post_type' => get_post_type(), 'text_domain' => WDKIT_TEXT_DOMAIN, 'use_editor' => $this->wdkit_use_editor(), 'post_type_list' => $this->wdkit_get_post_type_list(), 'WDKIT_onbording_end' => $onbording_end, 'wdkit_white_label' => $white_label, 'WDKIT_dark_mode' => $dark_mode, /** Widget Builder — public URL only, no server filesystem paths */ 'WDKIT_SITE_URL' => WDKIT_GET_SITE_URL, 'WDKIT_DOC_URL' => WDKIT_DOCUMENT, 'WDKIT_SERVER_PATH' => WDKIT_SERVER_PATH, 'WDKIT_VERSION' => WDKIT_VERSION, 'gutenberg_template' => Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_template', 'template' ), /** * Data Sharing switcher, Settings panel. * * Read as a SITE option — the consent is one answer per install, not per blog. The * class guard matches the one in wdesignkit.php: on a white-labelled install, or when * a sibling POSIMYTH plugin's SDK copy won the loader, the tracker class is never * declared and the constant reference would fatal. * * Both references are root-namespaced. This file lives in wdkit\WdKit_enqueue while * the SDK class is declared in the global namespace: a string class name is always * global so the guard passed either way, but an unprefixed `Posimyth_Tracker_WDK::` * resolves against THIS namespace and fatals on every admin page load. */ 'wdkit_data_sharing' => class_exists( '\Posimyth_Tracker_WDK' ) ? (bool) get_site_option( \Posimyth_Tracker_WDK::OPT_IN_OPTION, false ) : false, 'wdkit_consent_nonce' => wp_create_nonce( 'posimyth_consent_wdk' ), /** * Whether the Data Sharing card may be shown at all. * * Tracks the tracker class rather than the white-label flag: a rebranded install now * keeps the feature (see wdesignkit.php), so this is false only when the SDK genuinely * failed to load — a sibling POSIMYTH plugin winning the loader with a diverged copy. * Rendering a switch in that case would offer a save with no handler behind it. * * Separate from wdkit_data_sharing on purpose: that one is false both when sharing is * off and when the feature is absent, which cannot tell the two apart. */ 'wdkit_data_sharing_available' => class_exists( '\Posimyth_Tracker_WDK' ), /** * Reseller's product name, for the Data Sharing copy that would otherwise say * "WDesignKit" on a plugin they have rebranded as their own. */ 'wdkit_data_sharing_name' => ! empty( $white_label['plugin_name'] ) ? $white_label['plugin_name'] : 'WDesignKit', /** help_link is the reseller's "hide POSIMYTH documentation links" switch. */ 'wdkit_data_sharing_docs' => empty( $white_label['help_link'] ) ? WDKIT_DOCUMENT . 'data-sharing/' : '' ) ); /**Ace Editor files for Widget-builder */ if ( 'toplevel_page_wdesign-kit' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'builder', 'widget' ) ) { wp_enqueue_script( 'widgetBuilder-script-editor-js', WDKIT_URL . 'assets/js/extra/ace.min.js', array( 'wp-element' ), WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) ); wp_enqueue_script( 'widgetBuilder-script-editor-cobalt', WDKIT_URL . 'assets/js/extra/theme-cobalt.js', array( 'wp-element' ), WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) ); wp_enqueue_script( 'widgetBuilder-script-editor-html', WDKIT_URL . 'assets/js/extra/mode-html.js', array( 'wp-element' ), WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) ); } if ( 'elementor' === $hook && Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor_template', 'template' ) ) { wp_enqueue_script( 'wdkit-frontend-editor', WDKIT_ASSETS . 'js/main/elementor/elementor-editor.js', array( 'jquery', 'wp-i18n' ), WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) ); wp_set_script_translations( 'wdkit-frontend-editor', 'wdesignkit' ); $this->wdkit_cross_copy_paste_script( 'elementor' ); } } /** * Enqueue cross-domain copy/paste support for active builders. * * @since 1.0.0 */ public function wdkit_cross_copy_paste_script( $builder = '' ) { $settings = get_option( 'wkit_settings_panel', array() ); $enabled = array( 'elementor' => ! empty( $settings['cross_copy_paste_elementor'] ) || ! empty( $settings['cross_copy_paste'] ), 'gutenberg' => ! empty( $settings['cross_copy_paste_gutenberg'] ) || ! empty( $settings['cross_copy_paste'] ), // Bricks support is "Coming Soon" — force-disabled regardless of saved setting. 'bricks' => false, ); if ( empty( array_filter( $enabled ) ) ) { return; } if ( ! empty( $builder ) && empty( $enabled[ $builder ] ) ) { return; } if ( wp_script_is( 'wdkit-cross-copy-paste', 'enqueued' ) ) { return; } $deps = array( 'wp-i18n' ); // Gutenberg SlotFill needs these so the block toolbar's // "Options" menu can host our "WDesignKit Copy / Paste" items. if ( ! empty( $enabled['gutenberg'] ) ) { $deps[] = 'wp-plugins'; $deps[] = 'wp-element'; $deps[] = 'wp-components'; $deps[] = 'wp-block-editor'; $deps[] = 'wp-data'; $deps[] = 'wp-blocks'; $deps[] = 'wp-dom-ready'; } wp_enqueue_script( 'wdkit-cross-copy-paste', WDKIT_ASSETS . 'js/main/wdkit-cross-copy-paste.js', $deps, WDKIT_VERSION, array( 'in_footer' => true, 'strategy' => 'defer' ) ); wp_set_script_translations( 'wdkit-cross-copy-paste', 'wdesignkit' ); wp_localize_script( 'wdkit-cross-copy-paste', 'wdkitCrossCopyPaste', array( 'enabled' => true, 'version' => WDKIT_VERSION, 'site' => esc_url( home_url( '/' ) ), 'builders' => $enabled, // Direct AJAX access — the editor pages don't always // load the dashboard wdkitData global. Needed for the // wdkit_cp_check_widgets endpoint. 'ajax_url' => admin_url( 'admin-ajax.php' ), // WDesignKit dashboard (hash-router) page. Missing widgets // are installed by loading its /create/widget/:w_unique // route inside a hidden iframe. 'dashboard_url' => admin_url( 'admin.php?page=wdesign-kit' ), 'kit_nonce' => wp_create_nonce( 'wdkit_nonce' ), ) ); } /** * Add Menu Page WdKit. * * @since 1.0.0 */ public function wdkit_admin_menu() { $capability = 'manage_options'; $options = get_option( 'wkit_white_label' ); $setting_name = ! empty( $options['plugin_name'] ) ? $options['plugin_name'] : __( 'WDesignKit', 'wdesignkit' ); $setting_logo = ! empty( $options['plugin_logo'] ) ? $options['plugin_logo'] : WDKIT_ASSETS . 'images/svg/logo-icon.svg'; if ( current_user_can( $capability ) ) { $hook = add_menu_page( $setting_name, $setting_name, 'manage_options', 'wdesign-kit', array( $this, 'wdkit_menu_page_template' ), $setting_logo, 67 ); } } /** * Load wdkit page content. * * @since 1.0.0 */ public function wdkit_menu_page_template() { echo '
'; } /** * Hide "Need Help" tab in Elementor widgets section when white label is enabled * * @since 2.2.4 */ public function wdkit_elementor_hide_help_tab() { $white_label = get_option( 'wkit_white_label', false ); if ( ! empty( $white_label['help_link'] ) ) { wp_add_inline_style( 'elementor-editor', '.elementor-control.elementor-control-Need.Help.elementor-control-type-section{display:none!important;}' ); } } } Wdkit_Enqueue::get_instance(); }