$section ) { if ( ! empty( $section['section'] ) && ga_opt( $id, 'show' ) ) { $sections[ $id ] = (int) ga_opt( $id, 'order' ); } } asort( $sections ); return array_keys( $sections ); } /* Los datos de contacto y redes del personalizador sustituyen a los predeterminados. */ add_filter( 'ga_info', function ( $info ) { foreach ( array( 'direccion', 'maps', 'telefono', 'email', 'horario' ) as $key ) { $info[ $key ] = ga_opt( 'contact', $key ); } foreach ( array( 'instagram', 'facebook', 'tiktok', 'youtube', 'whatsapp' ) as $key ) { $info[ $key ] = ga_opt( 'social', $key ); } return $info; } ); /* ---------- Registro en el personalizador ---------- */ add_action( 'customize_register', function ( WP_Customize_Manager $c ) { $c->add_panel( 'ga_design', array( 'title' => 'Diseño (Gure Ametsa)', 'priority' => 25 ) ); $c->add_panel( 'ga_info', array( 'title' => 'Contacto y redes', 'priority' => 26 ) ); $c->add_panel( 'ga_home', array( 'title' => 'Portada', 'priority' => 27, 'description' => 'Muestra, oculta y reordena las secciones de la portada. Los textos se escriben en castellano y en euskera.', ) ); $sanitizers = array( 'text' => 'sanitize_text_field', 'textarea' => 'sanitize_textarea_field', 'url' => 'esc_url_raw', 'email' => 'sanitize_email', 'color' => 'sanitize_hex_color', 'checkbox' => fn( $v ) => (bool) $v, 'number' => 'absint', 'range' => 'absint', 'image' => 'absint', 'video' => 'absint', ); foreach ( ga_customizer_registry() as $sid => $section ) { $section_id = "ga_section_$sid"; $c->add_section( $section_id, array( 'title' => $section['title'], 'panel' => $section['panel'], 'description' => $section['description'] ?? '', ) ); foreach ( $section['fields'] as $fid => $field ) { $langs = ! empty( $field['i18n'] ) ? array( 'es', 'eu' ) : array( 'es' ); foreach ( $langs as $lang ) { $key = ga_mod_key( $sid, $fid, $lang ); $sanitize = $sanitizers[ $field['type'] ] ?? null; if ( 'select' === $field['type'] ) { $choices = $field['choices']; $default = $field['default']; $sanitize = fn( $v ) => array_key_exists( $v, $choices ) ? $v : $default; } $c->add_setting( $key, array( 'default' => ga_field_default( $field, $lang ), 'sanitize_callback' => $sanitize, ) ); $label = $field['label'] . ( ! empty( $field['i18n'] ) ? ( 'eu' === $lang ? ' · EU' : ' · ES' ) : '' ); $args = array( 'label' => $label, 'section' => $section_id, 'description' => $field['description'] ?? '', 'priority' => empty( $field['i18n'] ) ? 50 : ( 'eu' === $lang ? 200 : 100 ), ); switch ( $field['type'] ) { case 'color': $c->add_control( new WP_Customize_Color_Control( $c, $key, $args ) ); break; case 'image': case 'video': $c->add_control( new WP_Customize_Media_Control( $c, $key, $args + array( 'mime_type' => $field['type'] ) ) ); break; case 'range': case 'number': $args['type'] = $field['type']; $args['input_attrs'] = array_filter( array( 'min' => $field['min'] ?? null, 'max' => $field['max'] ?? null, 'step' => $field['step'] ?? 1, ), fn( $v ) => null !== $v ); if ( 'range' === $field['type'] ) { $args['description'] = trim( $args['description'] . ' Por defecto: ' . $field['default'] . '.' ); } $c->add_control( $key, $args ); break; case 'select': $c->add_control( $key, $args + array( 'type' => 'select', 'choices' => $field['choices'] ) ); break; default: $c->add_control( $key, $args + array( 'type' => $field['type'] ) ); } } } // Separador visual entre castellano y euskera. $has_i18n = (bool) array_filter( $section['fields'], fn( $f ) => ! empty( $f['i18n'] ) ); if ( $has_i18n ) { foreach ( array( 'es' => array( 99, 'Castellano' ), 'eu' => array( 199, 'Euskara' ) ) as $lang => [ $priority, $title ] ) { $c->add_setting( "ga_sep_{$sid}_{$lang}", array( 'sanitize_callback' => '__return_empty_string' ) ); $c->add_control( new GA_Customize_Heading_Control( $c, "ga_sep_{$sid}_{$lang}", array( 'label' => $title, 'section' => $section_id, 'priority' => $priority, ) ) ); } } } } ); add_action( 'customize_register', function () { if ( class_exists( 'GA_Customize_Heading_Control' ) ) { return; } /** Encabezado sin campo, para separar idiomas. */ class GA_Customize_Heading_Control extends WP_Customize_Control { public $type = 'ga-heading'; public function render_content() { printf( '