From d41f3cd2ea68f2db9abff87a093350da0f51ffbe Mon Sep 17 00:00:00 2001 From: Glynn Quelch Date: Thu, 29 May 2025 10:50:09 +0100 Subject: [PATCH 1/5] Add in the means to edit the footer and also to use the standard or AI header and footer --- .../acf-fields/group_68381f7bdc12b.json | 74 +++++++ .../acf-fields/post_type_672acc9b32c0c.json | 2 +- themes/osi/footer-ai.php | 182 ++-------------- themes/osi/inc/block-patterns.php | 198 ++++++++++++++++++ themes/osi/templates/ai-wide.php | 14 +- 5 files changed, 304 insertions(+), 166 deletions(-) create mode 100644 plugins/osi-features/acf-fields/group_68381f7bdc12b.json diff --git a/plugins/osi-features/acf-fields/group_68381f7bdc12b.json b/plugins/osi-features/acf-fields/group_68381f7bdc12b.json new file mode 100644 index 0000000..5f3c54a --- /dev/null +++ b/plugins/osi-features/acf-fields/group_68381f7bdc12b.json @@ -0,0 +1,74 @@ +{ + "key": "group_68381f7bdc12b", + "title": "AI Template Toggle", + "fields": [ + { + "key": "field_68381f7c701f6", + "label": "Use AI Header", + "name": "osi_use_ai_header", + "aria-label": "", + "type": "true_false", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "relevanssi_exclude": 0, + "message": "This will use any menu named 'ai' for the menu when active", + "default_value": 0, + "allow_in_bindings": 0, + "ui": 0, + "ui_on_text": "", + "ui_off_text": "" + }, + { + "key": "field_68381fc3701f8", + "label": "Use AI Footer", + "name": "osi_use_ai_footer", + "aria-label": "", + "type": "true_false", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "relevanssi_exclude": 0, + "message": "When selected this will use the ai footer, you can edit the footer in reusable blocks.", + "default_value": 0, + "allow_in_bindings": 0, + "ui": 0, + "ui_on_text": "", + "ui_off_text": "" + } + ], + "location": [ + [ + { + "param": "post_type", + "operator": "==", + "value": "page" + }, + { + "param": "post_template", + "operator": "==", + "value": "templates\/ai-wide.php" + } + ] + ], + "menu_order": 0, + "position": "normal", + "style": "default", + "label_placement": "top", + "instruction_placement": "label", + "hide_on_screen": "", + "active": true, + "description": "", + "show_in_rest": 0, + "modified": 1748508671 +} diff --git a/plugins/osi-features/acf-fields/post_type_672acc9b32c0c.json b/plugins/osi-features/acf-fields/post_type_672acc9b32c0c.json index c1ce8c6..558f4a1 100644 --- a/plugins/osi-features/acf-fields/post_type_672acc9b32c0c.json +++ b/plugins/osi-features/acf-fields/post_type_672acc9b32c0c.json @@ -1,5 +1,5 @@ { - "key": "post_type_672acc9b32c0c", + "key": "group_6414a33c7e529", "title": "Supporters", "menu_order": 0, "active": true, diff --git a/themes/osi/footer-ai.php b/themes/osi/footer-ai.php index 9a860c9..c678f86 100755 --- a/themes/osi/footer-ai.php +++ b/themes/osi/footer-ai.php @@ -8,173 +8,31 @@ * @package osi */ -// Get the footer icon -$image_url = get_template_directory_uri() . '/assets/img/osi-horizontal-white.svg'; - -// Compile the block markup for the footer -$footer_block = << - - -HTML; +$footer_block_id = create_or_find_ai_footer_block_content(); ?> - - + diff --git a/themes/osi/inc/block-patterns.php b/themes/osi/inc/block-patterns.php index e69de29..3b0c033 100644 --- a/themes/osi/inc/block-patterns.php +++ b/themes/osi/inc/block-patterns.php @@ -0,0 +1,198 @@ + __( 'Hero Section', 'osi' ), + 'description' => __( 'A full-width hero section with a title and subtitle.', 'osi' ), + 'content' => ' +
+

Welcome to Our Site

+ + + +

This is a simple hero section with a title and subtitle.

+
+ ', + ) + ); +} + +/** + * Create the base AI footer reusable block programmatically. + * + * @return integer + */ +function create_or_find_ai_footer_block_content(): int { + $title = 'OSI AI Footer'; + $slug = sanitize_title( $title ); + + // Check if block already exists + $existing = get_page_by_path( $slug, OBJECT, 'wp_block' ); + if ( $existing ) { + return $existing->ID; + } + + $image_url = get_template_directory_uri() . '/assets/img/osi-horizontal-white.svg'; + + // Compile the block markup for the footer + $block_content = << + + +HTML; + + $post_id = wp_insert_post( + array( + 'post_title' => $title, + 'post_name' => $slug, + 'post_type' => 'wp_block', + 'post_status' => 'publish', + 'post_content' => $block_content, + ) + ); + + return $post_id; +} +// add_action( 'init', 'create_reusable_block_programmatically' ); diff --git a/themes/osi/templates/ai-wide.php b/themes/osi/templates/ai-wide.php index bf1e062..e8b8520 100644 --- a/themes/osi/templates/ai-wide.php +++ b/themes/osi/templates/ai-wide.php @@ -4,8 +4,12 @@ Template Post Type: page Description: Custom template for full width */ - -get_header( 'ai' ); ?> +if ( osi_field_check( 'osi_use_ai_header' ) && true === (bool) osi_get_valid_field( 'osi_use_ai_header' ) ) : + get_header( 'ai' ); +else : + get_header(); +endif; +?>
@@ -23,4 +27,8 @@
Date: Thu, 29 May 2025 10:53:25 +0100 Subject: [PATCH 2/5] House Keeping --- .../acf-fields/post_type_672acc9b32c0c.json | 2 +- themes/osi/footer-ai.php | 4 ++-- themes/osi/inc/block-patterns.php | 22 +------------------ 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/plugins/osi-features/acf-fields/post_type_672acc9b32c0c.json b/plugins/osi-features/acf-fields/post_type_672acc9b32c0c.json index 558f4a1..c1ce8c6 100644 --- a/plugins/osi-features/acf-fields/post_type_672acc9b32c0c.json +++ b/plugins/osi-features/acf-fields/post_type_672acc9b32c0c.json @@ -1,5 +1,5 @@ { - "key": "group_6414a33c7e529", + "key": "post_type_672acc9b32c0c", "title": "Supporters", "menu_order": 0, "active": true, diff --git a/themes/osi/footer-ai.php b/themes/osi/footer-ai.php index c678f86..8d2064e 100755 --- a/themes/osi/footer-ai.php +++ b/themes/osi/footer-ai.php @@ -8,7 +8,7 @@ * @package osi */ -$footer_block_id = create_or_find_ai_footer_block_content(); +$footer_block_id = osi_create_or_find_ai_footer_block_content(); ?>