$modal ) { $modal_content .= $modal; } } return $content . $modal_content; }, 100 ); } public static function register_blocks() { add_filter( 'block_categories_all', [ 'AREOI_Lightspeed', 'add_block_categories' ], 100, 2 ); require AREOI__PLUGIN_LIGHTSPEED_DIR . 'blocks/index.php'; if ( is_admin() ) { $asset_file = include( AREOI__PLUGIN_LIGHTSPEED_DIR . 'assets/build/index.asset.php'); wp_enqueue_script( 'areoi-lightspeed-blocks', AREOI__PLUGIN_LIGHTSPEED_URI . 'assets/build/index.js', array_merge( $asset_file['dependencies'], array( 'areoi-blocks' ) ), $asset_file['version'] ); wp_localize_script( 'areoi-lightspeed-blocks', 'areoi_lightspeed_vars', array( 'blocks' => self::get_blocks(), 'templates' => self::get_templates(), 'forms' => self::get_forms(), 'is_lightspeed' => areoi_is_lightspeed(), 'pattern' => areoi2_get_option( 'areoi-lightspeed-styles-strip-pattern', false ), 'divider' => areoi2_get_option( 'areoi-lightspeed-styles-strip-divider', false ), 'mask' => areoi2_get_option( 'areoi-lightspeed-styles-image-mask', false ), 'transition' => areoi2_get_option( 'areoi-lightspeed-transition-transition', false ), 'parallax' => areoi2_get_option( 'areoi-lightspeed-parallax-parallax', false ), 'is_icons' => areoi2_get_option( 'areoi-dashboard-global-bootstrap-icon-css', false ) ) ); wp_set_script_translations( 'areoi-lightspeed-blocks', AREOI__TEXT_DOMAIN ); } } public static function add_block_categories( $categories, $post ) { $new_category = [ 'slug' => 'areoi-custom', 'title' => __( 'Custom', AREOI__TEXT_DOMAIN ), 'icon' => '' ]; $custom_category = array( $new_category ); $new_category = [ 'slug' => 'areoi-lightspeed', 'title' => __( 'Lightspeed', AREOI__TEXT_DOMAIN ), 'icon' => '' ]; $lightspeed_category = array( $new_category ); if ( areoi_is_lightspeed() ) { return array_merge( $custom_category, $lightspeed_category, $categories); } return array_merge( $custom_category, $categories, $lightspeed_category ); } public static function block_pattern_categories() { $templates = self::get_templates(); foreach ( $templates as $template_key => $template ) { $pattern_key = 'lightspeed/' . $template_key; if ( in_array( $pattern_key, [ 'dividers', 'patterns', 'content', 'masks' ] ) ) continue; if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $pattern_key ) ) { $pattern_name = str_replace( '-', ' ', $template_key ); $pattern_name = ucwords( $pattern_name ); register_block_pattern_category( $pattern_key, array( 'label' => $pattern_name ) ); } } } public static function block_patterns() { $templates = self::get_templates(); foreach ( $templates as $template_key => $template ) { $pattern_key = 'lightspeed/' . $template_key; foreach ( $template as $pattern ) { if ( in_array( $template_key, [ 'dividers', 'patterns', 'content', 'masks' ] ) ) continue; if ( !$pattern['value'] ) continue; $filename = $pattern['value']; register_block_pattern( $pattern_key . '/' . $filename, array( 'title' => $pattern['label'], 'categories' => array( $pattern_key ), 'content' => '', ), ); } } } public static function add_menu_locations() { register_nav_menus( [ 'top-menu' => __( 'Lightspeed: Top Menu', AREOI__TEXT_DOMAIN ), 'primary-menu' => __( 'Lightspeed: Primary Menu', AREOI__TEXT_DOMAIN ), 'more-menu' => __( 'Lightspeed: More Menu', AREOI__TEXT_DOMAIN ), 'feature-menu' => __( 'Lightspeed: Feature Menu', AREOI__TEXT_DOMAIN ), 'footer-menu' => __( 'Lightspeed: Footer Menu', AREOI__TEXT_DOMAIN ), 'bottom-menu' => __( 'Lightspeed: Bottom Menu', AREOI__TEXT_DOMAIN ), ] ); } public static function add_scripts() { $enqueue = 'assets/js/global.js'; wp_enqueue_script( 'areoi-lightspeed', AREOI__PLUGIN_LIGHTSPEED_URI . $enqueue, array( 'jquery' ), filemtime( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ); $scripts = ''; ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . 'assets/js/site.js' ); $scripts .= ob_get_clean(); $parallax = areoi2_get_option( 'areoi-lightspeed-parallax-parallax', false ); if ( $parallax ) { $enqueue = 'assets/js/parallax.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } $transition = areoi2_get_option( 'areoi-lightspeed-transition-transition', false ); if ( $transition ) { $enqueue = 'assets/js/transition.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } $page_transition = areoi2_get_option( 'areoi-lightspeed-transition-page', false ); if ( $page_transition ) { $enqueue = 'assets/js/transition-page.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } $background_transition = areoi2_get_option( 'areoi-lightspeed-transition-background', false ); if ( $background_transition ) { $enqueue = 'assets/js/transition-background.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } $gallery = areoi2_get_option( 'areoi-lightspeed-features-include-gallery', false ); if ( $gallery ) { $enqueue = 'assets/js/gallery.js'; if ( file_exists( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ) { ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ); $scripts .= ob_get_clean(); } } if ( $scripts ) { $scripts = ' jQuery(document).ready(function($){ ' . $scripts . ' }); '; wp_add_inline_script( 'areoi-lightspeed', areoi_minify_js( $scripts ) ); } } public static function add_admin_scripts() { $enqueue = 'assets/js/admin.js'; wp_enqueue_script( 'areoi-lightspeed-admin', AREOI__PLUGIN_LIGHTSPEED_URI . $enqueue, array( 'jquery' ), filemtime( AREOI__PLUGIN_LIGHTSPEED_DIR . $enqueue ) ); self::add_custom_fonts(); } public static function get_blocks() { $plugin_directory = AREOI__PLUGIN_LIGHTSPEED_DIR . 'blocks/'; $plugin_uri = AREOI__PLUGIN_LIGHTSPEED_URI . 'blocks/'; $plugin_templates = lightspeed_list_files_with_uri( $plugin_directory, $plugin_uri ); $custom_theme_directory = lightspeed_get_custom_directory(); $custom_theme_uri = lightspeed_get_custom_directory_uri(); $custom_theme_templates = lightspeed_list_files_with_uri( $custom_theme_directory, $custom_theme_uri ); $child_custom_theme_templates = array(); if ( is_child_theme() ) { $child_custom_theme_directory = lightspeed_get_custom_directory( true ); $child_custom_theme_uri = lightspeed_get_custom_directory_uri( true ); $child_custom_theme_templates = lightspeed_list_files_with_uri( $child_custom_theme_directory, $child_custom_theme_uri ); } $block_folders = array_merge( $plugin_templates, $custom_theme_templates, $child_custom_theme_templates ); return $block_folders; } public static function get_templates() { $block_folders = array( 'hero' => 'hero/templates', 'header' => 'header/templates', 'footer' => 'footer/templates', 'content-with-media'=> 'content-with-media/templates', 'content-with-items'=> 'content-with-items/templates', 'media' => 'media/templates', 'posts' => 'posts/templates', 'call-to-action' => 'call-to-action/templates', 'next-and-previous' => 'next-and-previous/templates', 'logos' => 'logos/templates', 'contact' => 'contact/templates', 'post-details' => 'post-details/templates', 'search' => 'search/templates', ); $theme_custom_directory = lightspeed_get_custom_directory(); $theme_custom_templates = lightspeed_list_files( $theme_custom_directory ); if ( !empty( $theme_custom_templates ) ) { foreach ( $theme_custom_templates as $template_key => $template ) { if ( !isset( $block_folders[$template] ) ) { $block_folders[$template] = 'custom/' . $template . '/templates'; } } } if ( is_child_theme() ) { $theme_custom_directory = lightspeed_get_custom_directory( true ); $theme_custom_templates = lightspeed_list_files( $theme_custom_directory ); if ( !empty( $theme_custom_templates ) ) { foreach ( $theme_custom_templates as $template_key => $template ) { if ( !isset( $block_folders[$template] ) ) { $block_folders[$template] = 'custom/' . $template . '/templates'; } } } } $templates = lightspeed_get_block_templates( $block_folders ); $block_folders = array(); $block_folders['dividers'] = 'dividers'; $block_folders['patterns'] = 'patterns'; $block_folders['content'] = 'content'; $block_folders['masks'] = 'masks'; $templates = array_merge( $templates, lightspeed_get_block_templates( $block_folders, false ) ); return $templates; } public static function get_forms() { $forms = array( array( 'value' => '', 'label' => 'None' ) ); if ( class_exists( 'Ninja_Forms' ) ) { $ninja_forms = Ninja_Forms()->form()->get_forms(); foreach ( $ninja_forms as $form_key => $form ) { $forms[] = array( 'value' => $form->get_id(), 'label' => $form->get_setting( 'title' ) ); } } return $forms; } public static function add_custom_fonts() { $fonts = array(); $heading_font = areoi2_get_option( 'areoi-lightspeed-company-heading-font-url', '' ); $body_font = areoi2_get_option( 'areoi-lightspeed-company-body-font-url', '' ); if ( $heading_font ) $fonts['areoi-heading-font'] = $heading_font; if ( $body_font && $body_font != $heading_font ) $fonts['areoi-body-font'] = $body_font; if ( !empty( $fonts ) ) { foreach ( $fonts as $font_key => $font ) { wp_enqueue_style( $font_key, $font, array(), '' ); } } } public static function add_styles() { self::add_custom_fonts(); ob_start(); include( AREOI__PLUGIN_LIGHTSPEED_DIR . 'assets/css/lightspeed.css' ); $styles = ob_get_clean(); $frame = areoi2_get_option( 'areoi-lightspeed-styles-frame', false ); if ( $frame ) { add_action( 'wp_body_open', function() { echo '