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 ''; foreach ( ga_fields() as $key => $f ) { $name = "ga_$key"; $value = ga_get( $post->ID, $key ); if ( 'estado' === $key && '' === $value ) { $value = 'disponible'; } echo ''; } echo ''; 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 '
'; } while ( $q->have_posts() ) { $q->the_post(); ga_animal_card(); } $carousel ? ga_carousel_close() : print( '
' ); } 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( '', esc_attr( ga__( 'Anteriores', 'Aurrekoak' ) ), esc_attr( ga__( 'Siguientes', 'Hurrengoak' ) ) ); } /** Tarjeta de un animal (dentro del loop). El tema puede sobrescribirla con template-parts/animal-card.php. */ function ga_animal_card() { if ( locate_template( 'template-parts/animal-card.php' ) ) { get_template_part( 'template-parts/animal-card' ); return; } printf( '
%s
', esc_url( get_permalink() ), esc_html( get_the_title() ) ); } /* ------------------------------------------------------------------------- * Formulario de contacto / solicitud de adopción [ga_contacto] * ---------------------------------------------------------------------- */ function ga_contact_reasons() { return array( 'adopcion' => ga__( 'Adopción', 'Adopzioa' ), 'acogida' => ga__( 'Casa de acogida', 'Harrera-etxea' ), 'voluntario' => ga__( 'Voluntariado', 'Boluntariotza' ), 'donaciones' => ga__( 'Donaciones', 'Dohaintzak' ), 'hotel' => ga__( 'Hotel para perros y gatos', 'Txakur eta katuentzako hotela' ), 'perdido' => ga__( 'He encontrado / perdido un animal', 'Animalia bat aurkitu / galdu dut' ), 'otro' => ga__( 'Otro', 'Beste bat' ), ); } add_shortcode( 'ga_contacto', function () { $status = isset( $_GET['enviado'] ) ? sanitize_key( $_GET['enviado'] ) : ''; $animal_id = isset( $_GET['adoptar'] ) ? absint( $_GET['adoptar'] ) : 0; $animal = $animal_id && 'animal' === get_post_type( $animal_id ) ? get_the_title( $animal_id ) : ''; $preselect = $animal ? 'adopcion' : ( isset( $_GET['motivo'] ) ? sanitize_key( $_GET['motivo'] ) : '' ); $privacy = ga_page_url( 'politica-de-privacidad' ); ob_start(); if ( 'ok' === $status ) { echo '
' . esc_html( ga__( '¡Eskerrik asko!', 'Eskerrik asko!' ) ) . ' ' . esc_html( ga__( 'Hemos recibido tu mensaje y te responderemos lo antes posible.', 'Zure mezua jaso dugu eta ahalik eta lasterren erantzungo dizugu.' ) ) . '
'; } elseif ( 'error' === $status ) { echo ''; } ?>
sanitize_text_field( wp_unslash( $_POST['nombre'] ?? '' ) ), 'email' => sanitize_email( wp_unslash( $_POST['email'] ?? '' ) ), 'telefono' => sanitize_text_field( wp_unslash( $_POST['telefono'] ?? '' ) ), 'motivo' => $reasons[ $reason ] ?? $reasons['otro'], 'animal' => sanitize_text_field( wp_unslash( $_POST['animal'] ?? '' ) ), 'mensaje' => sanitize_textarea_field( wp_unslash( $_POST['mensaje'] ?? '' ) ), 'idioma' => 'eu' === ( $_POST['idioma'] ?? '' ) ? 'Euskera' : 'Castellano', ); if ( ! $data['nombre'] || ! is_email( $data['email'] ) || ! $data['mensaje'] || empty( $_POST['privacidad'] ) ) { $go( 'error' ); } $subject = sprintf( '[Web] %s – %s', $data['motivo'], $data['nombre'] ); if ( $data['animal'] ) { $subject .= ' (' . $data['animal'] . ')'; } $body = sprintf( "Nombre: %s\nEmail: %s\nTeléfono: %s\nMotivo: %s\nAnimal: %s\nIdioma: %s\n\n%s", $data['nombre'], $data['email'], $data['telefono'] ?: '-', $data['motivo'], $data['animal'] ?: '-', $data['idioma'], $data['mensaje'] ); // Se guarda siempre en el panel, aunque falle el correo. 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' ); } /* ------------------------------------------------------------------------- * APIs: REST (/wp-json/wp/v2/animales) y GraphQL (/graphql) * ---------------------------------------------------------------------- */ /** Ficha de un animal lista para las APIs: valores internos + textos legibles. */ function ga_animal_api_data( $post_id ) { $lang = function_exists( 'pll_get_post_language' ) ? ( pll_get_post_language( $post_id ) ?: 'es' ) : 'es'; $list = fn( $key ) => array_values( array_filter( explode( ',', ga_get( $post_id, $key ) ) ) ); $data = array( 'estado' => ga_get( $post_id, 'estado' ) ?: 'disponible', 'sexo' => ga_get( $post_id, 'sexo' ), 'edad' => '' === ga_get( $post_id, 'edad' ) ? null : (float) ga_get( $post_id, 'edad' ), 'edad_unidad' => ga_get( $post_id, 'edad_unidad' ), 'tamano' => ga_get( $post_id, 'tamano' ), 'raza' => ga_get( $post_id, 'raza' ), 'llegada' => ga_get( $post_id, 'llegada' ), 'salud' => $list( 'salud' ), 'compatible' => $list( 'compatible' ), 'idioma' => $lang, ); // Textos legibles en el idioma del animal. $labels = function () use ( $post_id ) { return array( 'estado' => ga_label( $post_id, 'estado' ) ?: ga__( 'En adopción', 'Adopzioan' ), 'sexo' => ga_label( $post_id, 'sexo' ), 'edad' => ga_age( $post_id ), 'tamano' => ga_label( $post_id, 'tamano' ), 'salud' => ga_label( $post_id, 'salud' ) ?: array(), 'compatible' => ga_label( $post_id, 'compatible' ) ?: array(), ); }; $data['textos'] = ga_with_lang( $lang, $labels ); return $data; } /** Ejecuta $callback como si el idioma actual fuera $lang (para las etiquetas). */ function ga_with_lang( $lang, callable $callback ) { $GLOBALS['ga_forced_lang'] = $lang; try { return $callback(); } finally { unset( $GLOBALS['ga_forced_lang'] ); } } /* REST: campo «ficha» de solo lectura en /wp/v2/animales */ add_action( 'rest_api_init', function () { register_rest_field( 'animal', 'ficha', array( 'get_callback' => fn( $post ) => ga_animal_api_data( $post['id'] ), 'schema' => array( 'description' => 'Ficha del animal (valores internos y textos legibles en su idioma).', 'type' => 'object', 'context' => array( 'view', 'edit' ), 'readonly' => true, 'properties' => array( 'estado' => array( 'type' => 'string', 'enum' => array( 'disponible', 'urgente', 'acogida', 'reservado', 'adoptado' ) ), 'sexo' => array( 'type' => 'string' ), 'edad' => array( 'type' => array( 'number', 'null' ) ), 'edad_unidad' => array( 'type' => 'string', 'enum' => array( '', 'anos', 'meses' ) ), 'tamano' => array( 'type' => 'string' ), 'raza' => array( 'type' => 'string' ), 'llegada' => array( 'type' => 'string', 'format' => 'date' ), 'salud' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ), 'compatible' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ) ), 'idioma' => array( 'type' => 'string' ), 'textos' => array( 'type' => 'object' ), ), ), ) ); } ); /* GraphQL: tipo AnimalFicha y campo «ficha» en Animal */ add_action( 'graphql_register_types', function () { register_graphql_object_type( 'AnimalFichaTextos', array( 'description' => 'Textos legibles de la ficha, en el idioma del animal.', 'fields' => array( 'estado' => array( 'type' => 'String' ), 'sexo' => array( 'type' => 'String' ), 'edad' => array( 'type' => 'String' ), 'tamano' => array( 'type' => 'String' ), 'salud' => array( 'type' => array( 'list_of' => 'String' ) ), 'compatible' => array( 'type' => array( 'list_of' => 'String' ) ), ), ) ); register_graphql_object_type( 'AnimalFicha', array( 'description' => 'Ficha del animal en adopción.', 'fields' => array( 'estado' => array( 'type' => 'String', 'description' => 'disponible, urgente, acogida, reservado o adoptado' ), 'sexo' => array( 'type' => 'String' ), 'edad' => array( 'type' => 'Float' ), 'edadUnidad' => array( 'type' => 'String', 'description' => 'anos o meses' ), 'tamano' => array( 'type' => 'String' ), 'raza' => array( 'type' => 'String' ), 'llegada' => array( 'type' => 'String' ), 'salud' => array( 'type' => array( 'list_of' => 'String' ) ), 'compatible' => array( 'type' => array( 'list_of' => 'String' ) ), 'idioma' => array( 'type' => 'String' ), 'textos' => array( 'type' => 'AnimalFichaTextos' ), ), ) ); register_graphql_field( 'Animal', 'ficha', array( 'type' => 'AnimalFicha', 'resolve' => function ( $post ) { $data = ga_animal_api_data( $post->databaseId ); $data['edadUnidad'] = $data['edad_unidad']; return $data; }, ) ); } ); /* Documentación Swagger (/rest-api/docs/): solo para usuarios conectados, salvo API_DOCS_PUBLIC=true */ add_action( 'template_redirect', function () { if ( 'docs' === get_query_var( 'swagger_api' ) && 'true' !== getenv( 'API_DOCS_PUBLIC' ) && ! is_user_logged_in() ) { auth_redirect(); } }, 1 );