<?php

function aurora_lite_search_header_bg_color() {
    if ( ! is_search() ) return;

    $color = get_theme_mod('aurora_lite_search_header_bg') ?: '#664700';

    $css = ':root { --aurora-lite-search-header-bg-color: ' . esc_attr( $color ) . '; }';
    wp_add_inline_style( 'aurora-lite-style', $css );
}
add_action( 'wp_enqueue_scripts', 'aurora_lite_search_header_bg_color' );


function aurora_lite_filter_search_results( $query ) {

    if (
        ! is_admin() &&
        $query->is_main_query() &&
        $query->is_search()
    ) {
        $query->set( 'post_type', [ 'post' ] );
    }
}
add_action( 'pre_get_posts', 'aurora_lite_filter_search_results' );


function aurora_lite_search_count() {
    if ( ! is_search() ) { return; }

    global $wp_query;

    $total  = $wp_query->found_posts;
    $term   = get_search_query();

    if ( $total > 0 ) {
        printf(
            '<h3 class="search-results-count">%s</h3>',
            sprintf(
                /* translators: %1$s: number of results, %2$s: search query */
                _n(
                    'Found %1$s result for "%2$s"',
                    'Found %1$s results for "%2$s"',
                    $total,
                    'aurora-lite'
                ),
                number_format_i18n( $total ),
                esc_html( $term )
            )
        );
    }
}