Añadir mu-plugins y scripts de feadulta
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Fe Adulta — Buscador visible (#8, MVP nativo)
|
||||
* Description: Inyecta una barra de búsqueda visible bajo la cabecera (template part
|
||||
* FSE 'header'), usando el buscador nativo de WordPress (/?s=). Multiidioma:
|
||||
* el form apunta a la home del idioma actual (Polylang filtra por idioma).
|
||||
* Fase 2: sustituir el motor por Typesense (self-host) manteniendo esta UI.
|
||||
* Version: 1.0
|
||||
*/
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
/** HTML del formulario de búsqueda (home del idioma actual como action). */
|
||||
function fea_search_form_html(): string {
|
||||
// Raíz del idioma actual (Polylang) para que /?s= busque en ese idioma:
|
||||
// ES (idioma por defecto) → /; EN/FR/IT/PT → /<lang>/.
|
||||
$base = home_url('/');
|
||||
if (function_exists('pll_current_language')) {
|
||||
$lang = pll_current_language();
|
||||
$default = function_exists('pll_default_language') ? pll_default_language() : 'es';
|
||||
if ($lang && $lang !== $default) $base = home_url('/' . $lang . '/');
|
||||
}
|
||||
$action = esc_url($base);
|
||||
$q = esc_attr(get_search_query());
|
||||
$ph = esc_attr__('Buscar reflexiones, artículos, autores…', 'default');
|
||||
$svg = '<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false">'
|
||||
. '<path fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 1 0-.7.7l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0A4.5 4.5 0 1 1 14 9.5 4.5 4.5 0 0 1 9.5 14z"/></svg>';
|
||||
return '<div class="fea-search-bar"><form role="search" method="get" class="fea-search" action="' . $action . '">'
|
||||
. '<input type="search" name="s" value="' . $q . '" placeholder="' . $ph . '" aria-label="Buscar">'
|
||||
. '<button type="submit" aria-label="Buscar">' . $svg . '</button>'
|
||||
. '</form></div>';
|
||||
}
|
||||
|
||||
/** Inyecta la barra al final del template part 'header'. */
|
||||
add_filter('render_block', function ($html, $block) {
|
||||
if (is_admin()) return $html;
|
||||
if (($block['blockName'] ?? '') !== 'core/template-part') return $html;
|
||||
// El home usa el part 'cabecera-portada'; el resto del sitio usa 'header'.
|
||||
if (!in_array($block['attrs']['slug'] ?? '', ['header', 'cabecera-portada'], true)) return $html;
|
||||
return $html . fea_search_form_html();
|
||||
}, 20, 2);
|
||||
|
||||
add_action('wp_head', function () {
|
||||
?>
|
||||
<style>
|
||||
/* En desktop se usa el buscador del menú; esta barra es para móvil, donde el
|
||||
menú colapsa en hamburguesa y el buscador del menú queda oculto (#8). */
|
||||
.fea-search-bar{display:none;justify-content:center;padding:.5rem 1rem;
|
||||
background:#faf6f7;border-top:1px solid #efe2e5;border-bottom:1px solid #efe2e5}
|
||||
@media(max-width:600px){.fea-search-bar{display:flex}}
|
||||
.fea-search{display:flex;align-items:center;width:100%;max-width:560px;
|
||||
background:#fff;border:1px solid #d9c4c9;border-radius:999px;overflow:hidden}
|
||||
.fea-search input[type=search]{flex:1 1 auto;border:0;outline:0;background:transparent;
|
||||
font-size:.95rem;padding:.55rem .9rem;color:#222}
|
||||
.fea-search input[type=search]::placeholder{color:#9a8a8e}
|
||||
.fea-search button{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;
|
||||
border:0;cursor:pointer;background:#8b1a2e;color:#fff;width:42px;align-self:stretch}
|
||||
.fea-search button:hover{background:#6f1525}
|
||||
@media(max-width:600px){.fea-search-bar{padding:.45rem .6rem}}
|
||||
</style>
|
||||
<?php
|
||||
});
|
||||
Reference in New Issue
Block a user