style_dir = $upload_dir[ 'basedir' ] . DIRECTORY_SEPARATOR . $this->prefix . DIRECTORY_SEPARATOR; $this->style_url = set_url_scheme( $upload_dir[ 'baseurl' ] ) . '/' . $this->prefix . '/'; $this->frontend_style_dir = $this->style_dir . $this->frontend_prefix . DIRECTORY_SEPARATOR; $this->frontend_style_url = $this->style_url . $this->frontend_prefix . '/'; $this->fse_style_dir = $this->style_dir . $this->fse_prefix . DIRECTORY_SEPARATOR; $this->fse_style_url = $this->style_url . $this->fse_prefix . '/'; add_filter( 'dynamic_sidebar_params', array( $this, 'eb_widget_dynamic_sidebar_params' ) ); add_action( 'save_post', array( $this, 'on_save_post' ), 10, 3 ); add_action( 'wp', array( $this, 'generate_post_content' ) ); add_action( 'eb_after_save_responsiveBreakpoints_settings', array( $this, 'remove_frontend_assets' ), 10, 1 ); add_action( 'eb_after_reset_responsiveBreakpoints_settings', array( $this, 'remove_frontend_assets' ), 10 ); add_filter( 'generate_element_post_id', array( $this, 'get_generatepress_element' ), 99 ); add_action( 'wp_footer', array( $this, 'eb_add_widget_css_footer' ) ); //Enqueue Styles based on Block theme or not add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) ); if ( ! is_admin() ) { add_filter( 'render_block', array( $this, 'load_frontend_scripts_conditionally' ), 10, 2 ); // add_action('template_redirect', array($this, 'load_frontend_scripts_conditionally_head')); } //For Templately templates add_action( 'templately_printed_location', array( $this, 'templately_templates' ), 10, 3 ); // Hook into Astra Addon advanced hooks processing add_action( 'wp_enqueue_scripts', array( $this, 'astra_advanced_hooks_css_generation' ), 15 ); } /** * Enqueue frontend css for post if have one * @return void * @since 1.0.2 */ public function enqueue_frontend_assets() { global $post; $deps = apply_filters( 'eb_generated_css_frontend_deps', array( ) ); //FSE Template Predefined Style Enqueue if ( ! empty( $this->fse_page_template_id && is_int( $this->fse_page_template_id ) ) ) { $this->load_frontend_css_file( $this->fse_page_template_id, 'essential-blocks-fse-frontend-style', $this->fse_block_names ); } //Page/Post Predefined Style Enqueue if ( ! empty( $post ) && ! empty( $post->ID ) ) { $handle = $this->load_frontend_css_file( $post->ID, 'essential-blocks-frontend-style', $this->block_names ); if ( ! empty( $handle ) ) { $deps[ ] = $handle; } //Page/Post Generated Style Enqueue if ( file_exists( $this->style_dir . $this->prefix . '-' . $post->ID . '.min.css' ) ) { wp_enqueue_style( 'eb-block-style-' . $post->ID, $this->style_url . $this->prefix . '-' . $post->ID . '.min.css', $deps, substr( md5( microtime( true ) ), 0, 10 ) ); } // Reusable block Style Enqueues $reusableIds = get_post_meta( $post->ID, '_eb_reusable_block_ids', true ); $reusableIds = ! empty( $reusableIds ) ? $reusableIds : array( ); $templateReusableIds = get_option( '_eb_reusable_block_ids', array( ) ); $reusableIds = array_unique( array_merge( $reusableIds, $templateReusableIds ) ); if ( ! empty( $reusableIds ) ) { foreach ( $reusableIds as $reusableId ) { if ( file_exists( $this->style_dir . 'reusable-blocks/eb-reusable-' . $reusableId . '.min.css' ) ) { wp_enqueue_style( 'eb-reusable-block-style-' . $reusableId, $this->style_url . 'reusable-blocks/eb-reusable-' . $reusableId . '.min.css', $deps, substr( md5( microtime( true ) ), 0, 10 ) ); } } } } else { if ( ! empty( $this->block_names ) && ! empty( $this->templately_template_ids ) ) { foreach ( $this->templately_template_ids as $template ) { $handle = $this->load_frontend_css_file( $template, 'essential-blocks-frontend-style-' . $template, $this->block_names ); if ( ! empty( $handle ) ) { $deps[ ] = $handle; } } } } // generatepress elements if ( in_array( 'gp-premium/gp-premium.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { $gp_elements = get_posts( array( 'post_type' => 'gp_elements' ) ); if ( is_array( $gp_elements ) && ! empty( $gp_elements ) ) { foreach ( $gp_elements as $element ) { if ( file_exists( $this->style_dir . $this->get_eb_filename( $element->ID ) ) ) { wp_enqueue_style( 'eb-block-style-' . $element->ID, $this->style_url . $this->get_eb_filename( $element->ID ), $deps, substr( md5( microtime( true ) ), 0, 10 ) ); } } } } //Blocksy theme support if ( in_array( 'blocksy-companion-pro/blocksy-companion.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { $ct_elements = get_posts( array( 'post_type' => 'ct_content_block' ) ); if ( is_array( $ct_elements ) && ! empty( $ct_elements ) ) { foreach ( $ct_elements as $element ) { if ( file_exists( $this->style_dir . $this->get_eb_filename( $element->ID ) ) ) { wp_enqueue_style( 'eb-block-style-' . $element->ID, $this->style_url . $this->get_eb_filename( $element->ID ), $deps, substr( md5( microtime( true ) ), 0, 10 ) ); } } } } //Template Templates if ( is_array( $this->templately_template_ids ) && count( $this->templately_template_ids ) > 0 ) { foreach ( $this->templately_template_ids as $template ) { if ( file_exists( $this->style_dir . $this->get_eb_filename( $template ) ) ) { wp_enqueue_style( 'eb-block-style-' . $template, $this->style_url . $this->get_eb_filename( $template ), $deps, substr( md5( microtime( true ) ), 0, 10 ) ); } } } // NotificationX Post Type Support if ( in_array( 'notificationx/notificationx.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { $gutenberg_ids = $this->get_gutenberg_id_from_nx(); if ( is_array( $gutenberg_ids ) && ! empty( $gutenberg_ids ) ) { foreach ( $gutenberg_ids as $element ) { if ( file_exists( $this->frontend_style_dir . $this->get_frontend_filename( $element ) ) ) { wp_enqueue_style( 'frontend' . $element, $this->frontend_style_url . $this->get_frontend_filename( $element ), $deps, substr( md5( microtime( true ) ), 0, 10 ) ); } } } } // Astra Addon Advanced Hooks CSS files are now handled by astra_advanced_hooks_css_generation() method if ( in_array( 'astra-addon/astra-addon.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && defined( 'ASTRA_ADVANCED_HOOKS_POST_TYPE' ) ) { foreach ( $this->astra_hook_ids as $element_id ) { if ( file_exists( $this->style_dir . $this->get_eb_filename( $element_id ) ) ) { wp_enqueue_style( 'eb-block-style-' . $element_id, $this->style_url . $this->get_eb_filename( $element_id ), $deps, substr( md5( microtime( true ) ), 0, 10 ) ); } } } //Widget Style Enqueue $this->enqueue_widget_styles(); //FSE Style Enqueue if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { $templates = array_unique( $this->fse_template_ids ); foreach ( $templates as $template ) { if ( is_integer( $template ) && file_exists( $this->fse_style_dir . $this->get_fse_filename( $template ) ) ) { wp_enqueue_style( 'eb-fse-style-' . $template, $this->fse_style_url . $this->get_fse_filename( $template ), array( ), substr( md5( microtime( true ) ), 0, 10 ) ); } } } /** * Hooks assets for enqueue in frontend * * @param $path string * @param $url string * * @since 3.0.0 */ do_action( 'eb_frontend_assets', $this->style_dir, $this->style_url ); } public function load_frontend_scripts_conditionally( $block_content, $block ) { if ( null === $block_content ) { $block_content = ""; } // Load our main frontend scripts if there's a Essential block // loaded in the frontend. if ( ! $this->is_main_script_loaded && ! is_admin() ) { if ( strpos( $block_content, '