Cuestionario de adopción online y hueco para el aviso de nuevos animales

- [ga_cuestionario]: preguntas editables en ES/EU (Personalizar), borrador guardado en el
  navegador, envío a Mensajes y por correo. Páginas «Cuestionario de adopción /
  Adopzio-galdetegia» fuera del menú y con noindex; admite ?adoptar=ID.
- Pie: formulario de suscripción de MailPoet cuando se configure su shortcode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 10:32:29 +02:00
parent 1ad21c1b08
commit d7a17a2aca
9 changed files with 188 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<!-- wp:paragraph -->
<p>Gracias por querer conocernos. Estas preguntas nos ayudan a saber cómo es tu día a día y a encontrar juntos al compañero que mejor encaje contigo. No hay respuestas buenas o malas: cuéntanoslo con naturalidad.</p>
<!-- /wp:paragraph -->
<!-- wp:shortcode -->
[ga_cuestionario]
<!-- /wp:shortcode -->

View File

@@ -0,0 +1,7 @@
<!-- wp:paragraph -->
<p>Eskerrik asko gu ezagutu nahi izateagatik. Galdera hauek zure eguneroko bizitza nolakoa den jakiten eta zurekin hobekien bat datorren laguna elkarrekin aurkitzen laguntzen digute. Ez dago erantzun onik edo txarrik: kontaiguzu naturaltasunez.</p>
<!-- /wp:paragraph -->
<!-- wp:shortcode -->
[ga_cuestionario]
<!-- /wp:shortcode -->

View File

@@ -120,6 +120,7 @@ $pages = array(
'quienes-somos' => array( 'Quiénes somos', 'nor-gara', 'Nor gara' ), 'quienes-somos' => array( 'Quiénes somos', 'nor-gara', 'Nor gara' ),
'contacto' => array( 'Contacto', 'harremanetarako', 'Harremanetarako' ), 'contacto' => array( 'Contacto', 'harremanetarako', 'Harremanetarako' ),
'preguntas-frecuentes' => array( 'Preguntas frecuentes', 'ohiko-galderak', 'Ohiko galderak' ), 'preguntas-frecuentes' => array( 'Preguntas frecuentes', 'ohiko-galderak', 'Ohiko galderak' ),
'cuestionario-adopcion' => array( 'Cuestionario de adopción', 'adopzio-galdetegia', 'Adopzio-galdetegia' ),
'politica-de-privacidad' => array( 'Política de privacidad', 'pribatutasun-politika', 'Pribatutasun-politika' ), 'politica-de-privacidad' => array( 'Política de privacidad', 'pribatutasun-politika', 'Pribatutasun-politika' ),
'aviso-legal' => array( 'Aviso legal', 'lege-oharra', 'Lege-oharra' ), 'aviso-legal' => array( 'Aviso legal', 'lege-oharra', 'Lege-oharra' ),
); );

View File

@@ -16,3 +16,4 @@ require_once __DIR__ . '/gure-ametsa/admin.php';
require_once __DIR__ . '/gure-ametsa/share.php'; require_once __DIR__ . '/gure-ametsa/share.php';
require_once __DIR__ . '/gure-ametsa/seo.php'; require_once __DIR__ . '/gure-ametsa/seo.php';
require_once __DIR__ . '/gure-ametsa/stories.php'; require_once __DIR__ . '/gure-ametsa/stories.php';
require_once __DIR__ . '/gure-ametsa/questionnaire.php';

View File

