Web de Gure Ametsa Bi Lagun en WordPress para Dokploy
- Docker Compose (WordPress + MariaDB) listo para Dokploy, con instalación automática por etapas: idiomas, páginas, menús y plugins recomendados. - Web bilingüe castellano / euskera con Polylang. - Tema propio «gure-ametsa»: diseño inspirado en Beargrass Animal Rescue, personalizable desde Apariencia → Personalizar (paletas, tipografías, secciones de portada ordenables) y patrones de bloques propios. - Plugin mu «gure-ametsa-core»: animales en adopción con ficha y filtros, carrusel y formulario de contacto/adopción. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
276
docker/setup-content.php
Normal file
276
docker/setup-content.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
/**
|
||||
* Contenido inicial bilingüe (castellano / euskera).
|
||||
* Se ejecuta una sola vez con: wp eval-file setup-content.php
|
||||
*/
|
||||
|
||||
$src = ( getenv( 'GA_SRC' ) ?: '/usr/src/gure-ametsa' ) . '/content';
|
||||
$pll = function_exists( 'pll_set_post_language' ) && function_exists( 'PLL' );
|
||||
|
||||
if ( ! $pll ) {
|
||||
WP_CLI::warning( 'Polylang no está activo: se crea solo el contenido en castellano.' );
|
||||
}
|
||||
|
||||
/* ---------- 1. Idiomas y ajustes de Polylang ---------- */
|
||||
if ( $pll ) {
|
||||
$model = PLL()->model;
|
||||
$existing = wp_list_pluck( $model->get_languages_list(), 'slug' );
|
||||
$langs = 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() );
|
||||
}
|
||||
}
|
||||
$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' ),
|
||||
);
|
||||
$options = PLL()->options;
|
||||
if ( is_object( $options ) && method_exists( $options, 'set' ) ) {
|
||||
foreach ( $settings as $key => $value ) {
|
||||
$options->set( $key, $value );
|
||||
}
|
||||
if ( method_exists( $options, 'save_all' ) ) {
|
||||
$options->save_all();
|
||||
}
|
||||
} 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 );
|
||||
$mo->add_entry( $mo->make_entry( get_option( 'blogdescription' ), 'Adoptatu eta bi mundu aldatu · Hondarribia' ) );
|
||||
$mo->export_to_db( $eu );
|
||||
}
|
||||
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;
|
||||
}
|
||||
$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() );
|
||||
}
|
||||
if ( function_exists( 'pll_set_post_language' ) ) {
|
||||
pll_set_post_language( $id, $lang );
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
// slug es => [título es, archivo es, slug eu, título eu, archivo 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' ),
|
||||
);
|
||||
|
||||
$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' );
|
||||
if ( $pll ) {
|
||||
$ids[ $slug ]['eu'] = ga_setup_page( $slug_eu, $title_eu, "$src/eu/$file_eu.html", 'eu' );
|
||||
pll_save_post_translations( $ids[ $slug ] );
|
||||
}
|
||||
}
|
||||
|
||||
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' );
|
||||
|
||||
/* ---------- 3. Especies ---------- */
|
||||
$species = array(
|
||||
'perro' => array( 'Perro', 'txakurra', 'Txakurra' ),
|
||||
'gato' => array( 'Gato', 'katua', 'Katua' ),
|
||||
'otros' => array( 'Otros', 'besteak', 'Besteak' ),
|
||||
);
|
||||
$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 ( $pairs as $lang => [ $term_slug, $term_name ] ) {
|
||||
$term = get_term_by( 'slug', $term_slug, 'especie' );
|
||||
if ( ! $term ) {
|
||||
$res = wp_insert_term( $term_name, 'especie', array( 'slug' => $term_slug ) );
|
||||
$term = is_wp_error( $res ) ? null : get_term( $res['term_id'], 'especie' );
|
||||
}
|
||||
if ( $term ) {
|
||||
$term_ids[ $slug ][ $lang ] = $term->term_id;
|
||||
if ( $pll ) {
|
||||
pll_set_term_language( $term->term_id, $lang );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $pll && count( $term_ids[ $slug ] ?? array() ) === 2 ) {
|
||||
pll_save_term_translations( $term_ids[ $slug ] );
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 4. Menús ---------- */
|
||||
function ga_setup_menu( $name, $items ) {
|
||||
$menu = wp_get_nav_menu_object( $name );
|
||||
if ( $menu ) {
|
||||
return $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'] );
|
||||
}
|
||||
wp_update_nav_menu_item( $menu_id, 0, $args );
|
||||
}
|
||||
return $menu_id;
|
||||
}
|
||||
|
||||
$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' => 'Contacto', 'page' => $ids['contacto']['es'] ),
|
||||
) ),
|
||||
),
|
||||
'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'] ),
|
||||
) ),
|
||||
),
|
||||
);
|
||||
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' => 'Harremanetarako', 'page' => $ids['contacto']['eu'] ),
|
||||
) );
|
||||
$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'] ),
|
||||
) );
|
||||
|
||||
$theme = get_stylesheet();
|
||||
$nav_menus = array( $theme => $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' ) ) {
|
||||
PLL()->options->save_all();
|
||||
}
|
||||
} else {
|
||||
$opts = (array) get_option( 'polylang', array() );
|
||||
$opts['nav_menus'] = $nav_menus;
|
||||
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' );
|
||||
|
||||
/* ---------- 5. Animales de ejemplo (opcional) ---------- */
|
||||
if ( 'true' === getenv( 'SEED_DEMO_ANIMALS' ) ) {
|
||||
$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.' ),
|
||||
'sp' => 'perro',
|
||||
'meta' => array( 'sexo' => 'hembra', 'edad' => '3', 'edad_unidad' => 'anos', 'tamano' => 'mediano', 'estado' => 'disponible', 'raza' => 'Mestiza' ),
|
||||
),
|
||||
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.' ),
|
||||
'sp' => 'gato',
|
||||
'meta' => array( 'sexo' => 'macho', 'edad' => '1', 'edad_unidad' => 'anos', 'tamano' => 'pequeno', 'estado' => 'disponible', 'raza' => 'Común europeo' ),
|
||||
),
|
||||
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.' ),
|
||||
'sp' => 'perro',
|
||||
'meta' => array( 'sexo' => 'macho', 'edad' => '7', 'edad_unidad' => 'anos', 'tamano' => 'grande', 'estado' => 'urgente', 'raza' => 'Mastín' ),
|
||||
),
|
||||
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.' ),
|
||||
'sp' => 'gato',
|
||||
'meta' => array( 'sexo' => 'hembra', 'edad' => '4', 'edad_unidad' => 'meses', 'tamano' => 'pequeno', 'estado' => 'reservado', 'raza' => 'Común europeo' ),
|
||||
),
|
||||
);
|
||||
foreach ( $demo as $animal ) {
|
||||
$translations = array();
|
||||
foreach ( $pll ? array( 'es', 'eu' ) : array( 'es' ) as $lang ) {
|
||||
[ $title, $text ] = $animal[ $lang ];
|
||||
$id = wp_insert_post( array(
|
||||
'post_type' => 'animal',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => $title,
|
||||
'post_content' => "<!-- wp:paragraph -->\n<p>$text</p>\n<!-- /wp:paragraph -->",
|
||||
) );
|
||||
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 ) {
|
||||
update_post_meta( $id, "_ga_$key", $value );
|
||||
}
|
||||
if ( $pll ) {
|
||||
pll_set_post_language( $id, $lang );
|
||||
}
|
||||
$translations[ $lang ] = $id;
|
||||
}
|
||||
if ( $pll ) {
|
||||
pll_save_post_translations( $translations );
|
||||
}
|
||||
}
|
||||
WP_CLI::log( '[ga-setup] Animales de ejemplo creados' );
|
||||
}
|
||||
|
||||
// Polylang guarda en caché la portada de cada idioma: se regenera con las traducciones ya creadas.
|
||||
if ( $pll ) {
|
||||
PLL()->model->clean_languages_cache();
|
||||
}
|
||||
flush_rewrite_rules( false );
|
||||
Reference in New Issue
Block a user