refactor: theme from lovable
This commit is contained in:
93
wp-content/themes/cascapedia-st-jules/includes/acf.php
Normal file
93
wp-content/themes/cascapedia-st-jules/includes/acf.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
add_action( 'acf/init', 'cascapedia_st_jules_register_acf' );
|
||||
function cascapedia_st_jules_register_acf(): void {
|
||||
if ( function_exists( 'acf_add_options_page' ) ) {
|
||||
acf_add_options_page([
|
||||
'page_title' => 'Site Settings',
|
||||
'menu_title' => 'Site Settings',
|
||||
'menu_slug' => 'site-settings',
|
||||
'capability' => 'edit_posts',
|
||||
'redirect' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
acf_add_local_field_group([
|
||||
'key' => 'group_site_settings',
|
||||
'title' => 'Site Settings',
|
||||
'fields' => [
|
||||
cascapedia_st_jules_text_field('field_municipality_name_fr', 'municipality_name_fr', 'Nom municipal FR'),
|
||||
cascapedia_st_jules_text_field('field_municipality_name_en', 'municipality_name_en', 'Nom municipal EN'),
|
||||
cascapedia_st_jules_text_field('field_phone', 'phone', 'Téléphone'),
|
||||
cascapedia_st_jules_text_field('field_email', 'email', 'Courriel'),
|
||||
cascapedia_st_jules_textarea_field('field_address_fr', 'address_fr', 'Adresse FR'),
|
||||
cascapedia_st_jules_textarea_field('field_address_en', 'address_en', 'Adresse EN'),
|
||||
cascapedia_st_jules_text_field('field_hours_fr', 'hours_fr', 'Heures FR'),
|
||||
cascapedia_st_jules_text_field('field_hours_en', 'hours_en', 'Heures EN'),
|
||||
cascapedia_st_jules_url_field('field_facebook_url', 'facebook_url', 'Facebook'),
|
||||
],
|
||||
'location' => [[['param' => 'options_page', 'operator' => '==', 'value' => 'site-settings']]],
|
||||
]);
|
||||
|
||||
acf_add_local_field_group([
|
||||
'key' => 'group_page_content',
|
||||
'title' => 'Contenu de page',
|
||||
'fields' => [[
|
||||
'key' => 'field_sections',
|
||||
'label' => 'Sections',
|
||||
'name' => 'sections',
|
||||
'type' => 'flexible_content',
|
||||
'button_label' => 'Ajouter une section',
|
||||
'layouts' => cascapedia_st_jules_acf_layouts(),
|
||||
]],
|
||||
'location' => [[['param' => 'post_type', 'operator' => '==', 'value' => 'page']]],
|
||||
]);
|
||||
}
|
||||
|
||||
add_filter( 'acf/settings/save_json', fn() => get_stylesheet_directory() . '/acf-json' );
|
||||
add_filter( 'acf/settings/load_json', function( array $paths ): array {
|
||||
$paths[] = get_stylesheet_directory() . '/acf-json';
|
||||
return $paths;
|
||||
});
|
||||
|
||||
function cascapedia_st_jules_acf_layouts(): array {
|
||||
return [
|
||||
cascapedia_st_jules_layout('hero_carousel', 'Hero carousel', [cascapedia_st_jules_repeater_field('field_hero_slides', 'slides', 'Slides')]),
|
||||
cascapedia_st_jules_layout('text_intro', 'Texte intro', cascapedia_st_jules_basic_copy_fields()),
|
||||
cascapedia_st_jules_layout('text_image', 'Texte + image', array_merge(cascapedia_st_jules_basic_copy_fields(), [cascapedia_st_jules_image_field('field_text_image_image', 'image', 'Image')])),
|
||||
cascapedia_st_jules_layout('services_list', 'Liste de services', array_merge(cascapedia_st_jules_basic_copy_fields(), [cascapedia_st_jules_repeater_field('field_services', 'services', 'Services')])),
|
||||
cascapedia_st_jules_layout('photo_gallery', 'Galerie photos', [cascapedia_st_jules_text_field('field_gallery_title_fr', 'title_fr', 'Titre FR'), cascapedia_st_jules_text_field('field_gallery_title_en', 'title_en', 'Titre EN'), cascapedia_st_jules_gallery_field('field_gallery_photos', 'photos', 'Photos')]),
|
||||
cascapedia_st_jules_layout('events_list', 'Liste événements', array_merge(cascapedia_st_jules_basic_copy_fields(), [cascapedia_st_jules_repeater_field('field_events', 'events', 'Événements')])),
|
||||
cascapedia_st_jules_layout('businesses_list', 'Entreprises', array_merge(cascapedia_st_jules_basic_copy_fields(), [cascapedia_st_jules_repeater_field('field_business_categories', 'categories', 'Catégories')])),
|
||||
cascapedia_st_jules_layout('cta_section', 'CTA', array_merge(cascapedia_st_jules_basic_copy_fields(), [cascapedia_st_jules_link_field('field_cta_link', 'cta', 'Lien')])),
|
||||
cascapedia_st_jules_layout('council_grid', 'Conseil municipal', array_merge(cascapedia_st_jules_basic_copy_fields(), [cascapedia_st_jules_repeater_field('field_council_members', 'members', 'Membres')])),
|
||||
cascapedia_st_jules_layout('documents_list', 'Liste documents', array_merge(cascapedia_st_jules_basic_copy_fields(), [cascapedia_st_jules_repeater_field('field_document_groups', 'groups', 'Groupes')])),
|
||||
cascapedia_st_jules_layout('pdf_embed', 'PDF intégré', [cascapedia_st_jules_text_field('field_pdf_title_fr', 'title_fr', 'Titre FR'), cascapedia_st_jules_text_field('field_pdf_title_en', 'title_en', 'Titre EN'), cascapedia_st_jules_file_field('field_pdf_file', 'file', 'PDF')]),
|
||||
];
|
||||
}
|
||||
|
||||
function cascapedia_st_jules_basic_copy_fields(): array {
|
||||
return [
|
||||
cascapedia_st_jules_text_field('field_title_fr', 'title_fr', 'Titre FR'),
|
||||
cascapedia_st_jules_text_field('field_title_en', 'title_en', 'Titre EN'),
|
||||
cascapedia_st_jules_wysiwyg_field('field_body_fr', 'body_fr', 'Texte FR'),
|
||||
cascapedia_st_jules_wysiwyg_field('field_body_en', 'body_en', 'Texte EN'),
|
||||
];
|
||||
}
|
||||
|
||||
function cascapedia_st_jules_layout( string $name, string $label, array $sub_fields ): array {
|
||||
return ['key' => 'layout_' . $name, 'name' => $name, 'label' => $label, 'display' => 'block', 'sub_fields' => $sub_fields];
|
||||
}
|
||||
function cascapedia_st_jules_text_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'text']; }
|
||||
function cascapedia_st_jules_url_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'url']; }
|
||||
function cascapedia_st_jules_textarea_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'textarea','rows'=>3]; }
|
||||
function cascapedia_st_jules_wysiwyg_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'wysiwyg','tabs'=>'all','toolbar'=>'basic','media_upload'=>0]; }
|
||||
function cascapedia_st_jules_image_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'image','return_format'=>'array','preview_size'=>'medium']; }
|
||||
function cascapedia_st_jules_gallery_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'gallery','return_format'=>'array','preview_size'=>'medium']; }
|
||||
function cascapedia_st_jules_file_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'file','return_format'=>'array','mime_types'=>'pdf']; }
|
||||
function cascapedia_st_jules_link_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'link','return_format'=>'array']; }
|
||||
function cascapedia_st_jules_repeater_field($key, $name, $label): array { return ['key'=>$key,'label'=>$label,'name'=>$name,'type'=>'repeater','layout'=>'row','button_label'=>'Ajouter','sub_fields'=>[cascapedia_st_jules_text_field($key.'_label_fr','label_fr','Libellé FR'), cascapedia_st_jules_text_field($key.'_label_en','label_en','Libellé EN'), cascapedia_st_jules_wysiwyg_field($key.'_content_fr','content_fr','Contenu FR'), cascapedia_st_jules_wysiwyg_field($key.'_content_en','content_en','Contenu EN')]]; }
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
add_action( 'wp_enqueue_scripts', 'cascapedia_st_jules_enqueue_assets' );
|
||||
function cascapedia_st_jules_enqueue_assets(): void {
|
||||
$manifest_path = get_theme_file_path( 'assets/dist/.vite/manifest.json' );
|
||||
|
||||
if ( ! file_exists( $manifest_path ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$manifest = json_decode( file_get_contents( $manifest_path ), true );
|
||||
$entry = $manifest['assets/src/main.tsx'] ?? null;
|
||||
|
||||
if ( ! is_array( $entry ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $entry['css'] ) && is_array( $entry['css'] ) ) {
|
||||
foreach ( $entry['css'] as $index => $css_file ) {
|
||||
$css_path = get_theme_file_path( 'assets/dist/' . $css_file );
|
||||
wp_enqueue_style(
|
||||
'cascapedia-st-jules-' . $index,
|
||||
get_theme_file_uri( 'assets/dist/' . $css_file ),
|
||||
array(),
|
||||
file_exists( $css_path ) ? (string) filemtime( $css_path ) : wp_get_theme()->get( 'Version' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $entry['file'] ) ) {
|
||||
$js_path = get_theme_file_path( 'assets/dist/' . $entry['file'] );
|
||||
wp_enqueue_script(
|
||||
'cascapedia-st-jules-app',
|
||||
get_theme_file_uri( 'assets/dist/' . $entry['file'] ),
|
||||
array(),
|
||||
file_exists( $js_path ) ? (string) filemtime( $js_path ) : wp_get_theme()->get( 'Version' ),
|
||||
true
|
||||
);
|
||||
|
||||
$page_data = cascapedia_st_jules_current_page_data();
|
||||
wp_add_inline_script(
|
||||
'cascapedia-st-jules-app',
|
||||
'window.__CASCA_PAGE__ = ' . wp_json_encode( $page_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) . ';',
|
||||
'before'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function cascapedia_st_jules_current_page_data(): array {
|
||||
$post_id = get_queried_object_id();
|
||||
if ( ! $post_id && ( is_home() || is_front_page() ) ) {
|
||||
$post_id = (int) get_option( 'page_on_front' );
|
||||
}
|
||||
|
||||
$sections = $post_id ? json_decode( (string) get_post_meta( $post_id, '_react_sections_json', true ), true ) : array();
|
||||
|
||||
$data = array(
|
||||
'id' => $post_id,
|
||||
'seo' => array(
|
||||
'title' => array(
|
||||
'fr' => $post_id ? (string) get_post_meta( $post_id, '_seo_title_fr', true ) : '',
|
||||
'en' => $post_id ? (string) get_post_meta( $post_id, '_seo_title_en', true ) : '',
|
||||
),
|
||||
'description' => array(
|
||||
'fr' => $post_id ? (string) get_post_meta( $post_id, '_seo_description_fr', true ) : '',
|
||||
'en' => $post_id ? (string) get_post_meta( $post_id, '_seo_description_en', true ) : '',
|
||||
),
|
||||
),
|
||||
'sections' => is_array( $sections ) ? $sections : array(),
|
||||
);
|
||||
|
||||
return cascapedia_st_jules_rewrite_asset_urls( $data );
|
||||
}
|
||||
|
||||
function cascapedia_st_jules_rewrite_asset_urls( mixed $value ): mixed {
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $key => $item ) {
|
||||
$value[ $key ] = cascapedia_st_jules_rewrite_asset_urls( $item );
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ( is_string( $value ) && str_starts_with( $value, '/assets/' ) ) {
|
||||
return get_theme_file_uri( 'assets/dist' . $value );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
add_action( 'after_setup_theme', 'cascapedia_st_jules_after_setup_theme' );
|
||||
function cascapedia_st_jules_after_setup_theme(): void {
|
||||
load_theme_textdomain( 'cascapedia-st-jules', get_theme_file_path( 'languages' ) );
|
||||
|
||||
add_theme_support( 'custom-logo' );
|
||||
add_theme_support( 'editor-styles' );
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
add_theme_support( 'title-tag' );
|
||||
remove_theme_support( 'core-block-patterns' );
|
||||
|
||||
register_nav_menu( 'primary', 'Menu principal' );
|
||||
}
|
||||
|
||||
add_filter( 'show_admin_bar', '__return_false' );
|
||||
29
wp-content/themes/cascapedia-st-jules/includes/cpt.php
Normal file
29
wp-content/themes/cascapedia-st-jules/includes/cpt.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
add_action( 'init', 'cascapedia_st_jules_register_content_types' );
|
||||
function cascapedia_st_jules_register_content_types(): void {
|
||||
$types = [
|
||||
'document' => ['Documents', 'Document', 'dashicons-media-document'],
|
||||
'public_notice' => ['Avis publics', 'Avis public', 'dashicons-megaphone'],
|
||||
'event' => ['Événements', 'Événement', 'dashicons-calendar-alt'],
|
||||
'local_business' => ['Entreprises locales', 'Entreprise locale', 'dashicons-store'],
|
||||
'gallery' => ['Galeries', 'Galerie', 'dashicons-format-gallery'],
|
||||
];
|
||||
|
||||
foreach ( $types as $slug => [$plural, $singular, $icon] ) {
|
||||
register_post_type( $slug, [
|
||||
'labels' => [
|
||||
'name' => $plural,
|
||||
'singular_name' => $singular,
|
||||
'add_new_item' => 'Ajouter ' . strtolower( $singular ),
|
||||
'edit_item' => 'Modifier ' . strtolower( $singular ),
|
||||
],
|
||||
'public' => true,
|
||||
'show_in_rest' => true,
|
||||
'menu_icon' => $icon,
|
||||
'supports' => ['title', 'editor', 'thumbnail', 'excerpt'],
|
||||
'has_archive' => true,
|
||||
'rewrite' => ['slug' => str_replace( '_', '-', $slug )],
|
||||
] );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user