feat: Template CPT and section
This commit is contained in:
20
.vscode/launch.json
vendored
Normal file
20
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Xdebug",
|
||||||
|
"pathMappings": {
|
||||||
|
"/var/www/html": "${workspaceFolder}/.."
|
||||||
|
},
|
||||||
|
"port": 9003,
|
||||||
|
"request": "launch",
|
||||||
|
"type": "php",
|
||||||
|
"xdebugSettings": {
|
||||||
|
"max_data": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
7
wp-content/themes/headless/.hygen.cjs
Normal file
7
wp-content/themes/headless/.hygen.cjs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module.exports = {
|
||||||
|
templates: `../kaliroots/_templates`,
|
||||||
|
helpers: {
|
||||||
|
description: "Headless",
|
||||||
|
textdomain: "headless",
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -93,6 +93,67 @@
|
|||||||
"acfe_flexible_render_script": false,
|
"acfe_flexible_render_script": false,
|
||||||
"acfe_flexible_thumbnail": false,
|
"acfe_flexible_thumbnail": false,
|
||||||
"acfe_flexible_category": false
|
"acfe_flexible_category": false
|
||||||
|
},
|
||||||
|
"layout_69c69985e74f4": {
|
||||||
|
"key": "layout_69c69985e74f4",
|
||||||
|
"name": "template",
|
||||||
|
"label": "Modèle",
|
||||||
|
"display": "block",
|
||||||
|
"sub_fields": [
|
||||||
|
{
|
||||||
|
"key": "field_69c6998ce74f6",
|
||||||
|
"label": "Modèle",
|
||||||
|
"name": "template",
|
||||||
|
"aria-label": "",
|
||||||
|
"type": "post_object",
|
||||||
|
"instructions": "",
|
||||||
|
"required": 1,
|
||||||
|
"conditional_logic": 0,
|
||||||
|
"wrapper": {
|
||||||
|
"width": "",
|
||||||
|
"class": "",
|
||||||
|
"id": ""
|
||||||
|
},
|
||||||
|
"post_type": [
|
||||||
|
"template"
|
||||||
|
],
|
||||||
|
"post_status": [
|
||||||
|
"publish"
|
||||||
|
],
|
||||||
|
"taxonomy": "",
|
||||||
|
"return_format": "id",
|
||||||
|
"multiple": 0,
|
||||||
|
"save_custom": 0,
|
||||||
|
"save_post_status": "publish",
|
||||||
|
"acfe_bidirectional": {
|
||||||
|
"acfe_bidirectional_enabled": "0"
|
||||||
|
},
|
||||||
|
"allow_null": 0,
|
||||||
|
"allow_in_bindings": 0,
|
||||||
|
"bidirectional": 0,
|
||||||
|
"show_in_graphql": 1,
|
||||||
|
"graphql_description": "",
|
||||||
|
"graphql_field_name": "template",
|
||||||
|
"graphql_connection_type": "one_to_one",
|
||||||
|
"ui": 1,
|
||||||
|
"bidirectional_target": [],
|
||||||
|
"save_post_type": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"min": "",
|
||||||
|
"max": "",
|
||||||
|
"acfe_flexible_modal_edit_size": "",
|
||||||
|
"acfe_flexible_settings": [
|
||||||
|
"group_layout_padding",
|
||||||
|
"group_layout_container",
|
||||||
|
"group_layout_color"
|
||||||
|
],
|
||||||
|
"acfe_flexible_settings_size": "",
|
||||||
|
"acfe_flexible_render_template": false,
|
||||||
|
"acfe_flexible_render_style": false,
|
||||||
|
"acfe_flexible_render_script": false,
|
||||||
|
"acfe_flexible_thumbnail": false,
|
||||||
|
"acfe_flexible_category": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"min": "",
|
"min": "",
|
||||||
@@ -134,5 +195,5 @@
|
|||||||
"graphql_types": "",
|
"graphql_types": "",
|
||||||
"acfe_meta": "",
|
"acfe_meta": "",
|
||||||
"acfe_note": "",
|
"acfe_note": "",
|
||||||
"modified": 1774617029
|
"modified": 1774623170
|
||||||
}
|
}
|
||||||
|
|||||||
66
wp-content/themes/headless/acf-json/group_post_template.json
Normal file
66
wp-content/themes/headless/acf-json/group_post_template.json
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"key": "group_post_template",
|
||||||
|
"title": "Post - Template",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"key": "field_690cbda0abcbb",
|
||||||
|
"label": "Constructeur de page",
|
||||||
|
"name": "builder",
|
||||||
|
"aria-label": "",
|
||||||
|
"type": "clone",
|
||||||
|
"instructions": "",
|
||||||
|
"required": 0,
|
||||||
|
"conditional_logic": 0,
|
||||||
|
"wrapper": {
|
||||||
|
"width": "",
|
||||||
|
"class": "",
|
||||||
|
"id": ""
|
||||||
|
},
|
||||||
|
"graphql_field_name": "builder",
|
||||||
|
"clone": [
|
||||||
|
"group_abstract_builder"
|
||||||
|
],
|
||||||
|
"display": "seamless",
|
||||||
|
"layout": "block",
|
||||||
|
"prefix_label": 0,
|
||||||
|
"prefix_name": 1,
|
||||||
|
"acfe_seamless_style": 0,
|
||||||
|
"acfe_clone_modal": 0,
|
||||||
|
"acfe_clone_modal_close": 0,
|
||||||
|
"acfe_clone_modal_button": "",
|
||||||
|
"acfe_clone_modal_size": "large"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"location": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"param": "post_type",
|
||||||
|
"operator": "==",
|
||||||
|
"value": "template"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"menu_order": 0,
|
||||||
|
"position": "normal",
|
||||||
|
"style": "seamless",
|
||||||
|
"label_placement": "top",
|
||||||
|
"instruction_placement": "label",
|
||||||
|
"hide_on_screen": [
|
||||||
|
"the_content"
|
||||||
|
],
|
||||||
|
"active": true,
|
||||||
|
"description": "",
|
||||||
|
"show_in_rest": 0,
|
||||||
|
"display_title": "",
|
||||||
|
"acfe_autosync": [
|
||||||
|
"json"
|
||||||
|
],
|
||||||
|
"acfe_form": 0,
|
||||||
|
"show_in_graphql": 1,
|
||||||
|
"graphql_field_name": "GroupTemplate",
|
||||||
|
"map_graphql_types_from_location_rules": 0,
|
||||||
|
"graphql_types": "",
|
||||||
|
"acfe_meta": "",
|
||||||
|
"acfe_note": "",
|
||||||
|
"modified": 1774624640
|
||||||
|
}
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
// Core
|
// Core
|
||||||
require_once __DIR__ . '/includes/core/theme-setup.php';
|
require_once __DIR__ . '/includes/core/theme-setup.php';
|
||||||
|
|
||||||
|
// Custom Post Types
|
||||||
|
require_once __DIR__ . '/includes/cpt/template.php';
|
||||||
|
|
||||||
// Vendors
|
// Vendors
|
||||||
require_once __DIR__ . '/includes/vendors/acf.php';
|
require_once __DIR__ . '/includes/vendors/acf.php';
|
||||||
require_once __DIR__ . '/includes/vendors/rankmath.php';
|
require_once __DIR__ . '/includes/vendors/rankmath.php';
|
||||||
|
|||||||
130
wp-content/themes/headless/includes/cpt/template.php
Normal file
130
wp-content/themes/headless/includes/cpt/template.php
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Register 'template' post type
|
||||||
|
add_action( 'init', 'headless_template_register_post_type' );
|
||||||
|
function headless_template_register_post_type() {
|
||||||
|
register_post_type(
|
||||||
|
'template',
|
||||||
|
array(
|
||||||
|
'labels' => array(
|
||||||
|
'name' => "Modèles",
|
||||||
|
'menu_name' => "Modèles",
|
||||||
|
'singular_name' => "Modèle",
|
||||||
|
'add_new' => "Ajouter",
|
||||||
|
'add_new_item' => "Ajouter un modèle",
|
||||||
|
'new_item' => "Nouveau modèle",
|
||||||
|
'edit_item' => "Modifier le modèle",
|
||||||
|
'view_item' => "Voir le modèle",
|
||||||
|
'view_items' => "Voir les modèles",
|
||||||
|
'search_items' => "Rechercher des modèles",
|
||||||
|
'not_found' => "Aucun modèle trouvé",
|
||||||
|
'not_found_in_trash' => "Aucun modèle trouvé dans la corbeille",
|
||||||
|
'parent_item_colon' => "Modèle parent :",
|
||||||
|
'all_items' => "Tous les modèles",
|
||||||
|
'archives' => "Archives des modèles",
|
||||||
|
'attributes' => "Attributs du modèle",
|
||||||
|
'insert_into_item' => "Insérer dans le modèle",
|
||||||
|
'uploaded_to_this_item' => "Téléversé dans ce modèle",
|
||||||
|
'featured_image' => "Vignette",
|
||||||
|
'set_featured_image' => "Définir la vignette",
|
||||||
|
'remove_featured_image' => "Supprimer la vignette",
|
||||||
|
'use_featured_image' => "Utiliser comme vignette",
|
||||||
|
'filter_items_list' => "Filtrer la liste des modèles",
|
||||||
|
'items_list_navigation' => "Navigation dans la liste des modèles",
|
||||||
|
'items_list' => "Liste des modèles",
|
||||||
|
'item_published' => "Modèle publié.",
|
||||||
|
'item_published_privately' => "Modèle publié en privé.",
|
||||||
|
'item_reverted_to_draft' => "Modèle remis au brouillon.",
|
||||||
|
'item_scheduled' => "Modèle planifié.",
|
||||||
|
'item_updated' => "Modèle mis à jour.",
|
||||||
|
),
|
||||||
|
'public' => false,
|
||||||
|
'hierarchical' => false,
|
||||||
|
'show_ui' => true,
|
||||||
|
'show_in_nav_menus' => false,
|
||||||
|
'supports' => array( 'title', 'revisions' ),
|
||||||
|
'has_archive' => false,
|
||||||
|
'rewrite' => false,
|
||||||
|
'query_var' => true,
|
||||||
|
'menu_icon' => 'dashicons-clipboard',
|
||||||
|
'show_in_rest' => false,
|
||||||
|
'rest_base' => 'template',
|
||||||
|
'rest_controller_class' => 'WP_REST_Posts_Controller',
|
||||||
|
'show_in_graphql' => true,
|
||||||
|
'graphql_single_name' => "Template",
|
||||||
|
'graphql_plural_name' => "Templates",
|
||||||
|
'graphql_interfaces' => array( 'Node' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom 'template' post updated messages
|
||||||
|
add_filter( 'post_updated_messages', 'headless_template_post_updated_messages' );
|
||||||
|
function headless_template_post_updated_messages( $messages ) {
|
||||||
|
global $post;
|
||||||
|
$permalink = get_permalink( $post );
|
||||||
|
$preview_post_link_html = sprintf( ' <a target="_blank" href="%1$s">%2$s</a>', esc_url( get_preview_post_link( $post ) ), "Prévisualiser le modèle" );
|
||||||
|
$scheduled_post_link_html = sprintf( ' <a target="_blank" href="%1$s">%2$s</a>', esc_url( $permalink ), "Prévisualiser le modèle" );
|
||||||
|
$scheduled_date = date_i18n( "j M Y à H:i", strtotime( $post->post_date ) );
|
||||||
|
$view_post_link_html = sprintf( ' <a href="%1$s">%2$s</a>', esc_url( $permalink ), "Voir le modèle" );
|
||||||
|
$messages['template'] = array(
|
||||||
|
0 => '',
|
||||||
|
1 => "Modèle mis à jour." . $view_post_link_html,
|
||||||
|
2 => "Champ personnalisé mis à jour.",
|
||||||
|
3 => "Champ personnalisé supprimé.",
|
||||||
|
4 => "Modèle mis à jour.",
|
||||||
|
5 => isset( $_GET['revision'] ) ? sprintf( "Modèle restauré à partir de la révision du %s", wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
|
||||||
|
6 => "Modèle publié." . $view_post_link_html,
|
||||||
|
7 => "Modèle enregistré.",
|
||||||
|
8 => "Modèle soumis." . $preview_post_link_html,
|
||||||
|
9 => sprintf( "Modèle planifié pour le : %s.", '<strong>' . $scheduled_date . '</strong>' ) . $scheduled_post_link_html,
|
||||||
|
10 => "Brouillon du modèle mis à jour." . $preview_post_link_html,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper: Replace template(s) in sections value recursively
|
||||||
|
function headless_template_replace_sections( $sections ) {
|
||||||
|
if ( ! is_array( $sections ) ) {
|
||||||
|
return $sections;
|
||||||
|
}
|
||||||
|
|
||||||
|
$processed_sections = array();
|
||||||
|
foreach ( $sections as $section ) {
|
||||||
|
if ( empty( $layout = $section['acf_fc_layout'] ?? false ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $layout !== 'template' ) {
|
||||||
|
$processed_sections[] = $section;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $template_id = $section['template'] ?? false ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$template_sections = get_field( 'builder_sections', $template_id );
|
||||||
|
if ( is_array( $template_sections ) ) {
|
||||||
|
$expanded_sections = headless_template_replace_sections( $template_sections );
|
||||||
|
foreach ( $expanded_sections as $expanded_section ) {
|
||||||
|
$processed_sections[] = $expanded_section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $processed_sections;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace template(s) in GraphQL builder sections value
|
||||||
|
add_filter( 'wpgraphql/acf/field_value', 'headless_graphql_process_sections', 10, 2 );
|
||||||
|
function headless_graphql_process_sections( $value, $field_config ) {
|
||||||
|
if ( 'builder' !== $field_config['name'] ?? false || ! is_array( $value['sections'] ?? false ) ) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value['sections'] = headless_template_replace_sections( $value['sections'] );
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
@@ -31,9 +31,8 @@ export default defineNuxtConfig({
|
|||||||
|
|
||||||
graphql: {
|
graphql: {
|
||||||
client: {
|
client: {
|
||||||
cache: {
|
cache: { keyVersion: version },
|
||||||
keyVersion: version,
|
ssrForwardHeaders: ["authorization", "cookie"],
|
||||||
},
|
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
context: ["server/graphql/context.ts"],
|
context: ["server/graphql/context.ts"],
|
||||||
|
|||||||
Reference in New Issue
Block a user