Admin enqueue * Backend scripts & styles * */ if ( ! defined( 'ABSPATH' ) ) exit; function tbkkt_admin_style_deps( string ...$deps ): array { if ( empty( $deps ) ) return array( 'wp-base-styles' ); return $deps; } add_action( 'init', function (): void { // Base editor style $resolved_editor = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'editor.css' ); wp_register_style( 'tbkkt-editor', $resolved_editor['url'], tbkkt_admin_style_deps( 'wp-base-styles' ), $resolved_editor['version'] ); // Extension editor: Responsive spacing if ( tbkkt_settings_feature_is_enabled( 'responsive_spacing' ) ) : $resolved = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'editor-responsive-spacing.css' ); wp_register_style( 'tbkkt-editor-responsive-spacing', $resolved['url'], tbkkt_admin_style_deps( 'tbkkt-editor' ), $resolved['version'] ); endif; // Extension editor: Responsive font size if ( tbkkt_settings_feature_is_enabled( 'responsive_font_size' ) ) : $resolved = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'editor-responsive-font-size.css' ); wp_register_style( 'tbkkt-editor-responsive-font-size', $resolved['url'], tbkkt_admin_style_deps( 'tbkkt-editor' ), $resolved['version'] ); endif; // Extension editor: Scroll animation if ( tbkkt_settings_feature_is_enabled( 'scroll_animation' ) ) : $resolved = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'editor-scroll-animation.css' ); wp_register_style( 'tbkkt-editor-scroll-animation', $resolved['url'], tbkkt_admin_style_deps( 'tbkkt-editor' ), $resolved['version'] ); endif; // Extension editor: Position if ( tbkkt_settings_feature_is_enabled( 'position' ) ) : $resolved = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'editor-position.css' ); wp_register_style( 'tbkkt-editor-position', $resolved['url'], tbkkt_admin_style_deps( 'tbkkt-editor' ), $resolved['version'] ); endif; // Extension editor: Responsive visibility if ( tbkkt_settings_feature_is_enabled( 'responsive_visibility' ) ) : $resolved = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'editor-responsive-visibility.css' ); wp_register_style( 'tbkkt-editor-responsive-visibility', $resolved['url'], tbkkt_admin_style_deps( 'tbkkt-editor' ), $resolved['version'] ); endif; // Extension editor: Floating overlays if ( tbkkt_settings_feature_is_enabled( 'floating_overlays' ) ) : $resolved = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'editor-overlays.css' ); wp_register_style( 'tbkkt-editor-overlays', $resolved['url'], tbkkt_admin_style_deps( 'tbkkt-editor' ), $resolved['version'] ); endif; // Block editor: Container if ( tbkkt_settings_is_block_enabled( 'tbkkt/container' ) ) : $resolved = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'container/editor.css' ); wp_register_style( 'tbkkt-container-editor', $resolved['url'], tbkkt_admin_style_deps( 'tbkkt-editor' ), $resolved['version'] ); endif; // Block editor: Icon if ( tbkkt_settings_is_block_enabled( 'tbkkt/icon' ) ) : $resolved = tbkkt_responsive_breakpoints_css_get_resolved_style_registration( 'icon/editor.css' ); wp_register_style( 'tbkkt-icon-editor', $resolved['url'], tbkkt_admin_style_deps( 'tbkkt-editor' ), $resolved['version'] ); endif; }, 5 ); /** * Settings screen */ add_action( 'admin_enqueue_scripts', function ( string $hook_suffix ): void { if ( $hook_suffix !== 'settings_page_' . TBKKT_SETTINGS_PAGE_SLUG ) return; $admin_settings_css = 'assets/css/admin-settings.css'; wp_enqueue_style( 'tbkkt-admin-settings', TBKKT_PLUGIN_URL . $admin_settings_css, tbkkt_admin_style_deps(), tbkkt_plugin_get_asset_file_mtime( $admin_settings_css ), 'all' ); $admin_settings_js = 'assets/js/admin-settings.js'; wp_enqueue_script( 'tbkkt-admin-settings', TBKKT_PLUGIN_URL . $admin_settings_js, array(), tbkkt_plugin_get_asset_file_mtime( $admin_settings_js ), true ); wp_localize_script( 'tbkkt-admin-settings', 'tbkktSettingsCards', array( 'queryVar' => TBKKT_SETTINGS_CARDS_FILTER_QUERY_VAR, ) ); }, 5 ); /** * Post editor, site editor, etc */ function tbkkt_admin_is_block_editor_canvas(): bool { if ( ! is_admin() ) return false; global $pagenow; if ( isset( $pagenow ) && 'site-editor.php' === $pagenow ) return true; $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; return $screen && $screen->is_block_editor(); } add_action( 'admin_enqueue_scripts', function () { if ( ! tbkkt_admin_is_block_editor_canvas() ) return; // Base editor wp_enqueue_style( 'tbkkt-editor' ); // Extension editor styles if ( wp_style_is( 'tbkkt-editor-responsive-spacing', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-responsive-spacing' ); endif; if ( wp_style_is( 'tbkkt-editor-responsive-font-size', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-responsive-font-size' ); endif; if ( wp_style_is( 'tbkkt-editor-scroll-animation', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-scroll-animation' ); endif; if ( wp_style_is( 'tbkkt-editor-position', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-position' ); endif; if ( wp_style_is( 'tbkkt-editor-responsive-visibility', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-responsive-visibility' ); endif; if ( wp_style_is( 'tbkkt-editor-overlays', 'registered' ) ) : if ( tbkkt_settings_feature_is_enabled( 'floating_overlays' ) ) : wp_enqueue_style( 'tbkkt-editor-overlays' ); endif; endif; // Block editor styles if ( wp_style_is( 'tbkkt-container-editor', 'registered' ) ) : wp_enqueue_style( 'tbkkt-container-editor' ); endif; if ( wp_style_is( 'tbkkt-icon-editor', 'registered' ) ) : wp_enqueue_style( 'tbkkt-icon-editor' ); endif; if ( tbkkt_settings_editor_toolbar_is_enabled() ) : $editor_toolbar_js = 'assets/js/editor-toolbar.js'; wp_enqueue_script( 'tbkkt-editor-toolbar', TBKKT_PLUGIN_URL . $editor_toolbar_js, array( 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n', 'wp-data', ), tbkkt_plugin_get_asset_file_mtime( $editor_toolbar_js ), true ); endif; if ( ! tbkkt_settings_is_any_core_feature_enabled() ) return; global $pagenow; $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen && ( ! isset( $pagenow ) || 'site-editor.php' !== $pagenow ) ) return; $editor_features_js = 'assets/js/editor-features.js'; wp_enqueue_script( 'tbkkt-editor-features', TBKKT_PLUGIN_URL . $editor_features_js, array( 'wp-element', 'wp-block-editor', 'wp-blocks', 'wp-hooks', 'wp-components', 'wp-html-entities', 'wp-i18n', 'wp-data', ), tbkkt_plugin_get_asset_file_mtime( $editor_features_js ), true ); if ( wp_style_is( 'wp-media-views', 'registered' ) ) : wp_enqueue_style( 'wp-media-views' ); endif; $localize_features = array(); if ( tbkkt_settings_feature_is_enabled( 'responsive_font_size' ) ) : $localize_features[ TBKKT_FEATURE_RESPONSIVE_FONT_SIZE ] = tbkkt_supported_blocks_get_list( TBKKT_FEATURE_RESPONSIVE_FONT_SIZE ); endif; if ( tbkkt_settings_feature_is_enabled( 'responsive_spacing' ) ) : $localize_features[ TBKKT_FEATURE_RESPONSIVE_MARGIN ] = tbkkt_supported_blocks_get_list( TBKKT_FEATURE_RESPONSIVE_MARGIN ); $localize_features[ TBKKT_FEATURE_RESPONSIVE_PADDING ] = tbkkt_supported_blocks_get_list( TBKKT_FEATURE_RESPONSIVE_PADDING ); endif; if ( tbkkt_settings_feature_is_enabled( 'scroll_animation' ) ) : $localize_features[ TBKKT_FEATURE_SCROLL_ANIMATION ] = tbkkt_supported_blocks_get_list( TBKKT_FEATURE_SCROLL_ANIMATION ); endif; if ( tbkkt_settings_feature_is_enabled( 'responsive_visibility' ) ) : $localize_features[ TBKKT_FEATURE_RESPONSIVE_VISIBILITY ] = tbkkt_supported_blocks_get_list( TBKKT_FEATURE_RESPONSIVE_VISIBILITY ); endif; if ( tbkkt_settings_feature_is_enabled( 'position' ) ) : $localize_features[ TBKKT_FEATURE_POSITION ] = tbkkt_supported_blocks_get_list( TBKKT_FEATURE_POSITION ); endif; wp_localize_script( 'tbkkt-editor-features', 'tbkktSupportedBlocksData', array( 'groups' => tbkkt_supported_blocks_groups(), 'features' => $localize_features, 'editorFeatures' => array( 'responsive_font_size' => tbkkt_settings_feature_is_enabled( 'responsive_font_size' ), 'responsive_spacing' => tbkkt_settings_feature_is_enabled( 'responsive_spacing' ), 'scroll_animation' => tbkkt_settings_feature_is_enabled( 'scroll_animation' ), 'responsive_visibility' => tbkkt_settings_feature_is_enabled( 'responsive_visibility' ), 'position' => tbkkt_settings_feature_is_enabled( 'position' ), ), ) ); wp_localize_script( 'tbkkt-editor-features', 'tbkktI18n', tbkkt_admin_components_get_i18n_strings() ); if ( tbkkt_settings_feature_is_enabled( 'scroll_animation' ) ) : $animation_engine_js = 'assets/js/animation-engine.js'; $animation_scroll_js = 'assets/js/animation-scroll.js'; wp_enqueue_script( 'tbkkt-animation-engine', TBKKT_PLUGIN_URL . $animation_engine_js, array(), tbkkt_plugin_get_asset_file_mtime( $animation_engine_js ), true ); wp_enqueue_script( 'tbkkt-animation-scroll', TBKKT_PLUGIN_URL . $animation_scroll_js, array( 'tbkkt-animation-engine' ), tbkkt_plugin_get_asset_file_mtime( $animation_scroll_js ), true ); $should_enqueue_overlay = false; if ( $screen && defined( 'TBKKT_OVERLAY_POST_TYPE' ) && $screen->post_type === TBKKT_OVERLAY_POST_TYPE ) : $should_enqueue_overlay = true; endif; if ( $should_enqueue_overlay && tbkkt_settings_feature_is_enabled( 'floating_overlays' ) ) : $animation_overlay_js = 'assets/js/animation-overlay.js'; wp_enqueue_script( 'tbkkt-animation-overlay', TBKKT_PLUGIN_URL . $animation_overlay_js, array( 'tbkkt-animation-engine' ), tbkkt_plugin_get_asset_file_mtime( $animation_overlay_js ), true ); endif; endif; }, 20 ); /** * Overlay CPT: list table (edit.php?post_type=tms-overlay) */ add_action( 'admin_enqueue_scripts', function ( string $hook_suffix ): void { if ( 'edit.php' !== $hook_suffix ) return; if ( ! defined( 'TBKKT_OVERLAY_POST_TYPE' ) ) return; $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || TBKKT_OVERLAY_POST_TYPE !== $screen->post_type ) return; $admin_overlays_css = 'assets/css/admin-overlays.css'; wp_enqueue_style( 'tbkkt-overlay-admin-overlays', TBKKT_PLUGIN_URL . $admin_overlays_css, tbkkt_admin_style_deps(), tbkkt_plugin_get_asset_file_mtime( $admin_overlays_css ), 'all' ); $admin_overlays_js = 'assets/js/admin-overlays.js'; wp_enqueue_script( 'tbkkt-overlay-admin-overlays', TBKKT_PLUGIN_URL . $admin_overlays_js, array(), tbkkt_plugin_get_asset_file_mtime( $admin_overlays_js ), true ); $i18n_all = function_exists( 'tbkkt_admin_components_get_i18n_strings' ) ? tbkkt_admin_components_get_i18n_strings() : array(); $i18n_keys = array( 'copy', 'copied' ); $i18n = array(); foreach ( $i18n_keys as $key ) : if ( isset( $i18n_all[ $key ] ) ) : $i18n[ $key ] = $i18n_all[ $key ]; endif; endforeach; wp_localize_script( 'tbkkt-overlay-admin-overlays', 'tbkktOverlayAdminListI18n', $i18n ); }, 10 ); /** * Overlay CPT: block editor document settings panel */ add_action( 'enqueue_block_editor_assets', function (): void { if ( ! defined( 'TBKKT_OVERLAY_POST_TYPE' ) ) return; $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || ! $screen->is_block_editor() ) return; if ( TBKKT_OVERLAY_POST_TYPE !== $screen->post_type ) return; $editor_overlay_js = 'assets/js/editor-overlay.js'; wp_enqueue_script( 'tbkkt-editor-overlay', TBKKT_PLUGIN_URL . $editor_overlay_js, array( 'wp-plugins', 'wp-edit-post', 'wp-components', 'wp-data', 'wp-element', 'wp-block-editor', ), tbkkt_plugin_get_asset_file_mtime( $editor_overlay_js ), true ); if ( function_exists( 'tbkkt_overlay_get_document_editor_config' ) ) : wp_localize_script( 'tbkkt-editor-overlay', 'tbkktOverlayDocumentEditorConfig', tbkkt_overlay_get_document_editor_config() ); endif; }, 10 ); /** * Block editor canvas iframe: enqueue front bundles */ add_action( 'enqueue_block_assets', function (): void { if ( ! is_admin() ) return; if ( ! tbkkt_admin_is_block_editor_canvas() ) return; // Base style wp_enqueue_style( 'tbkkt-style' ); // Extension frontend styles if ( wp_style_is( 'tbkkt-responsive-spacing', 'registered' ) ) : wp_enqueue_style( 'tbkkt-responsive-spacing' ); endif; if ( wp_style_is( 'tbkkt-responsive-font-size', 'registered' ) ) : wp_enqueue_style( 'tbkkt-responsive-font-size' ); endif; if ( wp_style_is( 'tbkkt-scroll-animation', 'registered' ) ) : wp_enqueue_style( 'tbkkt-scroll-animation' ); endif; if ( wp_style_is( 'tbkkt-position', 'registered' ) ) : wp_enqueue_style( 'tbkkt-position' ); endif; if ( wp_style_is( 'tbkkt-responsive-visibility', 'registered' ) ) : wp_enqueue_style( 'tbkkt-responsive-visibility' ); endif; if ( wp_style_is( 'tbkkt-overlays', 'registered' ) ) : if ( tbkkt_settings_feature_is_enabled( 'floating_overlays' ) ) : wp_enqueue_style( 'tbkkt-overlays' ); endif; endif; // Extension editor styles (for inspector styling in canvas) if ( wp_style_is( 'tbkkt-editor-responsive-spacing', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-responsive-spacing' ); endif; if ( wp_style_is( 'tbkkt-editor-responsive-font-size', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-responsive-font-size' ); endif; if ( wp_style_is( 'tbkkt-editor-scroll-animation', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-scroll-animation' ); endif; if ( wp_style_is( 'tbkkt-editor-position', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-position' ); endif; if ( wp_style_is( 'tbkkt-editor-responsive-visibility', 'registered' ) ) : wp_enqueue_style( 'tbkkt-editor-responsive-visibility' ); endif; if ( wp_style_is( 'tbkkt-editor-overlays', 'registered' ) ) : if ( tbkkt_settings_feature_is_enabled( 'floating_overlays' ) ) : wp_enqueue_style( 'tbkkt-editor-overlays' ); endif; endif; // Block styles if ( wp_style_is( 'tbkkt-container-style', 'registered' ) ) : wp_enqueue_style( 'tbkkt-container-style' ); endif; if ( wp_style_is( 'tbkkt-container-editor', 'registered' ) ) : wp_enqueue_style( 'tbkkt-container-editor' ); endif; if ( wp_style_is( 'tbkkt-icon-style', 'registered' ) ) : wp_enqueue_style( 'tbkkt-icon-style' ); endif; if ( wp_style_is( 'tbkkt-icon-editor', 'registered' ) ) : wp_enqueue_style( 'tbkkt-icon-editor' ); endif; }, 20 );