- Tema: redes, teléfono, correo, ubicación, reloj, flecha, check y menú pasan a Doodle Icons (Khushmeen Sidhu, CC0), en assets/icons/ y leídos por ga_icon(); la huella y el logotipo no cambian. Sin máscara de recorte, en currentColor y a 20 px. Se «menean» al pasar el ratón. - design/doodle-icons/: los 451 SVG originales, catálogo con buscador, script to-theme.py para añadir iconos al tema y README con origen y licencia. Fuera de la imagen Docker (.dockerignore). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
309 lines
12 KiB
PHP
309 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* Tema Gure Ametsa.
|
|
*
|
|
* - inc/customizer.php Opciones de Apariencia → Personalizar (colores, tipografía, textos…).
|
|
* - inc/dynamic-css.php CSS generado a partir de esas opciones.
|
|
* - inc/patterns.php Patrones y estilos de bloque para el editor.
|
|
*/
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
define( 'GA_THEME_VERSION', '2.3.0' );
|
|
|
|
require_once __DIR__ . '/inc/customizer.php';
|
|
require_once __DIR__ . '/inc/dynamic-css.php';
|
|
require_once __DIR__ . '/inc/patterns.php';
|
|
|
|
add_action( 'after_setup_theme', function () {
|
|
add_theme_support( 'title-tag' );
|
|
add_theme_support( 'post-thumbnails' );
|
|
add_theme_support( 'custom-logo', array( 'height' => 120, 'width' => 120, 'flex-width' => true, 'flex-height' => true ) );
|
|
add_theme_support( 'html5', array( 'search-form', 'gallery', 'caption', 'style', 'script' ) );
|
|
add_theme_support( 'align-wide' );
|
|
add_theme_support( 'responsive-embeds' );
|
|
add_theme_support( 'editor-styles' );
|
|
add_theme_support( 'wp-block-styles' );
|
|
add_theme_support( 'customize-selective-refresh-widgets' );
|
|
add_editor_style( 'style.css' );
|
|
|
|
add_image_size( 'ga-card', 640, 544, true );
|
|
add_image_size( 'ga-square', 1000, 1000, true );
|
|
|
|
register_nav_menus( array(
|
|
'primary' => 'Menú principal',
|
|
'footer' => 'Menú legal (pie)',
|
|
) );
|
|
} );
|
|
|
|
/* Menú principal: en los desplegables, la descripción del elemento (Menús → Opciones de pantalla → Descripción) va bajo el título. */
|
|
add_filter( 'nav_menu_item_title', function ( $title, $item, $args, $depth ) {
|
|
if ( $depth > 0 && 'primary' === ( $args->theme_location ?? '' ) && trim( (string) $item->description ) ) {
|
|
$title .= '<span class="ga-nav__desc">' . esc_html( $item->description ) . '</span>';
|
|
}
|
|
return $title;
|
|
}, 10, 4 );
|
|
|
|
add_action( 'wp_enqueue_scripts', function () {
|
|
wp_enqueue_style( 'gure-ametsa', get_stylesheet_uri(), array(), GA_THEME_VERSION );
|
|
wp_enqueue_script( 'gure-ametsa', get_theme_file_uri( 'assets/js/main.js' ), array(), GA_THEME_VERSION, array( 'strategy' => 'defer', 'in_footer' => true ) );
|
|
} );
|
|
|
|
add_action( 'wp_head', function () {
|
|
echo '<meta name="theme-color" content="' . esc_attr( ga_color( 'primary' ) ) . '">' . "\n";
|
|
if ( ! has_site_icon() ) {
|
|
echo '<link rel="icon" href="' . esc_url( get_theme_file_uri( 'assets/img/favicon.svg' ) ) . '" type="image/svg+xml">' . "\n";
|
|
}
|
|
}, 1 );
|
|
|
|
/** Portada en el idioma actual. */
|
|
function ga_home_url() {
|
|
return function_exists( 'pll_home_url' ) ? pll_home_url() : home_url( '/' );
|
|
}
|
|
|
|
/* ---------- Selector de idioma ---------- */
|
|
function ga_language_switcher( $class = 'ga-lang' ) {
|
|
if ( ! function_exists( 'pll_the_languages' ) || ! ga_opt( 'header', 'switcher' ) ) {
|
|
return;
|
|
}
|
|
$langs = pll_the_languages( array( 'raw' => 1, 'hide_if_empty' => 0, 'hide_if_no_translation' => 0 ) );
|
|
if ( ! $langs ) {
|
|
return;
|
|
}
|
|
echo '<ul class="' . esc_attr( $class ) . '" aria-label="' . esc_attr( ga__( 'Idioma', 'Hizkuntza' ) ) . '">';
|
|
foreach ( $langs as $lang ) {
|
|
printf(
|
|
'<li><a href="%s" hreflang="%s" lang="%s"%s title="%s">%s</a></li>',
|
|
esc_url( $lang['url'] ),
|
|
esc_attr( $lang['slug'] ),
|
|
esc_attr( $lang['slug'] ),
|
|
$lang['current_lang'] ? ' aria-current="true" class="is-current"' : '',
|
|
esc_attr( $lang['name'] ),
|
|
esc_html( strtoupper( $lang['slug'] ) )
|
|
);
|
|
}
|
|
echo '</ul>';
|
|
}
|
|
|
|
/* ---------- Iconos SVG ---------- */
|
|
function ga_icon( $name ) {
|
|
$icons = array(
|
|
'paw' => '<svg viewBox="0 0 64 64" fill="currentColor" aria-hidden="true"><ellipse cx="17" cy="24" rx="6.5" ry="8.5" transform="rotate(-18 17 24)"/><ellipse cx="47" cy="24" rx="6.5" ry="8.5" transform="rotate(18 47 24)"/><ellipse cx="26" cy="12" rx="6" ry="8"/><ellipse cx="38" cy="12" rx="6" ry="8"/><path d="M32 30c-9 0-18 11-18 19 0 6 5 8 9 7 4-1 6-3 9-3s5 2 9 3c4 1 9-1 9-7 0-8-9-19-18-19z"/></svg>',
|
|
'mark' => '<svg viewBox="0 0 64 64" aria-hidden="true"><circle cx="32" cy="32" r="32" style="fill:var(--ga-green)"/><g style="fill:var(--ga-cream)"><ellipse cx="21" cy="28" rx="4" ry="5.2" transform="rotate(-18 21 28)"/><ellipse cx="27" cy="20.5" rx="3.6" ry="4.8"/><ellipse cx="35" cy="20.5" rx="3.6" ry="4.8"/><ellipse cx="41" cy="28" rx="4" ry="5.2" transform="rotate(18 41 28)"/></g><path style="fill:var(--ga-red)" d="M31 48.5s-12-7.2-12-14.6c0-3.6 2.8-6.1 6-6.1 2.6 0 4.6 1.5 6 3.6 1.4-2.1 3.4-3.6 6-3.6 3.2 0 6 2.5 6 6.1 0 7.4-12 14.6-12 14.6z"/></svg>',
|
|
);
|
|
if ( isset( $icons[ $name ] ) ) {
|
|
return $icons[ $name ];
|
|
}
|
|
// El resto son Doodle Icons (Khushmeen Sidhu, CC0), dibujados a mano, en assets/icons/.
|
|
static $cache = array();
|
|
if ( ! isset( $cache[ $name ] ) ) {
|
|
$file = get_theme_file_path( "assets/icons/$name.svg" );
|
|
$cache[ $name ] = preg_match( '/^[a-z0-9-]+$/', $name ) && is_readable( $file ) ? trim( (string) file_get_contents( $file ) ) : '';
|
|
}
|
|
return $cache[ $name ];
|
|
}
|
|
|
|
/** Enlaces a redes sociales configuradas en el personalizador. */
|
|
function ga_social_links( $with_labels = false ) {
|
|
$networks = array(
|
|
'instagram' => 'Instagram',
|
|
'facebook' => 'Facebook',
|
|
'tiktok' => 'TikTok',
|
|
'youtube' => 'YouTube',
|
|
'whatsapp' => 'WhatsApp',
|
|
);
|
|
$out = '';
|
|
foreach ( $networks as $key => $label ) {
|
|
$value = ga_info( $key );
|
|
if ( ! $value ) {
|
|
continue;
|
|
}
|
|
$href = 'whatsapp' === $key ? 'https://wa.me/' . preg_replace( '/\D/', '', $value ) : $value;
|
|
$out .= sprintf(
|
|
'<a href="%s" target="_blank" rel="noopener" aria-label="%s">%s%s</a>',
|
|
esc_url( $href ),
|
|
esc_attr( $label ),
|
|
ga_icon( $key ),
|
|
$with_labels ? ' ' . esc_html( $label ) : ''
|
|
);
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
function ga_tel_link() {
|
|
return 'tel:+34' . preg_replace( '/\D/', '', ga_info( 'telefono' ) );
|
|
}
|
|
|
|
/** SVG del logo (assets/img/logo.svg o logo-mark.svg), en línea para poder recolorearlo con CSS. */
|
|
function ga_logo_svg( $variant = 'full' ) {
|
|
static $cache = array();
|
|
if ( ! isset( $cache[ $variant ] ) ) {
|
|
$file = get_theme_file_path( 'assets/img/' . ( 'mark' === $variant ? 'logo-mark.svg' : 'logo.svg' ) );
|
|
$cache[ $variant ] = is_readable( $file ) ? trim( file_get_contents( $file ) ) : '';
|
|
}
|
|
return $cache[ $variant ];
|
|
}
|
|
|
|
/**
|
|
* Marca del sitio.
|
|
*
|
|
* @param string $context 'header' o 'footer'.
|
|
*/
|
|
function ga_brand( $context = 'header' ) {
|
|
if ( has_custom_logo() ) {
|
|
the_custom_logo();
|
|
return;
|
|
}
|
|
$style = 'footer' === $context ? 'full' : ga_opt( 'header', 'logo_style' );
|
|
$name = sprintf(
|
|
'<span class="ga-brand__name"><b>%s</b><b>%s</b><small>%s</small></span>',
|
|
esc_html( ga_opt( 'header', 'brand_line1' ) ),
|
|
esc_html( ga_opt( 'header', 'brand_line2' ) ),
|
|
esc_html( ga_opt( 'header', 'brand_line3' ) )
|
|
);
|
|
$inner = match ( $style ) {
|
|
'full' => '<span class="ga-brand__logo">' . ga_logo_svg( 'full' ) . '</span>',
|
|
'text' => $name,
|
|
default => '<span class="ga-brand__mark">' . ga_logo_svg( 'mark' ) . '</span>' . $name,
|
|
};
|
|
printf(
|
|
'<a class="ga-brand ga-brand--%s" href="%s" rel="home" aria-label="%s">%s</a>',
|
|
esc_attr( $style ),
|
|
esc_url( ga_home_url() ),
|
|
esc_attr( get_bloginfo( 'name' ) ),
|
|
$inner // SVG estático del tema y textos escapados.
|
|
);
|
|
}
|
|
|
|
/* ---------- Ayudantes de animales ---------- */
|
|
/** Distintivo de estado: solo se muestra «En proceso» o «Adoptado» (los disponibles no llevan etiqueta). */
|
|
function ga_status_badge( $post_id = null ) {
|
|
$post_id = $post_id ?: get_the_ID();
|
|
$estado = ga_status( $post_id );
|
|
if ( 'disponible' === $estado ) {
|
|
return;
|
|
}
|
|
printf( '<span class="ga-status ga-status--%s">%s</span>', esc_attr( $estado ), esc_html( ga_label( $post_id, 'estado' ) ) );
|
|
}
|
|
|
|
/** Foto principal o, si no hay, la silueta del logo. */
|
|
function ga_animal_photo( $size = 'ga-card', $post_id = null ) {
|
|
$post_id = $post_id ?: get_the_ID();
|
|
if ( has_post_thumbnail( $post_id ) ) {
|
|
echo get_the_post_thumbnail( $post_id, $size, array( 'loading' => 'lazy' ) );
|
|
} else {
|
|
echo '<div class="ga-card__placeholder">' . ga_placeholder_svg() . '</div>';
|
|
}
|
|
}
|
|
|
|
/** Silueta del logo para huecos sin foto. */
|
|
function ga_placeholder_svg() {
|
|
return ga_logo_svg( 'mark' ) ?: ga_icon( 'paw' );
|
|
}
|
|
|
|
/** Texto del botón «Quiero conocerlo / conocerla» según el sexo. */
|
|
function ga_meet_label( $post_id = null ) {
|
|
$post_id = $post_id ?: get_the_ID();
|
|
return 'hembra' === ga_get( $post_id, 'sexo' ) ? ga_opt( 'adopcion', 'btn_f' ) : ga_opt( 'adopcion', 'btn_m' );
|
|
}
|
|
|
|
/** Enlaces para compartir una ficha. */
|
|
function ga_share_links( $post_id = null ) {
|
|
$post_id = $post_id ?: get_the_ID();
|
|
$url = get_permalink( $post_id );
|
|
$text = get_the_title( $post_id ) . ' — ' . ga__( 'busca familia en Bilagun', 'familia bila Bilagunen' );
|
|
printf(
|
|
'<div class="ga-share"><span>%s</span><a class="ga-share__btn" href="%s" target="_blank" rel="noopener">WhatsApp</a><a class="ga-share__btn" href="%s" target="_blank" rel="noopener">Facebook</a><button type="button" class="ga-share__btn" data-copy="%s" data-done="%s">%s</button></div>',
|
|
esc_html( ga__( 'Comparte su historia:', 'Partekatu haren istorioa:' ) ),
|
|
esc_url( 'https://wa.me/?text=' . rawurlencode( $text . ' ' . $url ) ),
|
|
esc_url( 'https://www.facebook.com/sharer/sharer.php?u=' . rawurlencode( $url ) ),
|
|
esc_attr( $url ),
|
|
esc_attr( ga__( '¡Copiado!', 'Kopiatuta!' ) ),
|
|
esc_html( ga__( 'Copiar enlace', 'Kopiatu esteka' ) )
|
|
);
|
|
}
|
|
|
|
/** Vídeo de la ficha: oEmbed (YouTube, Vimeo…) o archivo de vídeo. */
|
|
function ga_video_html( $url ) {
|
|
if ( ! $url ) {
|
|
return '';
|
|
}
|
|
if ( preg_match( '/\.(mp4|webm|mov)(\?.*)?$/i', $url ) ) {
|
|
return '<video controls preload="metadata" playsinline src="' . esc_url( $url ) . '"></video>';
|
|
}
|
|
$embed = wp_oembed_get( $url, array( 'width' => 900 ) );
|
|
return $embed ?: '<a href="' . esc_url( $url ) . '" target="_blank" rel="noopener">' . esc_html( ga__( 'Ver vídeo', 'Ikusi bideoa' ) ) . '</a>';
|
|
}
|
|
|
|
function ga_species( $post_id = null ) {
|
|
$terms = get_the_terms( $post_id ?: get_the_ID(), 'especie' );
|
|
return $terms && ! is_wp_error( $terms ) ? $terms[0]->name : '';
|
|
}
|
|
|
|
function ga_plural( $name ) {
|
|
if ( 'eu' === ga_lang() ) {
|
|
return preg_match( '/k$/i', $name ) ? $name : $name . 'k'; // Txakurra → Txakurrak, Katua → Katuak.
|
|
}
|
|
return preg_match( '/s$/i', $name ) ? $name : $name . 's';
|
|
}
|
|
|
|
/** URL de la página de contacto con el animal preseleccionado. */
|
|
function ga_adopt_url( $post_id = null ) {
|
|
return add_query_arg( 'adoptar', $post_id ?: get_the_ID(), ga_page_url( 'contacto' ) ) . '#formulario';
|
|
}
|
|
|
|
/** Escapa un texto y convierte *entre asteriscos* en palabras resaltadas. */
|
|
function ga_highlight( $text ) {
|
|
return preg_replace( '/\*(.+?)\*/u', '<span class="ga-hl">$1</span>', esc_html( $text ) );
|
|
}
|
|
|
|
/**
|
|
* Encabezado de sección: rayita + antetítulo + título + texto, leídos del personalizador.
|
|
*
|
|
* @param string $section Sección del registro.
|
|
* @param array $args 'center' => bool, 'h' => nivel, 'extra' => HTML a la derecha (p. ej. un botón).
|
|
*/
|
|
function ga_section_head( $section, $args = array() ) {
|
|
$args = wp_parse_args( $args, array( 'center' => false, 'h' => 2, 'extra' => '' ) );
|
|
$eyebrow = ga_opt( $section, 'eyebrow' );
|
|
$title = ga_opt( $section, 'title' );
|
|
$text = ga_opt( $section, 'text' );
|
|
if ( ! $eyebrow && ! $title && ! $text ) {
|
|
return;
|
|
}
|
|
printf( '<div class="ga-head%s">', $args['center'] ? ' ga-head--center' : '' );
|
|
echo '<div class="ga-head__main">';
|
|
if ( $eyebrow ) {
|
|
echo '<span class="ga-eyebrow">' . esc_html( $eyebrow ) . '</span>';
|
|
}
|
|
if ( $title ) {
|
|
printf( '<h%1$d>%2$s</h%1$d>', (int) $args['h'], ga_highlight( $title ) );
|
|
}
|
|
if ( $text ) {
|
|
echo '<p class="ga-head__text">' . esc_html( $text ) . '</p>';
|
|
}
|
|
echo '</div>';
|
|
echo $args['extra']; // HTML ya escapado por quien llama.
|
|
echo '</div>';
|
|
}
|
|
|
|
/** Lista de líneas de un textarea del personalizador. */
|
|
function ga_lines( $text ) {
|
|
return array_values( array_filter( array_map( 'trim', explode( "\n", (string) $text ) ) ) );
|
|
}
|
|
|
|
/** URL configurable: vacía → valor por defecto; relativa → se respeta. */
|
|
function ga_link( $value, $fallback ) {
|
|
return '' !== trim( (string) $value ) ? $value : $fallback;
|
|
}
|
|
|
|
/* Título de archivo sin prefijo "Archivo:" */
|
|
add_filter( 'get_the_archive_title_prefix', '__return_empty_string' );
|
|
|
|
/* Extracto corto */
|
|
add_filter( 'excerpt_length', fn() => 24 );
|
|
add_filter( 'excerpt_more', fn() => '…' );
|
|
|
|
/* Formato de fecha según idioma */
|
|
add_filter( 'option_date_format', fn( $f ) => is_admin() ? $f : ga__( 'j \\d\\e F \\d\\e Y', 'Y\\(\\e\\)\\k\\o F\\r\\e\\n j\\a' ) );
|