__( 'Hero Sections', 'avada-press-block' ), 'avadablock-features' => __( 'Features', 'avada-press-block' ), 'avadablock-content' => __( 'Content', 'avada-press-block' ), 'avadablock-call-to-action' => __( 'Call to Action', 'avada-press-block' ), ] ); // Register pattern categories. foreach ( $categories as $slug => $label ) { // Check if category already exists to avoid errors. $registry = \WP_Block_Pattern_Categories_Registry::get_instance(); $existing = array_column( $registry->get_all_registered(), 'name' ); if ( ! in_array( $slug, $existing, true ) ) { register_block_pattern_category( $slug, [ 'label' => $label ] ); } } } add_action( 'init', 'avadablock_register_pattern_categories' ); /** * Manually register patterns from files. * * WordPress auto-discovers patterns, but we manually register them * to ensure they sync properly, especially when in subdirectories. * * @since 1.0 */ function avadablock_register_patterns_from_files() { $pattern_files = [ [ 'title' => 'Modern Hero Section', 'slug' => 'avadablock/hero/modern-hero', 'description' => 'A clean, modern hero section with responsive layout, headline, description, and CTA buttons.', 'categories' => [ 'avadablock-hero' ], 'keywords' => [ 'hero', 'banner', 'cta', 'header', 'introduction' ], 'file' => 'patterns/hero/modern-hero.php', ], [ 'title' => 'Three Column Features', 'slug' => 'avadablock/features/three-column-features', 'description' => 'A three-column feature section with icons, headings, and descriptions.', 'categories' => [ 'avadablock-features' ], 'keywords' => [ 'features', 'services', 'columns', 'benefits' ], 'file' => 'patterns/features/three-column-features.php', ], [ 'title' => 'Call to Action Banner', 'slug' => 'avadablock/call-to-action/cta-banner', 'description' => 'A centered call-to-action section with heading, description, and button.', 'categories' => [ 'avadablock-call-to-action' ], 'keywords' => [ 'cta', 'call to action', 'banner', 'button' ], 'file' => 'patterns/call-to-action/cta-banner.php', ], ]; foreach ( $pattern_files as $pattern ) { $file_path = get_template_directory() . '/' . $pattern['file']; if ( file_exists( $file_path ) ) { $file_content = file_get_contents( $file_path ); // Extract content after the closing PHP tag and comment header. $content = preg_replace( '/^.*?\?>\s*\n/s', '', $file_content ); // Clean up any remaining PHP tags or comments. $content = preg_replace( '/^<\?php\s*\n/', '', $content ); $content = trim( $content ); if ( ! empty( $content ) ) { register_block_pattern( $pattern['slug'], [ 'title' => $pattern['title'], 'description' => $pattern['description'], 'categories' => $pattern['categories'], 'keywords' => $pattern['keywords'], 'content' => $content, ] ); } } } } add_action( 'init', 'avadablock_register_patterns_from_files' ); /** * Register block styles. * * @since 1.0 */ function avadablock_register_block_styles() { // Register outline style for button block. register_block_style( 'core/button', [ 'name' => 'outline', 'label' => __( 'Outline', 'avada-press-block' ), 'inline_style' => '.wp-block-button.is-style-outline .wp-block-button__link { background: transparent !important; border: 2px solid currentColor; transition: all 0.3s ease; } .wp-block-button.is-style-outline .wp-block-button__link:hover { background: var(--wp--preset--color--background) !important; transform: translateY(-2px); box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15); }', ] ); } add_action( 'init', 'avadablock_register_block_styles' ); /** * Add theme supports. * * @since 1.0 */ function avadablock_theme_setup() { add_theme_support( 'responsive-embeds' ); add_theme_support( 'post-thumbnails' ); add_theme_support( 'title-tag' ); add_theme_support( 'editor-styles' ); add_theme_support( 'wp-block-styles' ); add_theme_support( 'align-wide' ); // Add custom logo support. add_theme_support( 'custom-logo', [ 'height' => 100, 'width' => 400, 'flex-height' => true, 'flex-width' => true, 'header-text' => [ 'site-title', 'site-description' ], ] ); /** * Action hook after theme setup. * * @since 1.0 */ do_action( 'avadablock_after_theme_setup' ); } add_action( 'after_setup_theme', 'avadablock_theme_setup' ); /** * Enqueue sticky header script if enabled. * * @since 1.0 */ function avadablock_enqueue_sticky_header() { if ( ! function_exists( 'wp_get_global_settings' ) ) { return; } $settings = wp_get_global_settings(); $sticky = $settings['custom']['header']['sticky'] ?? false; if ( $sticky ) { wp_enqueue_script( 'avadablock-prefetch' ); wp_add_inline_script( 'avadablock-prefetch', "(function() { const header = document.querySelector('.avadablock-site-header'); if (header) { let lastScroll = 0; window.addEventListener('scroll', function() { const currentScroll = window.pageYOffset || document.documentElement.scrollTop; if (currentScroll > 100) { header.classList.add('avadablock-header-sticky'); } else { header.classList.remove('avadablock-header-sticky'); } lastScroll = currentScroll; }); } })();", 'after' ); } } add_action( 'wp_enqueue_scripts', 'avadablock_enqueue_sticky_header', 20 ); /** * Add additional theme features. * * @since 1.0 */ function avadablock_additional_features() { // Add support for wide and full-width blocks. add_theme_support( 'align-wide' ); // Add support for custom line height. add_theme_support( 'custom-line-height' ); // Add support for custom units. add_theme_support( 'custom-units', [ 'px', 'em', 'rem', 'vh', 'vw', '%' ] ); /** * Filter to add custom theme features. * * @since 1.0 */ do_action( 'avadablock_additional_features' ); } add_action( 'after_setup_theme', 'avadablock_additional_features' ); /** * Customize excerpt length. * * @since 1.0 * @param int $length Excerpt length. * @return int Modified excerpt length. */ function avadablock_excerpt_length( $length ) { /** * Filter the excerpt length. * * @since 1.0 * @param int $length Current excerpt length. */ return apply_filters( 'avadablock_excerpt_length', 30 ); } add_filter( 'excerpt_length', 'avadablock_excerpt_length' ); /** * Customize excerpt more text. * * @since 1.0 * @param string $more More text. * @return string Modified more text. */ function avadablock_excerpt_more( $more ) { /** * Filter the excerpt more text. * * @since 1.0 * @param string $more Current more text. */ return apply_filters( 'avadablock_excerpt_more', '...' ); } add_filter( 'excerpt_more', 'avadablock_excerpt_more' ); // Add global styles. require_once 'includes/Styles.php'; new \AvadaBlock\Styles(); // Add scripts. require_once 'includes/Scripts.php'; new \AvadaBlock\Scripts(); /** * Filter to enable separate core block assets loading. * * @since 1.0 * @param bool $load_separate Whether to load separate assets. * @return bool */ add_filter( 'should_load_separate_core_block_assets', '__return_true' ); /** * Filter inline styles size limit. * * @since 1.0 * @param int $size Size limit in bytes. * @return int */ add_filter( 'styles_inline_size_limit', function( $size ) { /** * Filter the inline styles size limit. * * @since 1.0 * @param int $size Current size limit. */ return apply_filters( 'avadablock_inline_styles_size_limit', 50000 ); } );