<?php
/**
 * Redirect empty search queries to homepage
 *
 * Prevents display of search results page when query parameter is empty.
 * Handles cases like ?s= or ?s with no value directly typed in browser. 
 *
 * @package Sophia
 * @since 1.0.0
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Redirect empty search queries to homepage
 *
 * @since 1.0.0
 * @return void
 */
function sophia_redirect_empty_search() {
    if (is_search() && '' === get_search_query()) {
        wp_safe_redirect(home_url('/'));
        exit;
    }
}
add_action('template_redirect', 'sophia_redirect_empty_search');