diff --git a/README.md b/README.md
index 0852d62..8c0067c 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,36 @@ Web de la protectora **Gure Ametsa Bi Lagun** (Jaizubia 44, Hondarribia), en cas
- Formulario de contacto/adopción `[ga_contacto]`. Envía un email **y** guarda cada mensaje en *Mensajes* dentro del panel, así no se pierde aunque falle el correo.
- Shortcode `[ga_animales numero="6" especie="perro" estado="urgente"]` para usar en cualquier página.
+## Gestión del día a día (sin tocar código)
+
+| Qué | Dónde |
+|---|---|
+| Añadir o editar un animal | **Animales → Añadir animal**. Arriba va la historia y debajo la ficha:
• Datos comunes a castellano y euskera: estado, destacado, sexo, nacimiento o edad aproximada, tamaño, fecha de entrada, más fotos y vídeo.
• Textos de cada idioma: cómo es, qué necesita, convivencia y el hogar que buscamos.
La versión en euskera se crea con el **+** de la caja «Idiomas»; los datos comunes y las fotos se copian solos. |
+| Estado | *Disponible*, *En proceso* o *Adoptado*. Los adoptados salen solos del listado. |
+| Animales de la portada | Marcar **Destacado** en su ficha. Si no hay ninguno, salen los que llevan más tiempo. |
+| Ayuda material | **Personalizar → Adopción y colabora → Ayuda material** (una línea por necesidad). |
+| Textos del botón «Quiero conocerlo/la», formulario, confirmación, proceso, correo de destino | **Personalizar → Adopción y colabora → Listado y fichas**. |
+| Aviso de cita previa, teléfono, horario | **Personalizar → Contacto y redes**. |
+| Portada | **Personalizar → Portada**: cada bloque se puede mostrar u ocultar y reordenar. Por defecto se ve: portada principal, animales destacados, acogida, quiénes somos y contacto. Donaciones, cifras, finales felices, etc. están ocultos. |
+| Menú | **Apariencia → Menús** (Principal / Nagusia). |
+| Páginas (Acoge, Colabora, Quiénes somos, Contacto, Preguntas frecuentes) | **Páginas**, con el editor de bloques y los patrones «Gure Ametsa». |
+| Mensajes recibidos | Menú **Mensajes** (además llegan por correo). |
+
+Cada ficha tiene su propio enlace y botones para compartirla por WhatsApp o Facebook, o copiar el enlace.
+
+## Migraciones
+
+`docker/setup.sh` se ejecuta en cada arranque y aplica por etapas lo que falte (`ga_setup_version`):
+
+| Etapa | Qué hace |
+|---|---|
+| 2 | Idiomas, tema, páginas y menús iniciales |
+| 3 | Plugins recomendados |
+| 4 | APIs (WPGraphQL, Swagger) |
+| 5 | Indicaciones del cliente: páginas Acoge y Preguntas frecuentes, menú con submenús, retirada del hotel, estados nuevos y sin animaciones |
+
+`docker/setup-content.php` es idempotente. **Las páginas que el cliente haya editado nunca se sobrescriben**; se detecta con una huella del contenido original.
+
## Logo y colores
- El logo original se ha vectorizado en `wp-content/themes/gure-ametsa/assets/img/`:
@@ -63,8 +93,8 @@ Para escribir en la API REST (crear o editar animales) se usan las *contraseñas
El diseño está inspirado en [Beargrass Animal Rescue](https://louisvillewebguy.com/examples/beargrass-animal-rescue/):
- **Tipografía:** títulos en Fraunces muy gruesa y texto en Karla. Las dos van incluidas en el tema, sin Google Fonts.
- **Paletas:** por defecto, los colores del logo. También están ciruela y mostaza (la de Beargrass), verde y rojo, azul mar y bosque.
-- **Portada:** a pantalla completa con cuatro «puertas»: Adopta, Acoge, Voluntariado y Dona.
-- **Listado de animales:** panel de filtros por especie, tamaño, edad, sexo y compatibilidad.
+- **Portada:** a pantalla completa, con foto real y botones a perros y gatos.
+- **Listado de animales:** solo Perros y Gatos, con tarjetas de foto y nombre, sin filtros ni etiquetas, a petición del cliente.
- **Pasos de adopción:** en tarjetas.
- **Contacto:** sección oscura con el formulario en una tarjeta.
- **Pie:** columnas de enlaces.
@@ -128,7 +158,6 @@ Se instalan solos en el primer arranque (etapa 3 de `docker/setup.sh`).
| Smash Balloon Instagram Feed | activo | Muestra vuestro Instagram. Hay que conectar la cuenta. |
| Koko Analytics | activo | Estadísticas de visitas sin cookies. |
| Kadence Blocks | activo | Bloques visuales extra: carruseles de imágenes, pestañas, acordeones e iconos. |
-| Blocks Animation | activo | Animaciones de entrada para cualquier bloque. |
| GiveWP | desactivado | Donaciones online con tarjeta o PayPal. |
| MailPoet | desactivado | Newsletter. |
| Complianz | desactivado | Aviso de cookies. Solo hace falta si añadís YouTube, Analytics, etc. |
diff --git a/docker/content/es/acoge.html b/docker/content/es/acoge.html
new file mode 100644
index 0000000..08d8b2a
--- /dev/null
+++ b/docker/content/es/acoge.html
@@ -0,0 +1,29 @@
+
+
Quizá ahora no puedas adoptar, pero sí ofrecer un hogar durante un tiempo. Escríbenos y te contamos qué animales necesitan acogida y cómo puedes ayudar.
+ + + +Es un hogar temporal para un perro o un gato mientras encuentra a su familia. Algunos lo necesitan especialmente: cachorros, animales mayores o que se están recuperando y que están mejor en una casa que en la protectora.
+ + + +Cada acogida es distinta. Antes de empezar hablamos contigo de cuánto tiempo sería, los gastos, el material que hace falta y cómo te acompañamos durante la acogida.
+ + + + + + + +¿Tienes dudas? Mira las preguntas frecuentes o escríbenos.
+ diff --git a/docker/content/es/colabora.html b/docker/content/es/colabora.html index 5cdf1ca..100643a 100644 --- a/docker/content/es/colabora.html +++ b/docker/content/es/colabora.html @@ -1,63 +1,45 @@ -Cada ayuda cuenta. Estas son las formas en las que puedes cambiar la vida de nuestros animales:
- - - -Adoptar es la forma más directa de salvar una vida. Consulta los animales en adopción, ven a conocerlos y te acompañaremos en todo el proceso. Todos se entregan con microchip, vacunados y esterilizados.
- - - -Algunos animales necesitan salir del centro cuanto antes: cachorros, mayores o convalecientes. Como casa de acogida les ofreces un hogar temporal mientras encuentran su familia definitiva. Nosotros te orientamos en todo momento.
+Hay muchas maneras de ayudar a los animales de Bilagun, y todas cuentan.
-Pasear perros, socializar gatos, ayudar en jornadas de adopción, hacer fotos para las fichas o difundir en redes sociales. Si tienes tiempo y ganas, ¡te necesitamos!
- - - -Siempre nos vienen bien:
- - - -Si prefieres hacer una aportación económica, escríbenos y te indicamos cómo.
+Paseos, compañía y socialización de perros y gatos. Si te apetece echarnos una mano, concertamos una primera cita y rellenamos juntos un cuestionario.
+ + + +Si no puedes adoptar, también puedes ayudar compartiendo su historia. Cada ficha tiene su propio enlace para enviarla por WhatsApp o redes.
+ + + + diff --git a/docker/content/es/contacto.html b/docker/content/es/contacto.html index 1372b74..62dab77 100644 --- a/docker/content/es/contacto.html +++ b/docker/content/es/contacto.html @@ -1,5 +1,9 @@ + +[ga_cita] + + -📍 Jaizubia, 44 · 20280 Hondarribia (Gipuzkoa)
📞 943 64 52 79
✉️ hola@gureametsabilagun.org
🕙 Lunes a viernes: 10:00–13:00 y 14:00–19:00
Jaizubia, 44 · 20280 Hondarribia (Gipuzkoa)
943 64 52 79 · hola@gureametsabilagun.org
Atención al público: lunes a viernes, 10:00–13:00 y 14:00–19:00
Para adopciones, acogidas, voluntariado o reservas del hotel, déjanos tu mensaje y te responderemos lo antes posible.
+Cuéntanos qué necesitas y te respondemos lo antes posible.
diff --git a/docker/content/es/hotel.html b/docker/content/es/hotel.html deleted file mode 100644 index 7f934c9..0000000 --- a/docker/content/es/hotel.html +++ /dev/null @@ -1,35 +0,0 @@ - -¿Planeas unas vacaciones y no puedes llevar a tu compañero? En Gure Ametsa Bi Lagun cuidamos de tu perro o gato mientras estás fuera, en nuestras instalaciones de Jaizubia (Hondarribia), rodeadas de naturaleza.
- - - -Para reservar es necesario que el animal tenga el microchip y las vacunas al día. Las plazas se llenan en verano y fechas señaladas: reserva con antelación.
- - - - - diff --git a/docker/content/es/preguntas-frecuentes.html b/docker/content/es/preguntas-frecuentes.html new file mode 100644 index 0000000..e685634 --- /dev/null +++ b/docker/content/es/preguntas-frecuentes.html @@ -0,0 +1,39 @@ + +Entra en la ficha del animal que te interese y pulsa «Quiero conocerlo» o «Quiero conocerla». Te enviaremos nuestro cuestionario, lo valoramos con el equipo y quedamos para conoceros. Enviar la solicitud no confirma una adopción.
+Las visitas son siempre con cita previa. Escríbenos o llámanos y buscamos un momento.
+Ofrecer un hogar temporal a un animal mientras encuentra a su familia. La duración, los gastos, el material y el acompañamiento los concretamos contigo en cada caso.
+Escríbenos: concertamos una primera cita y rellenamos un cuestionario. Buscamos ayuda con paseos, compañía y socialización.
+Tienes la lista actualizada en Colabora. Antes de traer nada, escríbenos para concretar la entrega.
+Depende de cada caso. Cuéntanoslo cuando nos escribas y lo valoramos juntos con el equipo.
+¿No encuentras tu respuesta? Escríbenos.
+ diff --git a/docker/content/es/quienes-somos.html b/docker/content/es/quienes-somos.html index 1a9f132..ea79d09 100644 --- a/docker/content/es/quienes-somos.html +++ b/docker/content/es/quienes-somos.html @@ -1,43 +1,33 @@ -Gure Ametsa Bi Lagun (en euskera, «nuestro sueño, dos amigos») es un centro de protección y residencia de animales situado en Jaizubia, Hondarribia.
+Bilagun es la protectora de Jaizubia, en Hondarribia. Desde hace más de 25 años colaboramos con los ayuntamientos de Irun y Hondarribia: cuando aparece un perro o un gato perdido o abandonado, llega a nuestras instalaciones, pasa control veterinario y lo cuidamos hasta que vuelve con su familia o encuentra una nueva.
-Trabajamos desde hace más de 25 años con los ayuntamientos de Irun y Hondarribia. Cuando la Policía Municipal encuentra un animal perdido o abandonado en la vía pública, lo trae a nuestras instalaciones. Aquí pasa un control veterinario y permanece alojado y cuidado hasta que vuelve con su familia o encuentra una nueva.
+Para nosotras cada animal es un individuo, con su historia, sus miedos y su forma de ser. Intentamos conocerlo bien para contar con sinceridad cómo es y qué necesita.
-Cumpliendo la Ley de Bienestar Animal, todos los animales reciben los tratamientos necesarios antes de ser adoptados:
+Antes de la adopción, todos reciben microchip, vacunas, desparasitación y esterilización.
- --- - -Adopta y cambia dos mundos: el suyo y el tuyo.
-
Si has perdido a tu perro o gato en Irun u Hondarribia, llámanos cuanto antes al 943 64 52 79 y avisa también a la Policía Municipal. Tener el microchip actualizado es la mejor forma de que vuelva a casa.
+No buscamos familias perfectas, sino familias que encajen con cada animal y respeten su ritmo. Por eso vamos sin prisas: primero nos conocemos y después valoramos juntos.
+ + + + diff --git a/docker/content/eu/harremanetarako.html b/docker/content/eu/harremanetarako.html index 031503d..d741221 100644 --- a/docker/content/eu/harremanetarako.html +++ b/docker/content/eu/harremanetarako.html @@ -1,5 +1,9 @@ + +[ga_cita] + + -📍 Jaizubia, 44 · 20280 Hondarribia (Gipuzkoa)
📞 943 64 52 79
✉️ hola@gureametsabilagun.org
🕙 Astelehenetik ostiralera: 10:00–13:00 eta 14:00–19:00
Jaizubia, 44 · 20280 Hondarribia (Gipuzkoa)
943 64 52 79 · hola@gureametsabilagun.org
Jendaurreko arreta: astelehenetik ostiralera, 10:00–13:00 eta 14:00–19:00
Adopzioak, harrerak, boluntariotza edo hoteleko erreserbak direla eta, utzi zure mezua eta ahalik eta lasterren erantzungo dizugu.
+Kontaiguzu zer behar duzun eta ahalik eta lasterren erantzungo dizugu.
diff --git a/docker/content/eu/harrera.html b/docker/content/eu/harrera.html new file mode 100644 index 0000000..68f2336 --- /dev/null +++ b/docker/content/eu/harrera.html @@ -0,0 +1,29 @@ + +Agian orain ezin duzu adoptatu, baina bai etxe bat eskaini denbora batez. Idatzi iezaguzu eta kontatuko dizugu zein animaliak behar duten harrera eta nola lagun dezakezun.
+ + + +Txakur edo katu batentzako aldi baterako etxea da, bere familia aurkitu bitartean. Batzuek bereziki behar dute: kumeek, animalia zaharrek edo sendatzen ari direnek, babeslekuan baino hobeto baitaude etxe batean.
+ + + +Harrera bakoitza desberdina da. Hasi aurretik zurekin hitz egingo dugu iraupenaz, gastuez, behar den materialaz eta harreran zehar nola lagunduko dizugun.
+ + + + + + + +Zalantzarik baduzu? Begiratu ohiko galderak edo idatzi iezaguzu.
+ diff --git a/docker/content/eu/hotela.html b/docker/content/eu/hotela.html deleted file mode 100644 index 8d3d0b6..0000000 --- a/docker/content/eu/hotela.html +++ /dev/null @@ -1,35 +0,0 @@ - -Oporretara joateko asmoa duzu eta ezin duzu zure laguna eraman? Gure Ametsa Bi Lagunen zure txakurra edo katua zaintzen dugu kanpoan zauden bitartean, Hondarribiko Jaizubian ditugun instalazioetan, naturaz inguratuta.
- - - -Erreserba egiteko, animaliak mikrotxipa eta txertoak egunean izan behar ditu. Udan eta data berezietan plazak azkar betetzen dira: egin erreserba aldez aurretik.
- - - - - diff --git a/docker/content/eu/lagundu.html b/docker/content/eu/lagundu.html index bf67763..9c861d3 100644 --- a/docker/content/eu/lagundu.html +++ b/docker/content/eu/lagundu.html @@ -1,63 +1,45 @@ -Laguntza oro da garrantzitsua. Hauek dira gure animalien bizitza aldatzeko moduak:
- - - -Adoptatzea da bizitza bat salbatzeko modurik zuzenena. Begiratu adopzioko animaliak, etorri haiek ezagutzera eta prozesu osoan lagunduko dizugu. Guztiak mikrotxiparekin, txertatuta eta antzututa ematen dira.
- - - -Animalia batzuek lehenbailehen irten behar dute zentrotik: kumeek, zaharrek edo gaixorik daudenek. Harrera-etxe gisa, aldi baterako etxe bat eskaintzen diezu behin betiko familia aurkitu bitartean. Guk uneoro bideratuko zaitugu.
+Bilaguneko animaliei laguntzeko modu asko daude, eta guztiak dira garrantzitsuak.
-Txakurrak paseatu, katuak sozializatu, adopzio-jardunaldietan lagundu, fitxetarako argazkiak atera edo sare sozialetan zabaldu. Denbora eta gogoa badituzu, behar zaitugu!
- - - -Beti ondo etortzen zaizkigu:
- - - -Diru-ekarpen bat egin nahi baduzu, idatzi iezaguzu eta nola egin azalduko dizugu.
+Txakur eta katuekin ibilaldiak, konpainia eta sozializazioa. Esku bat eman nahi badiguzu, lehen hitzordu bat hitzartu eta galdetegi bat beteko dugu elkarrekin.
+ + + +Ezin baduzu adoptatu, haren istorioa partekatuz ere lagun dezakezu. Fitxa bakoitzak bere esteka du WhatsApp edo sare sozialen bidez bidaltzeko.
+ + + + diff --git a/docker/content/eu/nor-gara.html b/docker/content/eu/nor-gara.html index 2a0f567..d04b461 100644 --- a/docker/content/eu/nor-gara.html +++ b/docker/content/eu/nor-gara.html @@ -1,43 +1,33 @@ -Gure Ametsa Bi Lagun animaliak babesteko zentro eta egoitza bat da, Hondarribiko Jaizubia auzoan.
+Bilagun Jaizubiko babeslekua da, Hondarribian. 25 urte baino gehiago daramatzagu Irun eta Hondarribiko udalekin lanean: txakur edo katu bat galduta edo abandonatuta agertzen denean, gure instalazioetara iristen da, albaitari-kontrola egiten zaio eta zaindu egiten dugu bere familiarengana itzuli arte edo familia berri bat aurkitu arte.
-25 urte baino gehiago daramatzagu Irun eta Hondarribiko udalekin lanean. Udaltzaingoak kalean galdutako edo abandonatutako animalia bat aurkitzen duenean, gure instalazioetara ekartzen du. Hemen albaitari-kontrola egiten zaio eta zainduta egoten da bere familiarengana itzuli arte edo familia berri bat aurkitu arte.
+Guretzat animalia bakoitza norbait da, bere istorio, beldur eta izaerarekin. Ondo ezagutzen saiatzen gara, nolakoa den eta zer behar duen zintzotasunez kontatzeko.
-Animalien Ongizaterako Legea betez, animalia guztiek beharrezko tratamenduak jasotzen dituzte adoptatu aurretik:
+Adoptatu aurretik, guztiek mikrotxipa, txertoak, desparasitazioa eta antzutzea jasotzen dituzte.
- --- - -Adoptatu eta bi mundu aldatu: berea eta zurea.
-
Zure txakurra edo katua Irunen edo Hondarribian galdu baduzu, deitu iezaguzu lehenbailehen 943 64 52 79 zenbakira eta jakinarazi Udaltzaingoari ere. Mikrotxipa eguneratuta izatea da etxera itzultzeko modurik onena.
+Ez dugu familia perfekturik bilatzen, animalia bakoitzarekin bat datozen eta haren erritmoa errespetatzen duten familiak baizik. Horregatik presarik gabe goaz: lehenik elkar ezagutu eta gero elkarrekin baloratzen dugu.
+ + + + diff --git a/docker/content/eu/ohiko-galderak.html b/docker/content/eu/ohiko-galderak.html new file mode 100644 index 0000000..47b796a --- /dev/null +++ b/docker/content/eu/ohiko-galderak.html @@ -0,0 +1,39 @@ + +Sartu interesatzen zaizun animaliaren fitxan eta sakatu «Ezagutu nahi dut». Gure galdetegia bidaliko dizugu, taldearekin baloratuko dugu eta elkar ezagutzeko geratuko gara. Eskaera bidaltzeak ez du adopzioa baieztatzen.
+Bisitak beti aurretiko hitzorduarekin dira. Idatzi edo deitu iezaguzu eta une bat bilatuko dugu.
+Animalia bati aldi baterako etxe bat eskaintzea, bere familia aurkitu bitartean. Iraupena, gastuak, materiala eta laguntza zurekin zehazten ditugu kasu bakoitzean.
+Idatzi iezaguzu: lehen hitzordu bat hitzartu eta galdetegi bat betetzen dugu. Ibilaldietarako, konpainiarako eta sozializaziorako laguntza bilatzen dugu.
+Zerrenda eguneratua Lagundu atalean duzu. Ezer ekarri aurretik, idatzi iezaguzu entrega zehazteko.
+Kasuaren araberakoa da. Kontaiguzu idazten diguzunean eta elkarrekin baloratuko dugu taldearekin.
+Ez duzu zure erantzuna aurkitzen? Idatzi iezaguzu.
+ diff --git a/docker/setup-content.php b/docker/setup-content.php index 25f6b1f..762b106 100644 --- a/docker/setup-content.php +++ b/docker/setup-content.php @@ -1,45 +1,49 @@ model; $existing = wp_list_pluck( $model->get_languages_list(), 'slug' ); - $langs = array( + foreach ( array( array( 'locale' => 'es_ES', 'slug' => 'es', 'name' => 'Español', 'flag' => 'es', 'term_group' => 0 ), array( 'locale' => 'eu', 'slug' => 'eu', 'name' => 'Euskara', 'flag' => 'basque', 'term_group' => 1 ), - ); - foreach ( $langs as $lang ) { - if ( in_array( $lang['slug'], $existing, true ) ) { - continue; - } - $result = $model->add_language( $lang ); - if ( is_wp_error( $result ) ) { - WP_CLI::warning( 'No se pudo crear el idioma ' . $lang['slug'] . ': ' . $result->get_error_message() ); + ) as $lang ) { + if ( ! in_array( $lang['slug'], $existing, true ) ) { + $result = $model->add_language( $lang ); + if ( is_wp_error( $result ) ) { + WP_CLI::warning( 'No se pudo crear el idioma ' . $lang['slug'] . ': ' . $result->get_error_message() ); + } } } $model->clean_languages_cache(); $settings = array( - 'default_lang' => 'es', - 'force_lang' => 1, // Idioma en el directorio: /eu/... - 'hide_default' => true, // Castellano sin prefijo. - 'rewrite' => true, // /eu/ en lugar de /language/eu/. - 'redirect_lang' => true, // Portada en euskera en /eu/ (no /eu/hasiera/). - 'browser' => false, - 'post_types' => array( 'animal' ), - 'taxonomies' => array( 'especie' ), - 'sync' => array( 'taxonomies', 'post_meta', '_thumbnail_id', 'menu_order', 'post_parent' ), + 'default_lang' => 'es', + 'force_lang' => 1, // Idioma en el directorio: /eu/... + 'hide_default' => true, // Castellano sin prefijo. + 'rewrite' => true, // /eu/ en lugar de /language/eu/. + 'redirect_lang' => true, // Portada en euskera en /eu/. + 'browser' => false, + 'post_types' => array( 'animal' ), + 'taxonomies' => array( 'especie' ), + 'sync' => array( 'taxonomies', 'post_meta', '_thumbnail_id', 'menu_order', 'post_parent' ), ); $options = PLL()->options; if ( is_object( $options ) && method_exists( $options, 'set' ) ) { @@ -52,7 +56,6 @@ if ( $pll ) { } else { update_option( 'polylang', array_merge( (array) get_option( 'polylang', array() ), $settings ) ); } - // Traducción al euskera del lema del sitio. if ( class_exists( 'PLL_MO' ) && ( $eu = $model->get_language( 'eu' ) ) ) { $mo = new PLL_MO(); $mo->import_from_db( $eu ); @@ -62,25 +65,46 @@ if ( $pll ) { if ( class_exists( 'PLL_Admin_Notices' ) ) { PLL_Admin_Notices::dismiss( 'wizard' ); } - WP_CLI::log( '[ga-setup] Idiomas: castellano (por defecto) y euskera' ); } /* ---------- 2. Páginas ---------- */ -function ga_setup_page( $slug, $title, $file, $lang ) { - $existing = get_page_by_path( $slug, OBJECT, 'page' ); - if ( $existing ) { - return $existing->ID; + +/** ¿La página sigue con el contenido que pusimos nosotros? */ +function ga_setup_untouched( WP_Post $post ) { + $hash = get_post_meta( $post->ID, '_ga_seed_hash', true ); + if ( $hash ) { + return md5( $post->post_content ) === $hash; } - $content = file_get_contents( $file ); - $id = wp_insert_post( array( - 'post_type' => 'page', - 'post_status' => 'publish', - 'post_title' => $title, - 'post_name' => $slug, - 'post_content' => $content, - ), true ); - if ( is_wp_error( $id ) ) { - WP_CLI::error( "No se pudo crear la página $slug: " . $id->get_error_message() ); + // Páginas de la primera instalación (sin huella): intactas si nunca se han modificado. + return $post->post_modified_gmt === $post->post_date_gmt; +} + +function ga_setup_page( $slug, $title, $file, $lang ) { + $content = file_exists( $file ) ? file_get_contents( $file ) : ''; + $page = get_page_by_path( $slug, OBJECT, 'page' ); + + if ( $page && 'trash' !== $page->post_status ) { + if ( $content && ga_setup_untouched( $page ) && trim( $page->post_content ) !== trim( $content ) ) { + wp_update_post( array( 'ID' => $page->ID, 'post_content' => $content, 'post_title' => $title ) ); + update_post_meta( $page->ID, '_ga_seed_hash', md5( get_post( $page->ID )->post_content ) ); + WP_CLI::log( "[ga-setup] actualizada: $slug" ); + } elseif ( ! ga_setup_untouched( $page ) ) { + WP_CLI::log( "[ga-setup] se respeta (editada): $slug" ); + } + $id = $page->ID; + } else { + $id = wp_insert_post( array( + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_title' => $title, + 'post_name' => $slug, + 'post_content' => $content, + ), true ); + if ( is_wp_error( $id ) ) { + WP_CLI::error( "No se pudo crear la página $slug: " . $id->get_error_message() ); + } + update_post_meta( $id, '_ga_seed_hash', md5( get_post( $id )->post_content ) ); + WP_CLI::log( "[ga-setup] creada: $slug" ); } if ( function_exists( 'pll_set_post_language' ) ) { pll_set_post_language( $id, $lang ); @@ -88,43 +112,50 @@ function ga_setup_page( $slug, $title, $file, $lang ) { return $id; } -// slug es => [título es, archivo es, slug eu, título eu, archivo eu] +// slug es => [título es, slug eu, título eu] $pages = array( - 'inicio' => array( 'Inicio', 'inicio', 'hasiera', 'Hasiera', 'hasiera' ), - 'quienes-somos' => array( 'Quiénes somos', 'quienes-somos', 'nor-gara', 'Nor gara', 'nor-gara' ), - 'colabora' => array( 'Colabora', 'colabora', 'lagundu', 'Lagundu', 'lagundu' ), - 'hotel' => array( 'Hotel para perros y gatos', 'hotel', 'hotela', 'Txakur eta katuentzako hotela', 'hotela' ), - 'contacto' => array( 'Contacto', 'contacto', 'harremanetarako', 'Harremanetarako', 'harremanetarako' ), - 'politica-de-privacidad' => array( 'Política de privacidad', 'privacidad', 'pribatutasun-politika', 'Pribatutasun-politika', 'pribatutasun-politika' ), - 'aviso-legal' => array( 'Aviso legal', 'aviso-legal', 'lege-oharra', 'Lege-oharra', 'lege-oharra' ), + 'inicio' => array( 'Inicio', 'hasiera', 'Hasiera' ), + 'acoge' => array( 'Acoge', 'harrera', 'Harrera' ), + 'colabora' => array( 'Colabora', 'lagundu', 'Lagundu' ), + 'quienes-somos' => array( 'Quiénes somos', 'nor-gara', 'Nor gara' ), + 'contacto' => array( 'Contacto', 'harremanetarako', 'Harremanetarako' ), + 'preguntas-frecuentes' => array( 'Preguntas frecuentes', 'ohiko-galderak', 'Ohiko galderak' ), + 'politica-de-privacidad' => array( 'Política de privacidad', 'pribatutasun-politika', 'Pribatutasun-politika' ), + 'aviso-legal' => array( 'Aviso legal', 'lege-oharra', 'Lege-oharra' ), ); +$files = array( 'politica-de-privacidad' => 'privacidad' ); $ids = array(); -foreach ( $pages as $slug => [ $title_es, $file_es, $slug_eu, $title_eu, $file_eu ] ) { - $ids[ $slug ]['es'] = ga_setup_page( $slug, $title_es, "$src/es/$file_es.html", 'es' ); +foreach ( $pages as $slug => [ $title_es, $slug_eu, $title_eu ] ) { + $ids[ $slug ]['es'] = ga_setup_page( $slug, $title_es, "$src/es/" . ( $files[ $slug ] ?? $slug ) . '.html', 'es' ); if ( $pll ) { - $ids[ $slug ]['eu'] = ga_setup_page( $slug_eu, $title_eu, "$src/eu/$file_eu.html", 'eu' ); + $ids[ $slug ]['eu'] = ga_setup_page( $slug_eu, $title_eu, "$src/eu/$slug_eu.html", 'eu' ); pll_save_post_translations( $ids[ $slug ] ); } } +// El hotel ya no forma parte de la web: se retira si nadie lo ha editado. +foreach ( array( 'hotel', 'hotela' ) as $slug ) { + $page = get_page_by_path( $slug, OBJECT, 'page' ); + if ( $page && 'trash' !== $page->post_status ) { + if ( ga_setup_untouched( $page ) ) { + wp_trash_post( $page->ID ); + WP_CLI::log( "[ga-setup] a la papelera: $slug" ); + } else { + WP_CLI::warning( "La página «$slug» se ha editado: no se borra, revísala a mano." ); + } + } +} + update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', $ids['inicio']['es'] ); update_option( 'wp_page_for_privacy_policy', $ids['politica-de-privacidad']['es'] ); -WP_CLI::log( '[ga-setup] Páginas creadas' ); +WP_CLI::log( '[ga-setup] Páginas listas' ); -/* ---------- 3. Especies ---------- */ -$species = array( - 'perro' => array( 'Perro', 'txakurra', 'Txakurra' ), - 'gato' => array( 'Gato', 'katua', 'Katua' ), - 'otros' => array( 'Otros', 'besteak', 'Besteak' ), -); +/* ---------- 3. Especies: solo perros y gatos ---------- */ $term_ids = array(); -foreach ( $species as $slug => [ $name_es, $slug_eu, $name_eu ] ) { - $pairs = array( 'es' => array( $slug, $name_es ) ); - if ( $pll ) { - $pairs['eu'] = array( $slug_eu, $name_eu ); - } +foreach ( array( 'perro' => array( 'Perro', 'txakurra', 'Txakurra' ), 'gato' => array( 'Gato', 'katua', 'Katua' ) ) as $slug => [ $name_es, $slug_eu, $name_eu ] ) { + $pairs = array( 'es' => array( $slug, $name_es ) ) + ( $pll ? array( 'eu' => array( $slug_eu, $name_eu ) ) : array() ); foreach ( $pairs as $lang => [ $term_slug, $term_name ] ) { $term = get_term_by( 'slug', $term_slug, 'especie' ); if ( ! $term ) { @@ -138,64 +169,95 @@ foreach ( $species as $slug => [ $name_es, $slug_eu, $name_eu ] ) { } } } - if ( $pll && count( $term_ids[ $slug ] ?? array() ) === 2 ) { + if ( $pll && 2 === count( $term_ids[ $slug ] ?? array() ) ) { pll_save_term_translations( $term_ids[ $slug ] ); } } +foreach ( array( 'otros', 'besteak' ) as $slug ) { + $term = get_term_by( 'slug', $slug, 'especie' ); + if ( $term && 0 === (int) $term->count ) { + wp_delete_term( $term->term_id, 'especie' ); + } +} /* ---------- 4. Menús ---------- */ -function ga_setup_menu( $name, $items ) { +function ga_setup_menu( $name, $items, $rebuild ) { $menu = wp_get_nav_menu_object( $name ); - if ( $menu ) { + if ( $menu && ! $rebuild ) { return $menu->term_id; } + if ( $menu ) { + wp_delete_nav_menu( $menu->term_id ); + } $menu_id = wp_create_nav_menu( $name ); - foreach ( $items as $pos => $item ) { - $args = array( 'menu-item-status' => 'publish', 'menu-item-position' => $pos + 1, 'menu-item-title' => $item['title'] ); - if ( isset( $item['page'] ) ) { - $args += array( 'menu-item-type' => 'post_type', 'menu-item-object' => 'page', 'menu-item-object-id' => $item['page'] ); - } else { - $args += array( 'menu-item-type' => 'custom', 'menu-item-url' => $item['url'] ); + $pos = 0; + $add = function ( $item, $parent = 0 ) use ( $menu_id, &$pos, &$add ) { + $args = array( + 'menu-item-status' => 'publish', + 'menu-item-position' => ++$pos, + 'menu-item-title' => $item['title'], + 'menu-item-parent-id' => $parent, + ); + $args += isset( $item['page'] ) + ? array( 'menu-item-type' => 'post_type', 'menu-item-object' => 'page', 'menu-item-object-id' => $item['page'] ) + : array( 'menu-item-type' => 'custom', 'menu-item-url' => $item['url'] ); + $id = wp_update_nav_menu_item( $menu_id, 0, $args ); + foreach ( $item['children'] ?? array() as $child ) { + $add( $child, $id ); } - wp_update_nav_menu_item( $menu_id, 0, $args ); + }; + foreach ( $items as $item ) { + $add( $item ); } return $menu_id; } -$menus = array( +$rebuild = 'true' === getenv( 'GA_SEED_MENUS' ); +$menus = array( 'primary' => array( 'es' => ga_setup_menu( 'Principal', array( - array( 'title' => 'Adopta', 'url' => '/adopta/' ), - array( 'title' => 'Acoge', 'url' => '/colabora/#acogida' ), - array( 'title' => 'Voluntariado', 'url' => '/colabora/#voluntariado' ), - array( 'title' => 'Dona', 'url' => '/colabora/#donaciones' ), - array( 'title' => 'Hotel', 'page' => $ids['hotel']['es'] ), + array( 'title' => 'Inicio', 'page' => $ids['inicio']['es'] ), + array( 'title' => 'Adopta', 'url' => '/adopta/', 'children' => array( + array( 'title' => 'Perros', 'url' => '/especie/perro/' ), + array( 'title' => 'Gatos', 'url' => '/especie/gato/' ), + ) ), + array( 'title' => 'Acoge', 'page' => $ids['acoge']['es'] ), + array( 'title' => 'Colabora', 'page' => $ids['colabora']['es'], 'children' => array( + array( 'title' => 'Voluntariado', 'url' => '/colabora/#voluntariado' ), + array( 'title' => 'Ayuda material', 'url' => '/colabora/#material' ), + ) ), + array( 'title' => 'Quiénes somos', 'page' => $ids['quienes-somos']['es'] ), array( 'title' => 'Contacto', 'page' => $ids['contacto']['es'] ), - ) ), + ), $rebuild ), ), 'footer' => array( 'es' => ga_setup_menu( 'Legal', array( array( 'title' => 'Aviso legal', 'page' => $ids['aviso-legal']['es'] ), array( 'title' => 'Política de privacidad', 'page' => $ids['politica-de-privacidad']['es'] ), - ) ), + ), $rebuild ), ), ); if ( $pll ) { $menus['primary']['eu'] = ga_setup_menu( 'Nagusia (euskara)', array( - array( 'title' => 'Adoptatu', 'url' => '/eu/adopta/' ), - array( 'title' => 'Harrera', 'url' => '/eu/lagundu/#acogida' ), - array( 'title' => 'Boluntariotza', 'url' => '/eu/lagundu/#voluntariado' ), - array( 'title' => 'Dohaintza', 'url' => '/eu/lagundu/#donaciones' ), - array( 'title' => 'Hotela', 'page' => $ids['hotel']['eu'] ), + array( 'title' => 'Hasiera', 'page' => $ids['inicio']['eu'] ), + array( 'title' => 'Adoptatu', 'url' => '/eu/adopta/', 'children' => array( + array( 'title' => 'Txakurrak', 'url' => '/eu/especie/txakurra/' ), + array( 'title' => 'Katuak', 'url' => '/eu/especie/katua/' ), + ) ), + array( 'title' => 'Harrera', 'page' => $ids['acoge']['eu'] ), + array( 'title' => 'Lagundu', 'page' => $ids['colabora']['eu'], 'children' => array( + array( 'title' => 'Boluntariotza', 'url' => '/eu/lagundu/#voluntariado' ), + array( 'title' => 'Laguntza materiala', 'url' => '/eu/lagundu/#material' ), + ) ), + array( 'title' => 'Nor gara', 'page' => $ids['quienes-somos']['eu'] ), array( 'title' => 'Harremanetarako', 'page' => $ids['contacto']['eu'] ), - ) ); + ), $rebuild ); $menus['footer']['eu'] = ga_setup_menu( 'Legala (euskara)', array( array( 'title' => 'Lege-oharra', 'page' => $ids['aviso-legal']['eu'] ), array( 'title' => 'Pribatutasun-politika', 'page' => $ids['politica-de-privacidad']['eu'] ), - ) ); + ), $rebuild ); - $theme = get_stylesheet(); - $nav_menus = array( $theme => $menus ); + $nav_menus = array( get_stylesheet() => $menus ); if ( is_object( PLL()->options ) && method_exists( PLL()->options, 'set' ) ) { PLL()->options->set( 'nav_menus', $nav_menus ); if ( method_exists( PLL()->options, 'save_all' ) ) { @@ -207,44 +269,51 @@ if ( $pll ) { update_option( 'polylang', $opts ); } } -set_theme_mod( 'nav_menu_locations', array( - 'primary' => $menus['primary']['es'], - 'footer' => $menus['footer']['es'], -) ); -WP_CLI::log( '[ga-setup] Menús creados' ); +set_theme_mod( 'nav_menu_locations', array( 'primary' => $menus['primary']['es'], 'footer' => $menus['footer']['es'] ) ); +WP_CLI::log( '[ga-setup] Menús listos' ); -/* ---------- 5. Animales de ejemplo (opcional) ---------- */ -if ( 'true' === getenv( 'SEED_DEMO_ANIMALS' ) ) { +/* ---------- 5. Animales ---------- */ + +// Estados antiguos → nuevos (disponible / proceso / adoptado). +foreach ( get_posts( array( 'post_type' => 'animal', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids', 'lang' => '' ) ) as $animal_id ) { + $estado = get_post_meta( $animal_id, '_ga_estado', true ); + $map = array( 'reservado' => 'proceso', 'urgente' => 'disponible', 'acogida' => 'disponible' ); + if ( isset( $map[ $estado ] ) ) { + update_post_meta( $animal_id, '_ga_estado', $map[ $estado ] ); + } +} + +if ( 'true' === getenv( 'SEED_DEMO_ANIMALS' ) && ! get_posts( array( 'post_type' => 'animal', 'numberposts' => 1, 'post_status' => 'any', 'lang' => '' ) ) ) { $demo = array( array( - 'es' => array( 'Txuri (ejemplo)', 'Txuri es cariñosa, tranquila en casa y le encantan los paseos por Jaizkibel.' ), - 'eu' => array( 'Txuri (adibidea)', 'Txuri maitekorra da, lasaia etxean, eta Jaizkibelen barrena paseatzea asko gustatzen zaio.' ), + 'es' => array( 'Txuri (ejemplo)', 'Llegó un poco asustada, pero en cuanto coge confianza no se separa de ti.', array( 'caracter' => 'Tranquila en casa y muy cariñosa con quien conoce. Le encantan los paseos largos.', 'hogar' => 'Una familia que respete su ritmo y le acompañe con paciencia.' ) ), + 'eu' => array( 'Txuri (adibidea)', 'Beldur pixka batekin iritsi zen, baina konfiantza hartzen duenean ez da zure ondotik aldentzen.', array( 'caracter' => 'Lasaia etxean eta oso maitekorra ezagutzen dituenekin. Ibilaldi luzeak asko gustatzen zaizkio.', 'hogar' => 'Bere erritmoa errespetatu eta pazientziaz lagunduko dion familia bat.' ) ), 'sp' => 'perro', - 'meta' => array( 'sexo' => 'hembra', 'edad' => '3', 'edad_unidad' => 'anos', 'tamano' => 'mediano', 'estado' => 'disponible', 'raza' => 'Mestiza' ), + 'meta' => array( 'sexo' => 'hembra', 'edad' => '3', 'edad_unidad' => 'anos', 'tamano' => 'mediano', 'estado' => 'disponible', 'destacado' => '1' ), ), array( - 'es' => array( 'Beltza (ejemplo)', 'Beltza es un gato curioso y juguetón que busca un hogar sin prisas.' ), - 'eu' => array( 'Beltza (adibidea)', 'Beltza katu jakin-nahia eta jostalaria da, eta presarik gabe etxe baten bila dabil.' ), + 'es' => array( 'Beltza (ejemplo)', 'Curioso y juguetón, siempre quiere saber qué estás haciendo.', array( 'caracter' => 'Muy sociable con las personas. Le gusta jugar y dormir al sol.' ) ), + 'eu' => array( 'Beltza (adibidea)', 'Jakin-mina eta jostalaria, beti jakin nahi du zer egiten ari zaren.', array( 'caracter' => 'Oso soziala pertsonekin. Jolastea eta eguzkitan lo egitea gustatzen zaizkio.' ) ), 'sp' => 'gato', - 'meta' => array( 'sexo' => 'macho', 'edad' => '1', 'edad_unidad' => 'anos', 'tamano' => 'pequeno', 'estado' => 'disponible', 'raza' => 'Común europeo' ), + 'meta' => array( 'sexo' => 'macho', 'edad' => '1', 'edad_unidad' => 'anos', 'estado' => 'disponible' ), ), array( - 'es' => array( 'Hartz (ejemplo)', 'Hartz es un abuelito noble que merece pasar sus mejores años en familia.' ), - 'eu' => array( 'Hartz (adibidea)', 'Hartz aitona noblea da, eta bere urterik onenak familian igarotzea merezi du.' ), + 'es' => array( 'Hartz (ejemplo)', 'Un abuelito noble que merece pasar sus mejores años en familia.', array( 'necesidades' => 'Paseos tranquilos y una casa sin muchas escaleras.' ) ), + 'eu' => array( 'Hartz (adibidea)', 'Aitona noblea, bere urterik onenak familian igarotzea merezi duena.', array( 'necesidades' => 'Ibilaldi lasaiak eta eskailera askorik gabeko etxea.' ) ), 'sp' => 'perro', - 'meta' => array( 'sexo' => 'macho', 'edad' => '7', 'edad_unidad' => 'anos', 'tamano' => 'grande', 'estado' => 'urgente', 'raza' => 'Mastín' ), + 'meta' => array( 'sexo' => 'macho', 'edad' => '9', 'edad_unidad' => 'anos', 'tamano' => 'grande', 'estado' => 'disponible', 'destacado' => '1' ), ), array( - 'es' => array( 'Ilargi (ejemplo)', 'Ilargi es una gatita sociable que se lleva bien con otros gatos.' ), - 'eu' => array( 'Ilargi (adibidea)', 'Ilargi katakume soziala da eta beste katuekin ondo moldatzen da.' ), + 'es' => array( 'Ilargi (ejemplo)', 'Una gatita sociable que se lleva bien con otros gatos.', array() ), + 'eu' => array( 'Ilargi (adibidea)', 'Beste katuekin ondo moldatzen den katakume soziala.', array() ), 'sp' => 'gato', - 'meta' => array( 'sexo' => 'hembra', 'edad' => '4', 'edad_unidad' => 'meses', 'tamano' => 'pequeno', 'estado' => 'reservado', 'raza' => 'Común europeo' ), + 'meta' => array( 'sexo' => 'hembra', 'edad' => '4', 'edad_unidad' => 'meses', 'estado' => 'proceso' ), ), ); foreach ( $demo as $animal ) { $translations = array(); foreach ( $pll ? array( 'es', 'eu' ) : array( 'es' ) as $lang ) { - [ $title, $text ] = $animal[ $lang ]; + [ $title, $text, $texts ] = $animal[ $lang ]; $id = wp_insert_post( array( 'post_type' => 'animal', 'post_status' => 'publish', @@ -254,7 +323,7 @@ if ( 'true' === getenv( 'SEED_DEMO_ANIMALS' ) ) { if ( ! empty( $term_ids[ $animal['sp'] ][ $lang ] ) ) { wp_set_object_terms( $id, array( $term_ids[ $animal['sp'] ][ $lang ] ), 'especie' ); } - foreach ( $animal['meta'] + array( 'salud' => 'chip,vacunado,esterilizado', 'compatible' => 'perros,ninos' ) as $key => $value ) { + foreach ( $animal['meta'] + $texts as $key => $value ) { update_post_meta( $id, "_ga_$key", $value ); } if ( $pll ) { diff --git a/docker/setup.sh b/docker/setup.sh index d29e258..451c902 100644 --- a/docker/setup.sh +++ b/docker/setup.sh @@ -103,7 +103,7 @@ if (( VERSION < 2 )); then wp_ language plugin install polylang es_ES eu 2>/dev/null || true # Idiomas, páginas, especies, menús y (opcional) animales de ejemplo - if ! wp_ eval-file "$SRC/setup-content.php"; then + if ! GA_SEED_MENUS=true wp_ eval-file "$SRC/setup-content.php"; then log "Fallo creando el contenido inicial" exit 1 fi @@ -127,7 +127,6 @@ if (( VERSION < 3 )); then instagram-feed # Feed de Instagram koko-analytics # Estadísticas sin cookies kadence-blocks # Bloques visuales: carruseles, pestañas, acordeones… - blocks-animation # Animaciones de entrada para cualquier bloque ) # Instalados pero desactivados: se activan cuando se necesiten INACTIVE=( @@ -170,4 +169,18 @@ if (( VERSION < 4 )); then wp_ option update ga_setup_version 4 fi +# Etapa 5: indicaciones del cliente (adopción solo Perros/Gatos, fichas nuevas, sin hotel ni donaciones) +if (( VERSION < 5 )); then + log "Migración 5: páginas, menús y fichas nuevas" + # Crea las páginas nuevas, actualiza solo las que nadie ha editado, retira el hotel y rehace los menús + if ! GA_SEED_MENUS=true wp_ eval-file "$SRC/setup-content.php"; then + log "Fallo en la migración 5" + exit 1 + fi + # Sin animaciones que distraigan + wp_ plugin deactivate blocks-animation >/dev/null 2>&1 || true + wp_ rewrite flush + wp_ option update ga_setup_version 5 +fi + log "Configuración completada" diff --git a/wp-content/mu-plugins/gure-ametsa-core.php b/wp-content/mu-plugins/gure-ametsa-core.php index 95cfcc5..256fc2b 100644 --- a/wp-content/mu-plugins/gure-ametsa-core.php +++ b/wp-content/mu-plugins/gure-ametsa-core.php @@ -1,764 +1,14 @@ ID; - if ( function_exists( 'pll_get_post' ) ) { - $id = pll_get_post( $id, ga_lang() ) ?: $id; - } - return get_permalink( $id ) . $fragment; -} - -/* Animales y especies son traducibles; los mensajes no. */ -add_filter( 'pll_get_post_types', function ( $types, $is_settings ) { - $types['animal'] = 'animal'; - unset( $types['ga_mensaje'] ); - return $types; -}, 10, 2 ); - -add_filter( 'pll_get_taxonomies', function ( $taxonomies ) { - $taxonomies['especie'] = 'especie'; - return $taxonomies; -} ); - -/* ------------------------------------------------------------------------- - * Datos de la protectora - * ---------------------------------------------------------------------- */ - -function ga_info( $key = null ) { - $info = apply_filters( 'ga_info', array( - 'nombre' => 'Gure Ametsa Bi Lagun', - 'direccion' => 'Jaizubia, 44 · 20280 Hondarribia (Gipuzkoa)', - 'telefono' => '943 64 52 79', - 'email' => 'hola@gureametsabilagun.org', - 'horario' => ga__( 'Lunes a viernes: 10:00–13:00 y 14:00–19:00', 'Astelehenetik ostiralera: 10:00–13:00 eta 14:00–19:00' ), - 'instagram' => 'https://www.instagram.com/gureametsabilagun/', - 'facebook' => 'https://www.facebook.com/gureametsabilagun/', - 'maps' => 'https://www.google.com/maps/search/?api=1&query=Jaizubia+44+Hondarribia', - ) ); - return $key ? ( $info[ $key ] ?? '' ) : $info; -} - -function ga_contact_email() { - $email = getenv( 'GA_CONTACT_EMAIL' ); - return is_email( $email ) ? $email : get_option( 'admin_email' ); -} - -/* ------------------------------------------------------------------------- - * Tipos de contenido y taxonomías - * ---------------------------------------------------------------------- */ - -add_action( 'init', function () { - register_post_type( 'animal', array( - 'labels' => array( - 'name' => 'Animales', - 'singular_name' => 'Animal', - 'add_new' => 'Añadir animal', - 'add_new_item' => 'Añadir nuevo animal', - 'edit_item' => 'Editar animal', - 'new_item' => 'Nuevo animal', - 'view_item' => 'Ver ficha', - 'search_items' => 'Buscar animales', - 'not_found' => 'No hay animales', - 'not_found_in_trash' => 'No hay animales en la papelera', - 'all_items' => 'Todos los animales', - 'featured_image' => 'Foto principal', - 'set_featured_image' => 'Elegir foto principal', - 'menu_name' => 'Animales', - ), - 'public' => true, - 'has_archive' => 'adopta', - 'rewrite' => array( 'slug' => 'adopta', 'with_front' => false ), - 'menu_icon' => 'dashicons-pets', - 'menu_position' => 5, - 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ), - 'show_in_rest' => true, - 'rest_base' => 'animales', - // WPGraphQL - 'show_in_graphql' => true, - 'graphql_single_name' => 'animal', - 'graphql_plural_name' => 'animales', - ) ); - - register_taxonomy( 'especie', 'animal', array( - 'labels' => array( - 'name' => 'Especies', - 'singular_name' => 'Especie', - 'add_new_item' => 'Añadir especie', - ), - 'hierarchical' => true, - 'show_admin_column' => true, - 'show_in_rest' => true, - 'rest_base' => 'especies', - 'show_in_graphql' => true, - 'graphql_single_name' => 'especie', - 'graphql_plural_name' => 'especies', - 'rewrite' => array( 'slug' => 'especie', 'with_front' => false ), - ) ); - - register_post_type( 'ga_mensaje', array( - 'labels' => array( - 'name' => 'Mensajes', - 'singular_name' => 'Mensaje', - 'edit_item' => 'Mensaje', - 'all_items' => 'Mensajes recibidos', - 'not_found' => 'Aún no hay mensajes', - ), - 'public' => false, - 'show_ui' => true, - 'menu_icon' => 'dashicons-email-alt', - 'menu_position' => 6, - 'supports' => array( 'title', 'editor' ), - 'capability_type' => 'post', - 'capabilities' => array( 'create_posts' => 'do_not_allow' ), - 'map_meta_cap' => true, - ) ); - - foreach ( array_keys( ga_fields() ) as $key ) { - register_post_meta( 'animal', "_ga_$key", array( - 'type' => 'string', - 'single' => true, - 'show_in_rest' => true, - 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, - ) ); - } -} ); - -/* ------------------------------------------------------------------------- - * Campos de la ficha (etiquetas en el idioma actual) - * ---------------------------------------------------------------------- */ - -function ga_fields() { - return array( - 'estado' => array( 'label' => ga__( 'Estado', 'Egoera' ), 'type' => 'select', 'options' => array( - 'disponible' => ga__( 'En adopción', 'Adopzioan' ), - 'urgente' => ga__( 'Adopción urgente', 'Adopzio premiazkoa' ), - 'acogida' => ga__( 'Busca casa de acogida', 'Harrera-etxe bila' ), - 'reservado' => ga__( 'Reservado', 'Erreserbatuta' ), - 'adoptado' => ga__( 'Adoptado', 'Adoptatuta' ), - ) ), - 'sexo' => array( 'label' => ga__( 'Sexo', 'Sexua' ), 'type' => 'select', 'options' => array( - 'macho' => ga__( 'Macho', 'Arra' ), - 'hembra' => ga__( 'Hembra', 'Emea' ), - ) ), - 'edad' => array( 'label' => ga__( 'Edad', 'Adina' ), 'type' => 'number', 'placeholder' => 'p. ej. 2' ), - 'edad_unidad' => array( 'label' => ga__( 'Edad en', 'Adina' ), 'type' => 'select', 'options' => array( - 'anos' => ga__( 'Años', 'Urteak' ), - 'meses' => ga__( 'Meses', 'Hilabeteak' ), - ) ), - 'tamano' => array( 'label' => ga__( 'Tamaño', 'Tamaina' ), 'type' => 'select', 'options' => array( - 'pequeno' => ga__( 'Pequeño', 'Txikia' ), - 'mediano' => ga__( 'Mediano', 'Ertaina' ), - 'grande' => ga__( 'Grande', 'Handia' ), - ) ), - 'raza' => array( 'label' => ga__( 'Raza', 'Arraza' ), 'type' => 'text', 'placeholder' => 'p. ej. Mestizo' ), - 'llegada' => array( 'label' => ga__( 'Fecha de llegada', 'Iritsiera-data' ), 'type' => 'date' ), - 'salud' => array( 'label' => ga__( 'Salud', 'Osasuna' ), 'type' => 'checks', 'options' => array( - 'chip' => ga__( 'Microchip', 'Mikrotxipa' ), - 'vacunado' => ga__( 'Vacunado', 'Txertatuta' ), - 'esterilizado' => ga__( 'Esterilizado', 'Antzututa' ), - 'desparasitado' => ga__( 'Desparasitado', 'Desparasitatuta' ), - ) ), - 'compatible' => array( 'label' => ga__( 'Se lleva bien con', 'Ondo moldatzen da hauekin' ), 'type' => 'checks', 'options' => array( - 'ninos' => ga__( 'Niños', 'Haurrak' ), - 'perros' => ga__( 'Perros', 'Txakurrak' ), - 'gatos' => ga__( 'Gatos', 'Katuak' ), - ) ), - ); -} - -/** Edad legible en el idioma actual: «3 años», «1 mes», «3 urte», «4 hilabete». */ -function ga_age( $post_id ) { - $n = ga_get( $post_id, 'edad' ); - if ( '' === $n || ! is_numeric( $n ) ) { - return $n; // Valores antiguos en texto libre. - } - $n = (float) $n + 0; - $months = 'meses' === ga_get( $post_id, 'edad_unidad' ); - if ( 'eu' === ga_lang() ) { - return $n . ( $months ? ' hilabete' : ' urte' ); - } - if ( $months ) { - return $n . ( 1 == $n ? ' mes' : ' meses' ); - } - return $n . ( 1 == $n ? ' año' : ' años' ); -} - -function ga_get( $post_id, $key ) { - return (string) get_post_meta( $post_id, "_ga_$key", true ); -} - -/** Etiqueta legible de un campo select, o lista de etiquetas de un campo checks. */ -function ga_label( $post_id, $key ) { - $fields = ga_fields(); - $value = ga_get( $post_id, $key ); - if ( '' === $value || ! isset( $fields[ $key ] ) ) { - return ''; - } - $field = $fields[ $key ]; - if ( 'select' === $field['type'] ) { - return $field['options'][ $value ] ?? $value; - } - if ( 'checks' === $field['type'] ) { - $labels = array(); - foreach ( explode( ',', $value ) as $v ) { - if ( isset( $field['options'][ $v ] ) ) { - $labels[] = $field['options'][ $v ]; - } - } - return $labels; - } - if ( 'date' === $field['type'] ) { - return date_i18n( get_option( 'date_format' ), strtotime( $value ) ); - } - return $value; -} - -add_action( 'add_meta_boxes_animal', function () { - add_meta_box( 'ga_ficha', 'Ficha del animal', 'ga_render_metabox', 'animal', 'normal', 'high' ); -} ); - -function ga_render_metabox( $post ) { - wp_nonce_field( 'ga_ficha', 'ga_ficha_nonce' ); - echo '| '; - switch ( $f['type'] ) { - case 'select': - echo ''; - break; - case 'checks': - $current = array_filter( explode( ',', $value ) ); - foreach ( $f['options'] as $v => $l ) { - printf( - '', - esc_attr( $name ), esc_attr( $v ), checked( in_array( $v, $current, true ), true, false ), esc_html( $l ) - ); - } - break; - default: - printf( - '', - esc_attr( $f['type'] ), esc_attr( $name ), esc_attr( $name ), esc_attr( $value ), - 'number' === $f['type'] ? 'small-text' : 'regular-text', - esc_attr( $f['placeholder'] ?? '' ), - 'number' === $f['type'] ? ' min="0" step="1"' : '' - ); - } - echo ' |
La ficha se comparte entre la versión en castellano y en euskera: al guardar una, se copia a la otra. Solo el nombre y la descripción se traducen.
'; - echo 'Consejo: la foto principal aparece en los listados. Añade más fotos en el contenido con el bloque «Galería».
'; -} - -add_action( 'save_post_animal', function ( $post_id ) { - if ( ! isset( $_POST['ga_ficha_nonce'] ) || ! wp_verify_nonce( $_POST['ga_ficha_nonce'], 'ga_ficha' ) ) { - return; - } - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || ! current_user_can( 'edit_post', $post_id ) ) { - return; - } - foreach ( ga_fields() as $key => $f ) { - $raw = $_POST[ "ga_$key" ] ?? ''; - if ( 'checks' === $f['type'] ) { - $raw = array_intersect( (array) $raw, array_keys( $f['options'] ) ); - $value = implode( ',', $raw ); - } elseif ( 'select' === $f['type'] ) { - $value = isset( $f['options'][ $raw ] ) ? $raw : ''; - } else { - $value = sanitize_text_field( wp_unslash( $raw ) ); - } - ga_update_meta_all_languages( $post_id, "_ga_$key", $value ); - } -} ); - -/** Guarda un campo en el animal y en todas sus traducciones. */ -function ga_update_meta_all_languages( $post_id, $meta_key, $value ) { - $ids = array( $post_id ); - if ( function_exists( 'pll_get_post_translations' ) ) { - $ids = array_unique( array_merge( $ids, array_values( pll_get_post_translations( $post_id ) ) ) ); - } - foreach ( $ids as $id ) { - update_post_meta( $id, $meta_key, $value ); - } -} - -/* Columnas en el listado del admin */ -add_filter( 'manage_animal_posts_columns', function ( $cols ) { - $new = array(); - foreach ( $cols as $k => $v ) { - if ( 'title' === $k ) { - $new['ga_foto'] = 'Foto'; - } - $new[ $k ] = $v; - if ( 'title' === $k ) { - $new['ga_estado'] = 'Estado'; - $new['ga_edad'] = 'Edad'; - } - } - return $new; -} ); - -add_action( 'manage_animal_posts_custom_column', function ( $col, $post_id ) { - if ( 'ga_foto' === $col ) { - echo get_the_post_thumbnail( $post_id, array( 60, 60 ) ); - } elseif ( 'ga_estado' === $col ) { - echo esc_html( ga_label( $post_id, 'estado' ) ); - } elseif ( 'ga_edad' === $col ) { - echo esc_html( ga_age( $post_id ) ); - } -}, 10, 2 ); - -/* Título de la pestaña del listado en el idioma actual */ -add_filter( 'document_title_parts', function ( $parts ) { - if ( is_post_type_archive( 'animal' ) ) { - $parts['title'] = ga__( 'Animales en adopción', 'Animaliak adopzioan' ); - } - return $parts; -} ); - -/* ------------------------------------------------------------------------- - * Consultas del listado público /adopta/ - * ---------------------------------------------------------------------- */ - -add_filter( 'query_vars', function ( $vars ) { - return array_merge( $vars, array( 'tamano', 'sexo', 'edad', 'con' ) ); -} ); - -/** Grupos de edad para el filtro del listado. */ -function ga_age_groups() { - return array( - 'joven' => ga__( 'Menos de 1 año', 'Urtebete baino gutxiago' ), - 'adulto' => ga__( 'Adulto', 'Heldua' ), - 'senior' => ga__( 'Mayor (8+)', 'Adinekoa (8+)' ), - ); -} - -/** meta_query para un grupo de edad (la edad se guarda como número + unidad). */ -function ga_age_meta_query( $group ) { - $anos = array( 'key' => '_ga_edad_unidad', 'value' => 'anos' ); - switch ( $group ) { - case 'joven': - return array( - 'relation' => 'OR', - array( 'key' => '_ga_edad_unidad', 'value' => 'meses' ), - array( 'relation' => 'AND', $anos, array( 'key' => '_ga_edad', 'value' => 1, 'compare' => '<', 'type' => 'NUMERIC' ) ), - ); - case 'adulto': - return array( 'relation' => 'AND', $anos, array( 'key' => '_ga_edad', 'value' => array( 1, 7 ), 'compare' => 'BETWEEN', 'type' => 'NUMERIC' ) ); - case 'senior': - return array( 'relation' => 'AND', $anos, array( 'key' => '_ga_edad', 'value' => 8, 'compare' => '>=', 'type' => 'NUMERIC' ) ); - } - return array(); -} - -function ga_not_adopted_meta_query() { - return array( - 'relation' => 'OR', - array( 'key' => '_ga_estado', 'value' => 'adoptado', 'compare' => '!=' ), - array( 'key' => '_ga_estado', 'compare' => 'NOT EXISTS' ), - ); -} - -add_action( 'pre_get_posts', function ( $q ) { - if ( is_admin() || ! $q->is_main_query() || ! ( $q->is_post_type_archive( 'animal' ) || $q->is_tax( 'especie' ) ) ) { - return; - } - $meta = array( ga_not_adopted_meta_query() ); - foreach ( array( 'tamano', 'sexo' ) as $key ) { - $v = sanitize_key( (string) $q->get( $key ) ); - if ( $v && isset( ga_fields()[ $key ]['options'][ $v ] ) ) { - $meta[] = array( 'key' => "_ga_$key", 'value' => $v ); - } - } - $edad = sanitize_key( (string) $q->get( 'edad' ) ); - if ( isset( ga_age_groups()[ $edad ] ) ) { - $meta[] = ga_age_meta_query( $edad ); - } - $con = sanitize_key( (string) $q->get( 'con' ) ); - if ( isset( ga_fields()['compatible']['options'][ $con ] ) ) { - $meta[] = array( 'key' => '_ga_compatible', 'value' => $con, 'compare' => 'LIKE' ); - } - $q->set( 'meta_query', $meta ); - $q->set( 'posts_per_page', 12 ); -} ); - -/** - * Consulta reutilizable de animales (Polylang filtra por el idioma actual). - */ -function ga_query_animals( $args = array() ) { - $args = wp_parse_args( $args, array( - 'numero' => 6, - 'especie' => '', - 'estado' => '', - ) ); - - $query = array( - 'post_type' => 'animal', - 'posts_per_page' => (int) $args['numero'], - 'no_found_rows' => true, - ); - if ( $args['especie'] ) { - $query['tax_query'] = array( array( - 'taxonomy' => 'especie', - 'field' => 'slug', - 'terms' => array_map( 'trim', explode( ',', $args['especie'] ) ), - ) ); - } - if ( $args['estado'] ) { - $query['meta_query'] = array( array( - 'key' => '_ga_estado', - 'value' => array_map( 'trim', explode( ',', $args['estado'] ) ), - 'compare' => 'IN', - ) ); - } else { - $query['meta_query'] = ga_not_adopted_meta_query(); - } - return new WP_Query( $query ); -} - -/* [ga_animales numero="6" especie="perro" estado="urgente" vista="carrusel"] */ -add_shortcode( 'ga_animales', function ( $atts ) { - $atts = shortcode_atts( array( 'numero' => 6, 'especie' => '', 'estado' => '', 'vista' => 'rejilla' ), $atts, 'ga_animales' ); - $q = ga_query_animals( $atts ); - ob_start(); - if ( $q->have_posts() ) { - $carousel = 'carrusel' === $atts['vista']; - if ( $carousel ) { - ga_carousel_open(); - } else { - echo '' . esc_html( ga__( 'Ahora mismo no hay animales en esta sección. ¡Vuelve pronto!', 'Une honetan ez dago animaliarik atal honetan. Itzuli laster!' ) ) . '
'; - } - wp_reset_postdata(); - return ob_get_clean(); -} ); - -/** Apertura y cierre de un carrusel accesible (el tema aporta el CSS y el JS). */ -function ga_carousel_open( $label = '' ) { - printf( - 'La historia se escribe en el editor principal. La «frase corta» (extracto) es opcional.
'; + foreach ( $groups as $title => $group ) { + echo '| ';
+ switch ( $f['type'] ) {
+ case 'select':
+ echo '';
+ break;
+ case 'checkbox':
+ printf( '', esc_attr( $name ), checked( $value, '1', false ) );
+ break;
+ case 'textarea':
+ printf( '', esc_attr( $name ), esc_textarea( $value ) );
+ break;
+ case 'gallery':
+ printf( '', esc_attr( $name ), esc_attr( $value ) );
+ echo ' ';
+ foreach ( array_filter( explode( ',', $value ) ) as $id ) {
+ $thumb = wp_get_attachment_image( (int) $id, array( 80, 80 ) );
+ if ( $thumb ) {
+ printf( '%s', (int) $id, $thumb );
+ }
+ }
+ echo ' ';
+ break;
+ case 'number':
+ printf( '', esc_attr( $name ), esc_attr( $value ) );
+ break;
+ default:
+ printf( '', esc_attr( $f['type'] ), esc_attr( $name ), esc_attr( $value ) );
+ }
+ if ( ! empty( $f['help'] ) ) {
+ echo '' . esc_html( $f['help'] ) . ' '; + } + echo ' |
' . esc_html( ga__( 'Ahora mismo no hay animales en esta sección. ¡Vuelve pronto!', 'Une honetan ez dago animaliarik atal honetan. Itzuli laster!' ) ) . '
'; + } + wp_reset_postdata(); + return ob_get_clean(); +} ); + +/** Apertura y cierre de un carrusel accesible (el tema aporta el CSS y el JS). */ +function ga_carousel_open( $label = '' ) { + printf( + '' . esc_html( $note ) . '
'; + } + return ob_get_clean(); +} ); + +/* [ga_cita] aviso de cita previa */ +add_shortcode( 'ga_cita', function () { + $text = ga_info( 'cita' ); + return $text ? '' . esc_html( $text ) . '
' : ''; +} ); diff --git a/wp-content/mu-plugins/gure-ametsa/i18n.php b/wp-content/mu-plugins/gure-ametsa/i18n.php new file mode 100644 index 0000000..d09f807 --- /dev/null +++ b/wp-content/mu-plugins/gure-ametsa/i18n.php @@ -0,0 +1,118 @@ +ID; + if ( function_exists( 'pll_get_post' ) ) { + $id = pll_get_post( $id, ga_lang() ) ?: $id; + } + return get_permalink( $id ) . $fragment; +} + +/** URL del listado de una especie (slug en castellano: perro, gato) en el idioma actual. */ +function ga_species_url( $slug_es ) { + $term = get_term_by( 'slug', $slug_es, 'especie' ); + if ( $term && function_exists( 'pll_get_term' ) ) { + $translated = pll_get_term( $term->term_id, ga_lang() ); + $term = $translated ? get_term( $translated, 'especie' ) : $term; + } + $url = $term && ! is_wp_error( $term ) ? get_term_link( $term ) : ''; + return is_wp_error( $url ) || ! $url ? get_post_type_archive_link( 'animal' ) : $url; +} + +/* Animales y especies son traducibles; los mensajes no. */ +add_filter( 'pll_get_post_types', function ( $types ) { + $types['animal'] = 'animal'; + unset( $types['ga_mensaje'] ); + return $types; +} ); + +add_filter( 'pll_get_taxonomies', function ( $taxonomies ) { + $taxonomies['especie'] = 'especie'; + return $taxonomies; +} ); + +/** + * Ajuste del personalizador del tema, con valor por defecto si el tema no está activo. + */ +function ga_setting( $section, $field, $default = '' ) { + if ( function_exists( 'ga_opt' ) ) { + $value = ga_opt( $section, $field ); + return null === $value ? $default : $value; + } + return $default; +} + +/* ------------------------------------------------------------------------- + * Datos de la protectora (el tema los sustituye por los del personalizador) + * ---------------------------------------------------------------------- */ + +function ga_info( $key = null ) { + $info = apply_filters( 'ga_info', array( + 'nombre' => 'Bilagun', + 'direccion' => 'Jaizubia, 44 · 20280 Hondarribia (Gipuzkoa)', + 'telefono' => '943 64 52 79', + 'email' => 'hola@gureametsabilagun.org', + 'horario' => ga__( 'Lunes a viernes: 10:00–13:00 y 14:00–19:00', 'Astelehenetik ostiralera: 10:00–13:00 eta 14:00–19:00' ), + 'cita' => ga__( 'Atendemos con cita previa. Escríbenos o llámanos antes de venir.', 'Aurretiko hitzorduarekin artatzen dugu. Idatzi edo deitu iezaguzu etorri aurretik.' ), + 'instagram' => 'https://www.instagram.com/gureametsabilagun/', + 'facebook' => 'https://www.facebook.com/gureametsabilagun/', + 'maps' => 'https://www.google.com/maps/search/?api=1&query=Jaizubia+44+Hondarribia', + ) ); + return $key ? ( $info[ $key ] ?? '' ) : $info; +} + +/** Correo que recibe los formularios: ajuste del panel → variable GA_CONTACT_EMAIL → administrador. */ +function ga_contact_email() { + $email = ga_setting( 'adopcion', 'form_email', '' ); + if ( ! is_email( $email ) ) { + $email = getenv( 'GA_CONTACT_EMAIL' ); + } + return is_email( $email ) ? $email : get_option( 'admin_email' ); +} diff --git a/wp-content/themes/gure-ametsa/404.php b/wp-content/themes/gure-ametsa/404.php index 6b242de..c689d83 100644 --- a/wp-content/themes/gure-ametsa/404.php +++ b/wp-content/themes/gure-ametsa/404.php @@ -3,12 +3,12 @@ get_header(); ?>← name ) : ga__( 'Adopta', 'Adoptatu' ) ); ?>
+:
- - - + $text ) : ?> +- - -
- - - -+ + + + +