'assets/css/editor-bootstrap.min.css', 'areoi-index' => 'build/index.css', 'areoi-select2' => 'assets/css/select2.min.css' ); areoi_enqueue_css( $css_enqueues ); $js_enqueues = array( 'areoi-js' => array( 'path' => 'assets/js/areoi.js', 'includes' => array() ), 'areoi-color-picker' => array( 'path' => 'assets/js/wp-color-picker-alpha.min.js', 'includes' => array( 'wp-color-picker' ) ), 'areoi-select2' => array( 'path' => 'assets/js/select2.min.js', 'includes' => array() ), ); areoi_enqueue_js( $js_enqueues ); wp_localize_script( 'areoi-blocks', 'areoi_vars', array( 'plugin_url' => AREOI__PLUGIN_URI, 'hide_buttons' => get_option( 'areoi-dashboard-global-hide-buttons-block', 0 ), 'hide_columns' => get_option( 'areoi-dashboard-global-hide-columns-block', 0 ), 'text_domain' => AREOI__TEXT_DOMAIN, 'colors' => areoi_get_option_colors(), 'menus' => self::get_formatted_menus(), ) ); wp_set_script_translations( 'areoi-blocks', AREOI__TEXT_DOMAIN ); } public static function enqueue_custom_style() { if ( get_option( 'areoi-dashboard-global-bootstrap-css', 1 ) ) { $css_enqueues = array( 'areoi-bootstrap' => 'assets/css/bootstrap.min.css', ); areoi_enqueue_css( $css_enqueues ); } if ( get_option( 'areoi-dashboard-global-bootstrap-icon-css', 1 ) ) { $css_enqueues = array( 'areoi-bootstrap-icons' => 'src/bootstrap-icons-1.8.1/bootstrap-icons.min.css', ); areoi_enqueue_css( $css_enqueues ); } $css_enqueues = array( 'areoi-style-index' => 'build/style-index.css', ); areoi_enqueue_css( $css_enqueues ); if ( get_option( 'areoi-dashboard-global-bootstrap-js', 1 ) ) { $js_enqueues = array( 'areoi-bootstrap' => array( 'path' => 'assets/js/bootstrap.min.js', 'includes' => array('jquery') ), ); areoi_enqueue_js( $js_enqueues ); $scripts = ''; ob_start(); include( AREOI__PLUGIN_DIR . 'assets/js/bootstrap-extra.js' ); $scripts .= ob_get_clean(); wp_add_inline_script( 'areoi-bootstrap', areoi_minify_js( $scripts ) ); } $post = get_post(); $added_styles = array(); $added_scripts = array(); if ( isset( $post->post_content ) && has_blocks( $post->post_content ) ) { $blocks = parse_blocks( $post->post_content ); self::traverse_block_styles( $blocks, $added_styles, $added_scripts ); } } public static function traverse_block_styles( $blocks, $added_styles, $added_scripts ) { foreach ( $blocks as $block_key => $block ) { $block_name = str_replace( 'areoi/', '', $block['blockName'] ); if ( $block['blockName'] == 'core/gallery' ) { $block_name = str_replace( 'core/', '', $block['blockName'] ); } if ( file_exists( AREOI__PLUGIN_DIR . 'blocks/' . $block_name . '/style.css' ) && empty( $added_styles[$block_name] ) ) { areoi_enqueue_css( array( 'areoi-block-' . $block_name => 'blocks/' . $block_name . '/style.css' ) ); $added_styles[$block_name] = true; } if ( file_exists( AREOI__PLUGIN_DIR . 'blocks/' . $block_name . '/script.js' ) && empty( $added_scripts[$block_name] ) ) { $scripts = array( 'areoi-block-' . $block_name => array( 'path' => 'blocks/' . $block_name . '/script.js', 'includes' => array() ) ); areoi_enqueue_js( $scripts ); $added_scripts[$block_name] = true; } if ( in_array( $block_name, array( 'media-grid', 'post-grid', 'content-grid' ) ) ) { $added_styles['gallery'] = true; $added_styles['post-grid'] = true; $added_styles['media-grid'] = true; } if ( !empty( $block['innerBlocks'] ) ) { self::traverse_block_styles( $block['innerBlocks'], $added_styles, $added_scripts ); } } } public static function add_block_styles() { $xs = str_replace( 'px', '', get_option( 'areoi-layout-grid-grid-breakpoint-xs', 0 ) ); $sm = str_replace( 'px', '', get_option( 'areoi-layout-grid-grid-breakpoint-sm', 576 ) ); $md = str_replace( 'px', '', get_option( 'areoi-layout-grid-grid-breakpoint-md', 768 ) ); $lg = str_replace( 'px', '', get_option( 'areoi-layout-grid-grid-breakpoint-lg', 992 ) ); $xl = str_replace( 'px', '', get_option( 'areoi-layout-grid-grid-breakpoint-xl', 1200 ) ); $xxl = str_replace( 'px', '', get_option( 'areoi-layout-grid-grid-breakpoint-xxl', 1400 ) ); $devices = array( '_xs' => $xs, '_sm' => $sm, '_md' => $md, '_lg' => $lg, '_xl' => $xl, '_xxl' => $xxl ); $styles = ''; $standard_blocks = parse_blocks( get_the_content() ); $page_reuseable_blocks = array(); if ( !empty( $standard_blocks ) ) { foreach ( $standard_blocks as $block_key => $block ) { if ( $block['blockName'] == 'core/block' && !empty( $block['attrs']['ref'] ) ) { unset( $standard_blocks[$block_key] ); $post = get_post($block['attrs']['ref']); if ( $post ) $page_reuseable_blocks = array_merge( parse_blocks( $post->post_content ), $page_reuseable_blocks ); } if ( !$block['blockName'] ) { unset( $standard_blocks[$block_key] ); } } } $block_posts = get_posts( array( 'post_type' => 'wp_block', 'numberposts' => -1 ) ); $reuseable_blocks = array(); if ( !empty( $block_posts ) ) { foreach ( $block_posts as $post_key => $post ) { $reuseable_blocks = array_merge( parse_blocks( $post->post_content ), $reuseable_blocks ); } } $widget_block = get_option( 'widget_block', null ); $sidebars_widgets = get_option( 'sidebars_widgets', array() ); if ( is_array( $sidebars_widgets ) && isset( $sidebars_widgets['array_version'] ) ) unset( $sidebars_widgets['array_version'] ); $widget_blocks = array(); if ( !empty( $widget_block ) && !empty( $sidebars_widgets ) && is_array( $sidebars_widgets ) ) { foreach ( $sidebars_widgets as $sidebar_widget_key => $sidebar_widget ) { foreach ( $sidebar_widget as $block_key => $block ) { $block_key = str_replace( 'block-', '', $block ); $block = $widget_block[$block_key]; $widget_blocks = array_merge( parse_blocks( $block['content'] ), $widget_blocks ); } } } global $_wp_current_template_content; $template_blocks = array(); if ( $_wp_current_template_content ) $template_blocks = parse_blocks( $_wp_current_template_content ); $blocks = array_merge( $standard_blocks, $page_reuseable_blocks, $reuseable_blocks, $template_blocks, $widget_blocks ); foreach ( $devices as $device_key => $device ) { $new_styles = '@media ( min-width: ' . $device . 'px ) {'; $inner_styles = self::add_block_style( $blocks, $device_key ); if ( empty( $inner_styles ) ) { continue; } $new_styles .= $inner_styles; $new_styles .= '}'; $styles .= $new_styles; } wp_add_inline_style( 'areoi-style-index', areoi_minify_css( $styles ) ); } public static function add_block_style( $blocks, $device_key ) { $styles = ''; if ( !empty( $blocks ) ) { foreach ( $blocks as $block_key => $block ) { $attributes = $block['attrs']; $inner_styles = ( !empty( $attributes['height_dimension' . $device_key] ) ? 'height: ' . $attributes['height_dimension' . $device_key] . (!empty( !empty( $attributes['height_unit' . $device_key] ) ) ? $attributes['height_unit' . $device_key] : 'px') . ';' : '' ); $inner_styles .= ( !empty( $attributes['padding_top' . $device_key] ) ? 'padding-top: ' . $attributes['padding_top' . $device_key] . 'px;' : '' ); $inner_styles .= ( !empty( $attributes['padding_right' . $device_key] ) ? 'padding-right: ' . $attributes['padding_right' . $device_key] . 'px;' : '' ); $inner_styles .= ( !empty( $attributes['padding_bottom' . $device_key] ) ? 'padding-bottom: ' . $attributes['padding_bottom' . $device_key] . 'px;' : '' ); $inner_styles .= ( !empty( $attributes['padding_left' . $device_key] ) ? 'padding-left: ' . $attributes['padding_left' . $device_key] . 'px;' : '' ); $inner_styles .= ( !empty( $attributes['margin_top' . $device_key] ) ? 'margin-top: ' . $attributes['margin_top' . $device_key] . 'px;' : '' ); $inner_styles .= ( !empty( $attributes['margin_right' . $device_key] ) ? 'margin-right: ' . $attributes['margin_right' . $device_key] . 'px;' : '' ); $inner_styles .= ( !empty( $attributes['margin_bottom' . $device_key] ) ? 'margin-bottom: ' . $attributes['margin_bottom' . $device_key] . 'px;' : '' ); $inner_styles .= ( !empty( $attributes['margin_left' . $device_key] ) ? 'margin-left: ' . $attributes['margin_left' . $device_key] . 'px;' : '' ); if ( !empty( $inner_styles ) && !empty( $attributes['block_id'] ) ) { $styles .= '.block-' . $attributes['block_id'] . ' {'; $styles .= $inner_styles; $styles .= '}'; } if ( !empty( $block['innerBlocks'] ) ) { $styles .= self::add_block_style( $block['innerBlocks'], $device_key ); } } } return $styles; } public static function get_formatted_menus() { $menus = array( array( 'label' => 'Default', 'value' => '' ) ); $all_menus = get_terms( 'nav_menu' ); if ( !empty( $all_menus ) ) { foreach ( $all_menus as $menu_key => $menu ) { $menus[] = array( 'label' => $menu->name, 'value' => $menu->term_id ); } } return $menus; } }