@@ -0,0 +1,124 @@
<?php
/**
* Cuestionario de adopción online [ga_cuestionario]. Las preguntas se editan en
* Personalizar → Adopción y colabora → Cuestionario. La página no se indexa.
*/
defined( 'ABSPATH' ) || exit;
function ga_questionnaire_questions() {
return array_values( array_filter( array_map( 'trim', explode( "\n", (string) ga_setting( 'cuestionario', 'questions', '' ) ) ) ) );
}
add_shortcode( 'ga_cuestionario', function () {
$status = sanitize_key( $_GET['cuestionario'] ?? '' );
$animal_id = absint( $_GET['adoptar'] ?? 0 );
$animal = $animal_id && 'animal' === get_post_type( $animal_id ) ? get_the_title( $animal_id ) : '';
$questions = ga_questionnaire_questions();
$privacy = ga_page_url( 'politica-de-privacidad' );
ob_start();
if ( 'ok' === $status ) {
echo '<div class="ga-notice ga-notice--ok" role="status" data-ga-clear-draft>' . esc_html( ga_setting( 'cuestionario', 'confirm', '' ) ) . '</div>';
return ob_get_clean();
}
if ( 'error' === $status ) {
echo '<div class="ga-notice ga-notice--error" role="alert">' . esc_html( ga__( 'Falta algún dato obligatorio. Revisa el formulario: lo que habías escrito se ha guardado.', 'Derrigorrezko daturen bat falta da. Berrikusi formularioa: idatzitakoa gorde da.' ) ) . '</div>';
}
?>
<form class="ga-form ga-questionnaire" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" data-ga-draft="ga-cuestionario-<?php echo esc_attr( ga_lang() ); ?>">
<input type="hidden" name="action" value="ga_cuestionario">
<input type="hidden" name="idioma" value="<?php echo esc_attr( ga_lang() ); ?>">
<input type="hidden" name="redirect" value="<?php echo esc_url( get_permalink() ); ?>">
<?php wp_nonce_field( 'ga_cuestionario', 'ga_nonce' ); ?>
<div class="ga-hp" aria-hidden="true"><label>No rellenar <input type="text" name="web" tabindex="-1" autocomplete="off"></label></div>
<fieldset>
<legend><?php ga_e( 'Tus datos', 'Zure datuak' ); ?></legend>
<div class="ga-form__row">
<label><?php ga_e( 'Nombre y apellidos', 'Izen-abizenak' ); ?> *<input type="text" name="nombre" required autocomplete="name"></label>
<label><?php ga_e( 'Correo electrónico', 'Posta elektronikoa' ); ?> *<input type="email" name="email" required autocomplete="email"></label>
</div>
<div class="ga-form__row">
<label><?php ga_e( 'Teléfono', 'Telefonoa' ); ?> *<input type="tel" name="telefono" required autocomplete="tel"></label>
<label><?php ga_e( 'Localidad', 'Herria' ); ?><input type="text" name="localidad" autocomplete="address-level2"></label>
</div>
<label><?php ga_e( 'Animal por el que te interesas', 'Interesatzen zaizun animalia' ); ?><input type="text" name="animal" value="<?php echo esc_attr( $animal ); ?>"></label>
</fieldset>
<fieldset>
<legend><?php ga_e( 'Sobre ti y tu hogar', 'Zuri eta zure etxeari buruz' ); ?></legend>
<?php foreach ( $questions as $i => $question ) : ?>
<label><?php echo esc_html( $question ); ?> *
<textarea name="respuestas[<?php echo (int) $i; ?>]" rows="3" required></textarea>
</label>
<?php endforeach; ?>
</fieldset>
<label class="ga-form__check">
<input type="checkbox" name="privacidad" value="1" required>
<span><?php printf( wp_kses( ga__( 'He leído y acepto la <a href="%s" target="_blank">política de privacidad</a>. *', '<a href="%s" target="_blank">Pribatutasun-politika</a> irakurri eta onartzen dut. *' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ), esc_url( $privacy ) ); ?></span>
</label>
<p class="ga-form__hint"><?php ga_e( 'Lo que escribes se guarda en este navegador hasta que lo envíes.', 'Idazten duzuna nabigatzaile honetan gordetzen da bidali arte.' ); ?></p>
<button type="submit" class="ga-btn"><?php ga_e( 'Enviar cuestionario', 'Galdetegia bidali' ); ?></button>
</form>
<?php
return ob_get_clean();
} );
add_action( 'admin_post_nopriv_ga_cuestionario', 'ga_handle_questionnaire' );
add_action( 'admin_post_ga_cuestionario', 'ga_handle_questionnaire' );
function ga_handle_questionnaire() {
$redirect = wp_validate_redirect( esc_url_raw( wp_unslash( $_POST['redirect'] ?? '' ) ), home_url( '/' ) );
$go = function ( $status ) use ( $redirect ) {
wp_safe_redirect( add_query_arg( 'cuestionario', $status, $redirect ) );
exit;
};
if ( ! isset( $_POST['ga_nonce'] ) || ! wp_verify_nonce( $_POST['ga_nonce'], 'ga_cuestionario' ) ) {
$go( 'error' );
}
if ( ! empty( $_POST['web'] ) ) {
$go( 'ok' );
}
$lang = 'eu' === ( $_POST['idioma'] ?? '' ) ? 'eu' : 'es';
$questions = ga_with_lang( $lang, 'ga_questionnaire_questions' );
$answers = array_map( fn( $a ) => sanitize_textarea_field( wp_unslash( $a ) ), (array) ( $_POST['respuestas'] ?? array() ) );
$data = array(
'nombre' => sanitize_text_field( wp_unslash( $_POST['nombre'] ?? '' ) ),
'email' => sanitize_email( wp_unslash( $_POST['email'] ?? '' ) ),
'telefono' => sanitize_text_field( wp_unslash( $_POST['telefono'] ?? '' ) ),
'localidad' => sanitize_text_field( wp_unslash( $_POST['localidad'] ?? '' ) ),
'animal' => sanitize_text_field( wp_unslash( $_POST['animal'] ?? '' ) ),
);
if ( ! $data['nombre'] || ! is_email( $data['email'] ) || ! $data['telefono'] || empty( $_POST['privacidad'] ) ) {
$go( 'error' );
}
foreach ( array_keys( $questions ) as $i ) {
if ( '' === trim( $answers[ $i ] ?? '' ) ) {
$go( 'error' );
}
}
$subject = sprintf( '[Web] Cuestionario de adopción – %s%s', $data['nombre'], $data['animal'] ? ' (' . $data['animal'] . ')' : '' );
$body = sprintf(
"Nombre: %s\nEmail: %s\nTeléfono: %s\nLocalidad: %s\nAnimal: %s\nIdioma: %s\n",
$data['nombre'], $data['email'], $data['telefono'], $data['localidad'] ?: '-', $data['animal'] ?: '-', 'eu' === $lang ? 'Euskera' : 'Castellano'
);
foreach ( $questions as $i => $question ) {
$body .= "\n" . $question . "\n" . ( $answers[ $i ] ?? '' ) . "\n";
}
wp_insert_post( array( 'post_type' => 'ga_mensaje', 'post_status' => 'private', 'post_title' => $subject, 'post_content' => $body ) );
wp_mail( ga_contact_email(), $subject, $body, array( 'Reply-To: ' . $data['nombre'] . ' <' . $data['email'] . '>' ) );
$go( 'ok' );
}
/* La página del cuestionario no aparece en buscadores (el enlace lo envía el equipo). */
add_filter( 'wp_robots', function ( $robots ) {
if ( is_page( array( 'cuestionario-adopcion', 'adopzio-galdetegia' ) ) ) {
$robots['noindex'] = true;
$robots['nofollow'] = true;
}
return $robots;
} );

View File

@@ -92,3 +92,25 @@
select.addEventListener( 'change', function () { field.hidden = select.value !== 'visita'; } ); select.addEventListener( 'change', function () { field.hidden = select.value !== 'visita'; } );
} ); } );
} )(); } )();
// Cuestionario: guarda el borrador en este navegador hasta que se envía.
( function () {
var done = document.querySelector( '[data-ga-clear-draft]' );
try {
if ( done ) { Object.keys( localStorage ).filter( function ( k ) { return k.indexOf( 'ga-cuestionario-' ) === 0; } ).forEach( function ( k ) { localStorage.removeItem( k ); } ); }
} catch ( e ) {}
document.querySelectorAll( 'form[data-ga-draft]' ).forEach( function ( form ) {
var key = form.dataset.gaDraft, saved = {};
try { saved = JSON.parse( localStorage.getItem( key ) || '{}' ); } catch ( e ) {}
Array.prototype.forEach.call( form.elements, function ( el ) {
if ( el.name && el.type !== 'hidden' && el.type !== 'checkbox' && saved[ el.name ] && ! el.value ) { el.value = saved[ el.name ]; }
} );
form.addEventListener( 'input', function () {
var data = {};
Array.prototype.forEach.call( form.elements, function ( el ) {
if ( el.name && el.type !== 'hidden' && el.type !== 'checkbox' && el.name !== 'web' ) { data[ el.name ] = el.value; }
} );
try { localStorage.setItem( key, JSON.stringify( data ) ); } catch ( e ) {}
} );
} );
} )();

