load_includes(); add_action('after_setup_theme', [$this, 'setup_theme']); add_action('wp_enqueue_scripts', [$this, 'enqueue_theme_styles']); add_action('init', [$this, 'register_block_bindings']); add_action('init', [$this, 'register_pattern_categories']); add_action('init', [$this, 'register_blocks']); add_filter('block_categories_all', [$this, 'register_block_categories'], 10, 2); } /** * Load necessary files for the theme. * * Includes all required PHP files from the includes directory. */ private function load_includes() { $files = [ 'block-styles.php', // Registers custom block styles 'class-enqueue.php', // Handles asset loading 'theme-settings.php', // Handles theme settings 'class-zoloblocks-installer.php', // Handles ZoloBlocks plugin installation 'class-admin-notice.php', // Handles admin notices 'features/scroll-top.php', // Handles scroll to top button 'features/contact-form-handler.php', // Contact form submission handler 'hover-effect-frontend.php', // Handles frontend hover effects ]; foreach ($files as $file) { $path = get_template_directory() . '/includes/' . $file; if (file_exists($path)) { require_once $path; } } } /** * Set up theme features and support. * * Registers theme support for various WordPress features. */ public function setup_theme() { // Load theme text domain for translations load_theme_textdomain('blynex', get_template_directory() . '/languages'); // Add support for post formats add_theme_support( 'post-formats', ['aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video'] ); // Add WooCommerce support add_theme_support('woocommerce'); // Add WooCommerce block styles add_theme_support('wc-product-gallery-zoom'); add_theme_support('wc-product-gallery-lightbox'); add_theme_support('wc-product-gallery-slider'); // Add support for WooCommerce block templates add_theme_support('woocommerce-block-templates'); } /** * Enqueue theme styles. * * Loads the main stylesheet for the theme. */ public function enqueue_theme_styles() { wp_enqueue_style( 'blynex-style', get_parent_theme_file_uri('style.css'), [], wp_get_theme()->get('Version') ); } /** * Register block bindings for dynamic content. * * Sets up custom block bindings for the theme. */ public function register_block_bindings() { register_block_bindings_source( 'blynex/format', [ 'label' => _x('Post format name', 'Label for the block binding placeholder in the editor', 'blynex'), 'get_value_callback' => [$this, 'format_binding_callback'], ] ); } /** * Callback for the post format binding. * * Returns the formatted post format name. * * @return string|null The post format name or null if standard format. */ public function format_binding_callback() { $post_format_slug = get_post_format(); if ($post_format_slug && 'standard' !== $post_format_slug) { return get_post_format_string($post_format_slug); } } /** * Register block pattern categories. * * Creates custom pattern categories for the theme. */ public function register_pattern_categories() { register_block_pattern_category( 'blynex_page', [ 'label' => __('Pages', 'blynex'), 'description' => __('A collection of full page layouts.', 'blynex'), ] ); register_block_pattern_category( 'blynex_post-format', [ 'label' => __('Post formats', 'blynex'), 'description' => __('A collection of post format patterns.', 'blynex'), ] ); } /** * Register custom blocks. * * This method registers custom blocks using block.json metadata. */ public function register_blocks() { // Register the Responsive Navigation Menu block $responsive_nav_menu_block_path = get_template_directory() . '/build/features/responsive-nav-menu'; if (file_exists($responsive_nav_menu_block_path . '/block.json')) { register_block_type_from_metadata($responsive_nav_menu_block_path); } // Register the Card Widget block $card_widget_block_path = get_template_directory() . '/build/features/card-widget'; if (file_exists($card_widget_block_path . '/block.json')) { register_block_type_from_metadata($card_widget_block_path); } // Register the Contact Form Widget block $contact_form_widget_block_path = get_template_directory() . '/build/features/contact-form-widget'; if (file_exists($contact_form_widget_block_path . '/block.json')) { register_block_type_from_metadata($contact_form_widget_block_path); } // Register the Live Clock/Date block $live_clock_date_block_path = get_template_directory() . '/build/features/live-clock-date'; if (file_exists($live_clock_date_block_path . '/block.json')) { register_block_type_from_metadata($live_clock_date_block_path); } // Register the Lottie Animation block $lottie_animation_block_path = get_template_directory() . '/build/features/lottie-animation'; if (file_exists($lottie_animation_block_path . '/block.json')) { register_block_type_from_metadata($lottie_animation_block_path); } } /** * Register custom block categories. * * Adds a custom category for blynex blocks. * * @param array $categories Array of block categories. * @param object $post Post object. * @return array Modified array of block categories. */ public function register_block_categories($categories, $post) { return array_merge( [ [ 'slug' => 'blynex-blocks', 'title' => __('blynex Blocks', 'blynex'), 'icon' => 'admin-customizer', ], ], $categories ); } }