View File

@@ -61,6 +61,13 @@ $columns = array(
</div> </div>
</div> </div>
<?php $newsletter = trim( (string) ga_opt( 'footer', 'newsletter' ) ); ?>
<?php if ( $newsletter && preg_match( '/^\[mailpoet_form[^\]]*\]$/', $newsletter ) && shortcode_exists( 'mailpoet_form' ) ) : ?>
<div class="ga-footer__newsletter">
<h2><?php ga_opt_e( 'footer', 'newsletter_title' ); ?></h2>
<?php echo do_shortcode( $newsletter ); ?>
</div>
<?php endif; ?>
<div class="ga-footer__bottom"> <div class="ga-footer__bottom">
<span>© <?php echo esc_html( wp_date( 'Y' ) ); ?> <?php ga_opt_e( 'footer', 'copyright' ); ?></span> <span>© <?php echo esc_html( wp_date( 'Y' ) ); ?> <?php ga_opt_e( 'footer', 'copyright' ); ?></span>
<?php <?php

View File

@@ -170,6 +170,8 @@ function ga_customizer_registry() {
'Bilagun es la protectora de Jaizubia, en Hondarribia. Cuidamos de los perros y gatos que llegan a nosotras y les buscamos una segunda oportunidad.', 'Bilagun es la protectora de Jaizubia, en Hondarribia. Cuidamos de los perros y gatos que llegan a nosotras y les buscamos una segunda oportunidad.',
'Bilagun Jaizubiko babeslekua da, Hondarribian. Guregana iristen diren txakur eta katuak zaintzen ditugu eta bigarren aukera bat bilatzen diegu.', 'textarea' ), 'Bilagun Jaizubiko babeslekua da, Hondarribian. Guregana iristen diren txakur eta katuak zaintzen ditugu eta bigarren aukera bat bilatzen diegu.', 'textarea' ),
'copyright' => array( 'type' => 'text', 'label' => 'Texto de copyright', 'default' => 'Gure Ametsa Bi Lagun' ), 'copyright' => array( 'type' => 'text', 'label' => 'Texto de copyright', 'default' => 'Gure Ametsa Bi Lagun' ),
'newsletter' => array( 'type' => 'text', 'label' => 'Suscripción «Nuevos animales» (shortcode de MailPoet, p. ej. [mailpoet_form id="1"])', 'default' => '', 'description' => 'Vacío = no se muestra. Ver README: cómo crear el aviso automático en MailPoet.' ),
'newsletter_title' => $t( 'Suscripción · título', 'Te avisamos cuando lleguen nuevos animales', 'Animalia berriak iristen direnean abisatuko dizugu' ),
), ),
), ),
@@ -241,6 +243,17 @@ function ga_customizer_registry() {
'retention_months' => array( 'type' => 'number', 'label' => 'Borrar los mensajes del formulario pasados (meses, 0 = nunca)', 'default' => 12, 'min' => 0, 'max' => 120, 'description' => 'Protección de datos: no guardar datos personales más tiempo del necesario.' ), 'retention_months' => array( 'type' => 'number', 'label' => 'Borrar los mensajes del formulario pasados (meses, 0 = nunca)', 'default' => 12, 'min' => 0, 'max' => 120, 'description' => 'Protección de datos: no guardar datos personales más tiempo del necesario.' ),
), ),
), ),
'cuestionario' => array(
'panel' => 'ga_adopt',
'title' => 'Cuestionario de adopción',
'description' => 'Página «Cuestionario de adopción» (no aparece en el menú ni en Google). Enviad su enlace tras el primer contacto; añadiendo ?adoptar=ID del animal aparece ya rellenado.',
'fields' => array(
'questions' => $t( 'Preguntas (una por línea)',
"¿Por qué quieres adoptar?\n¿Cómo es tu vivienda? (piso o casa, si tiene jardín o terraza, si es de alquiler)\n¿Quién vive contigo? ¿Hay niños? ¿Estáis todos de acuerdo con la adopción?\n¿Tienes o has tenido otros animales? Cuéntanos cómo son.\n¿Cuántas horas al día pasaría solo en casa?\n¿Qué harías con él en vacaciones o si te mudaras?\n¿Qué esperas de tu nuevo compañero?",
"Zergatik adoptatu nahi duzu?\nNolakoa da zure etxebizitza? (pisua edo etxea, lorategia edo terraza duen, alokairuan dagoen)\nNor bizi da zurekin? Haurrik ba al dago? Denak ados zaudete adopzioarekin?\nBeste animaliarik baduzu edo izan duzu? Kontaiguzu nolakoak diren.\nZenbat ordu egongo litzateke bakarrik etxean egunean?\nZer egingo zenuke harekin oporretan edo etxez aldatuko bazina?\nZer espero duzu zure lagun berriarengandik?", 'textarea' ),
'confirm' => $t( 'Confirmación tras enviarlo', '¡Gracias! Hemos recibido tu cuestionario. El equipo lo valorará y te llamaremos para quedar, siempre con cita previa.', 'Eskerrik asko! Zure galdetegia jaso dugu. Taldeak baloratuko du eta deituko dizugu geratzeko, beti aurretiko hitzorduarekin.', 'textarea' ),
),
),
'material' => array( 'material' => array(
'panel' => 'ga_adopt', 'panel' => 'ga_adopt',
'title' => 'Ayuda material', 'title' => 'Ayuda material',

View File

@@ -619,6 +619,12 @@ body { overflow-x: clip; }
.ga-needs-note { font-weight: 600; color: var(--ga-green-dark); } .ga-needs-note { font-weight: 600; color: var(--ga-green-dark); }
.ga-form__animal { margin: 0; font-weight: 700; } .ga-form__animal { margin: 0; font-weight: 700; }
.ga-footer__cita { color: #fff; font-weight: 600; } .ga-footer__cita { color: #fff; font-weight: 600; }
.ga-footer__newsletter { margin-top: 44px; padding: 24px 28px; border-radius: var(--ga-radius); background: rgba(255, 255, 255, .06); }
.ga-footer__newsletter h2 { margin-bottom: .8em; }
.ga-questionnaire fieldset { border: 1px solid var(--ga-line); border-radius: var(--ga-radius); padding: 18px 20px 22px; margin: 0; display: grid; gap: 16px; }
.ga-questionnaire legend { padding: 0 8px; font: 800 1.1rem var(--ga-serif); color: var(--ga-green-dark); }
.ga-questionnaire label { text-transform: none; letter-spacing: 0; font-size: .98rem; }
.ga-form__hint { margin: 0; font-size: .88rem; color: var(--ga-muted); }
/* ========================================================================= /* =========================================================================
Formularios Formularios