From 17c7efbecc3c278d80b38852f841aad6e196a7be Mon Sep 17 00:00:00 2001 From: Szymon Kasprzyk Date: Tue, 31 Mar 2026 09:43:07 +0200 Subject: [PATCH 1/3] allows menu selection in vf hero blocks and templates --- .../group_vf_wp_hero_group.json | 34 ++++++- .../vf-hero-container-custom-blog/index.php | 15 +++ .../template.php | 10 +- .../group_vf_wp_hero_group.json | 34 ++++++- .../vf-hero-container-secondary/index.php | 15 +++ .../vf-hero-container-secondary/template.php | 10 +- .../group_vf_wp_hero_group.json | 34 ++++++- .../plugins/vf-hero-container/index.php | 15 +++ .../plugins/vf-hero-container/template.php | 9 ++ .../plugins/vf-navigation-container/index.php | 97 ++++++++++++++++++- .../vf-navigation-container/template.php | 48 +++++---- wp-content/themes/vf-wp-groups/archive.php | 6 +- wp-content/themes/vf-wp-groups/author.php | 6 +- .../vf-wp-groups/functions/groups-theme.php | 14 ++- wp-content/themes/vf-wp-groups/index.php | 6 +- wp-content/themes/vf-wp-groups/singular.php | 6 +- .../group_vf_wp_groups_header.json | 42 +++++++- .../vf-wp-groups-header/index.php | 15 +++ .../vf-wp-groups-header/vf-navigation.php | 46 +++++---- .../themes/vf-wp/blocks/vfwp-hero/acf.json | 34 ++++++- .../themes/vf-wp/blocks/vfwp-hero/index.php | 16 +++ .../vf-wp/blocks/vfwp-hero/template.php | 17 +++- .../vf-wp/template-secondary-hero-ebi.php | 6 +- .../vf-wp/template-secondary-hero-embl.php | 6 +- 24 files changed, 460 insertions(+), 81 deletions(-) diff --git a/wp-content/plugins/vf-hero-container-custom-blog/group_vf_wp_hero_group.json b/wp-content/plugins/vf-hero-container-custom-blog/group_vf_wp_hero_group.json index e03a26950..5a7c93968 100644 --- a/wp-content/plugins/vf-hero-container-custom-blog/group_vf_wp_hero_group.json +++ b/wp-content/plugins/vf-hero-container-custom-blog/group_vf_wp_hero_group.json @@ -206,6 +206,36 @@ "ui_on_text": "", "ui_off_text": "" }, + { + "key": "field_67ea9901b0a03", + "label": "Navigation menu", + "name": "vf_navigation_menu", + "type": "select", + "instructions": "Choose which menu to display when navigation is enabled.", + "required": 0, + "conditional_logic": [ + [ + { + "field": "field_621c9cc1c7da0", + "operator": "==", + "value": "1" + } + ] + ], + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "choices": {}, + "default_value": "", + "allow_null": 0, + "multiple": 0, + "ui": 1, + "return_format": "value", + "ajax": 0, + "placeholder": "" + }, { "key": "field_621c9cc1c7e36", "label": "Heading link", @@ -239,5 +269,5 @@ "hide_on_screen": "", "active": true, "description": "VF-Hero container for blog pages", - "modified": 1646044300 -} \ No newline at end of file + "modified": 1774955400 +} diff --git a/wp-content/plugins/vf-hero-container-custom-blog/index.php b/wp-content/plugins/vf-hero-container-custom-blog/index.php index b784f2c15..234a30f32 100644 --- a/wp-content/plugins/vf-hero-container-custom-blog/index.php +++ b/wp-content/plugins/vf-hero-container-custom-blog/index.php @@ -36,6 +36,10 @@ public function __construct(array $params = array()) { 'acf/settings/load_json', array($this, 'acf_settings_load_json') ); + add_filter( + 'acf/load_field/name=vf_navigation_menu', + array($this, 'acf_load_navigation_menu') + ); } // public function template_callback($block, $content, $is_preview = false, $acf_id) { @@ -50,6 +54,17 @@ public function acf_settings_load_json($paths) { return $paths; } + public function acf_load_navigation_menu($field) { + $field['choices'] = class_exists('VF_Navigation') + ? VF_Navigation::get_navigation_menu_choices() + : array(); + $field['default_value'] = class_exists('VF_Navigation') + ? VF_Navigation::get_primary_menu_source() + : ''; + + return $field; + } + } // VF_WP_Hero_Blog $plugin = new VF_WP_Hero_Blog( diff --git a/wp-content/plugins/vf-hero-container-custom-blog/template.php b/wp-content/plugins/vf-hero-container-custom-blog/template.php index ca672332b..bd3bed10f 100644 --- a/wp-content/plugins/vf-hero-container-custom-blog/template.php +++ b/wp-content/plugins/vf-hero-container-custom-blog/template.php @@ -10,6 +10,10 @@ $hero_subheading = get_field('vf_hero_subheading'); $hero_heading = get_field('vf_hero_heading'); $hero_url = get_field('vf_hero_url'); +$navigation_enable = get_field('vf_navigation_enable'); +$navigation_menu_source = class_exists('VF_Navigation') + ? VF_Navigation::resolve_menu_source(get_field('vf_navigation_menu')) + : 'location:primary'; $spacing = get_field('vf_hero_spacing'); $spacing_class = "| vf-hero--"; @@ -91,4 +95,8 @@ - + diff --git a/wp-content/plugins/vf-hero-container-secondary/group_vf_wp_hero_group.json b/wp-content/plugins/vf-hero-container-secondary/group_vf_wp_hero_group.json index 6b28d2273..42b0ac1b7 100644 --- a/wp-content/plugins/vf-hero-container-secondary/group_vf_wp_hero_group.json +++ b/wp-content/plugins/vf-hero-container-secondary/group_vf_wp_hero_group.json @@ -220,6 +220,36 @@ "ui": 1, "ui_on_text": "", "ui_off_text": "" + }, + { + "key": "field_67ea9901b0a02", + "label": "Navigation menu", + "name": "vf_navigation_menu", + "type": "select", + "instructions": "Choose which menu to display when navigation is enabled.", + "required": 0, + "conditional_logic": [ + [ + { + "field": "field_614326ab47614", + "operator": "==", + "value": "1" + } + ] + ], + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "choices": {}, + "default_value": "", + "allow_null": 0, + "multiple": 0, + "ui": 1, + "return_format": "value", + "ajax": 0, + "placeholder": "" } ], "location": [ @@ -239,5 +269,5 @@ "hide_on_screen": "", "active": true, "description": "VF-Hero container", - "modified": 1642150579 -} \ No newline at end of file + "modified": 1774955400 +} diff --git a/wp-content/plugins/vf-hero-container-secondary/index.php b/wp-content/plugins/vf-hero-container-secondary/index.php index 396dfa271..79339abb2 100644 --- a/wp-content/plugins/vf-hero-container-secondary/index.php +++ b/wp-content/plugins/vf-hero-container-secondary/index.php @@ -36,6 +36,10 @@ public function __construct(array $params = array()) { 'acf/settings/load_json', array($this, 'acf_settings_load_json') ); + add_filter( + 'acf/load_field/name=vf_navigation_menu', + array($this, 'acf_load_navigation_menu') + ); } // public function template_callback($block, $content, $is_preview = false, $acf_id) { @@ -50,6 +54,17 @@ public function acf_settings_load_json($paths) { return $paths; } + public function acf_load_navigation_menu($field) { + $field['choices'] = class_exists('VF_Navigation') + ? VF_Navigation::get_navigation_menu_choices() + : array(); + $field['default_value'] = class_exists('VF_Navigation') + ? VF_Navigation::get_primary_menu_source() + : ''; + + return $field; + } + } // VF_WP_Hero_Secondary $plugin = new VF_WP_Hero_Secondary( diff --git a/wp-content/plugins/vf-hero-container-secondary/template.php b/wp-content/plugins/vf-hero-container-secondary/template.php index ca672332b..bd3bed10f 100644 --- a/wp-content/plugins/vf-hero-container-secondary/template.php +++ b/wp-content/plugins/vf-hero-container-secondary/template.php @@ -10,6 +10,10 @@ $hero_subheading = get_field('vf_hero_subheading'); $hero_heading = get_field('vf_hero_heading'); $hero_url = get_field('vf_hero_url'); +$navigation_enable = get_field('vf_navigation_enable'); +$navigation_menu_source = class_exists('VF_Navigation') + ? VF_Navigation::resolve_menu_source(get_field('vf_navigation_menu')) + : 'location:primary'; $spacing = get_field('vf_hero_spacing'); $spacing_class = "| vf-hero--"; @@ -91,4 +95,8 @@ - + diff --git a/wp-content/plugins/vf-hero-container/group_vf_wp_hero_group.json b/wp-content/plugins/vf-hero-container/group_vf_wp_hero_group.json index 3332e8ebd..c7a6e3260 100644 --- a/wp-content/plugins/vf-hero-container/group_vf_wp_hero_group.json +++ b/wp-content/plugins/vf-hero-container/group_vf_wp_hero_group.json @@ -225,6 +225,36 @@ "ui": 1, "ui_on_text": "", "ui_off_text": "" + }, + { + "key": "field_67ea9901b0a01", + "label": "Navigation menu", + "name": "vf_navigation_menu", + "type": "select", + "instructions": "Choose which menu to display when navigation is enabled.", + "required": 0, + "conditional_logic": [ + [ + { + "field": "field_603b3d040391d", + "operator": "==", + "value": "1" + } + ] + ], + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "choices": {}, + "default_value": "", + "allow_null": 0, + "multiple": 0, + "ui": 1, + "return_format": "value", + "ajax": 0, + "placeholder": "" } ], "location": [ @@ -244,5 +274,5 @@ "hide_on_screen": "", "active": true, "description": "VF-Hero container", - "modified": 1635940900 -} \ No newline at end of file + "modified": 1774955400 +} diff --git a/wp-content/plugins/vf-hero-container/index.php b/wp-content/plugins/vf-hero-container/index.php index 1e386cea8..2afbd2db5 100644 --- a/wp-content/plugins/vf-hero-container/index.php +++ b/wp-content/plugins/vf-hero-container/index.php @@ -36,6 +36,10 @@ public function __construct(array $params = array()) { 'acf/settings/load_json', array($this, 'acf_settings_load_json') ); + add_filter( + 'acf/load_field/name=vf_navigation_menu', + array($this, 'acf_load_navigation_menu') + ); } // public function template_callback($block, $content, $is_preview = false, $acf_id) { @@ -50,6 +54,17 @@ public function acf_settings_load_json($paths) { return $paths; } + public function acf_load_navigation_menu($field) { + $field['choices'] = class_exists('VF_Navigation') + ? VF_Navigation::get_navigation_menu_choices() + : array(); + $field['default_value'] = class_exists('VF_Navigation') + ? VF_Navigation::get_primary_menu_source() + : ''; + + return $field; + } + } // VF_WP_Hero $plugin = new VF_WP_Hero( diff --git a/wp-content/plugins/vf-hero-container/template.php b/wp-content/plugins/vf-hero-container/template.php index 9e895d4e4..aaaf4bd1a 100644 --- a/wp-content/plugins/vf-hero-container/template.php +++ b/wp-content/plugins/vf-hero-container/template.php @@ -10,6 +10,10 @@ $hero_subheading = get_field('vf_hero_subheading'); $hero_heading = get_field('vf_hero_heading'); $search = get_field('vf_hero_search'); +$navigation_enable = get_field('vf_navigation_enable'); +$navigation_menu_source = class_exists('VF_Navigation') + ? VF_Navigation::resolve_menu_source(get_field('vf_navigation_menu')) + : 'location:primary'; $theme = wp_get_theme(); $spacing = get_field('vf_hero_spacing'); $spacing_class = "| vf-hero--"; @@ -171,3 +175,8 @@ class="vf-search__button | vf-button vf-button--primary"> + diff --git a/wp-content/plugins/vf-navigation-container/index.php b/wp-content/plugins/vf-navigation-container/index.php index c1b003bda..be0e26132 100644 --- a/wp-content/plugins/vf-navigation-container/index.php +++ b/wp-content/plugins/vf-navigation-container/index.php @@ -16,6 +16,8 @@ class VF_Navigation extends VF_Plugin { + protected static $menu_source_override = null; + protected $file = __FILE__; protected $config = array( @@ -42,11 +44,97 @@ public function __construct(array $params = array()) { } + public static function get_navigation_menu_choices() { + $choices = array(); + $labels = array(); + $menus = wp_get_nav_menus(); + + if (is_array($menus)) { + foreach ($menus as $menu) { + if ( ! $menu instanceof WP_Term) { + continue; + } + + $label = $menu->name; + + if (in_array($label, $labels, true)) { + $label = sprintf(__('%s (menu)', 'vfwp'), $menu->name); + } + + if (in_array($label, $labels, true)) { + $label = sprintf(__('%s (menu #%d)', 'vfwp'), $menu->name, $menu->term_id); + } + + $choices["menu:{$menu->term_id}"] = $label; + $labels[] = $label; + } + } + + return $choices; + } + + public static function get_primary_menu_source() { + $locations = get_nav_menu_locations(); + if (is_array($locations) && ! empty($locations['primary'])) { + return "menu:{$locations['primary']}"; + } + + $menus = wp_get_nav_menus(); + if (is_array($menus)) { + foreach ($menus as $menu) { + if ( + $menu instanceof WP_Term && + in_array(strtolower($menu->name), array('primary', 'primary menu'), true) + ) { + return "menu:{$menu->term_id}"; + } + } + } + + return 'location:primary'; + } + + public static function resolve_menu_source($menu_source = '') { + if ( + is_string($menu_source) && + preg_match('#^(menu|location):.+$#', $menu_source) + ) { + return $menu_source; + } + + return self::get_primary_menu_source(); + } + + public static function get_render_menu_source() { + if ( + is_string(self::$menu_source_override) && + self::$menu_source_override !== '' + ) { + return self::resolve_menu_source(self::$menu_source_override); + } + + return self::resolve_menu_source(get_field('vf_navigation_menu_source')); + } + + public static function render_menu($menu_source = '') { + $previous_menu_source = self::$menu_source_override; + self::$menu_source_override = self::resolve_menu_source($menu_source); + + VF_Plugin::render(self::get_plugin('vf_navigation')); + + self::$menu_source_override = $previous_menu_source; + } + /** * Add VF class to primary menu items */ public function nav_menu_css_class($classes, $item, $args, $depth) { - if (in_array($args->theme_location, array('primary', 'secondary'))) { + $theme_location = isset($args->theme_location) ? $args->theme_location : ''; + + if ( + in_array($theme_location, array('primary', 'secondary')) || + ! empty($args->vf_navigation) + ) { $classes[] = 'vf-navigation__item'; } return $classes; @@ -56,7 +144,12 @@ public function nav_menu_css_class($classes, $item, $args, $depth) { * Add VF class to primary menu items */ public function nav_menu_link_attributes($atts, $item, $args, $depth) { - if (in_array($args->theme_location, array('primary', 'secondary'))) { + $theme_location = isset($args->theme_location) ? $args->theme_location : ''; + + if ( + in_array($theme_location, array('primary', 'secondary')) || + ! empty($args->vf_navigation) + ) { $atts['class'] = 'vf-navigation__link'; } return $atts; diff --git a/wp-content/plugins/vf-navigation-container/template.php b/wp-content/plugins/vf-navigation-container/template.php index 4fe5a38a9..9d175c2bb 100644 --- a/wp-content/plugins/vf-navigation-container/template.php +++ b/wp-content/plugins/vf-navigation-container/template.php @@ -20,32 +20,42 @@ if ( ! defined( 'ABSPATH' ) ) exit; +$menu_source = class_exists('VF_Navigation') + ? VF_Navigation::get_render_menu_source() + : 'location:primary'; + +$menu_args = array( + 'depth' => 1, + 'container' => false, + 'items_wrap' => '%3$s', + 'fallback_cb' => '__return_empty_string', + 'vf_navigation' => true, +); + +if (is_string($menu_source) && strpos($menu_source, 'menu:') === 0) { + $menu_id = (int) substr($menu_source, 5); + if ($menu_id > 0) { + $menu_args['menu'] = $menu_id; + } +} elseif (is_string($menu_source) && strpos($menu_source, 'location:') === 0) { + $location = substr($menu_source, 9); + if ($location) { + $menu_args['theme_location'] = $location; + } +} + +if (empty($menu_args['menu']) && empty($menu_args['theme_location'])) { + $menu_args['theme_location'] = 'primary'; +} + ?> - diff --git a/wp-content/themes/vf-wp-groups/archive.php b/wp-content/themes/vf-wp-groups/archive.php index 7da7d27b3..57ab2926f 100644 --- a/wp-content/themes/vf-wp-groups/archive.php +++ b/wp-content/themes/vf-wp-groups/archive.php @@ -21,9 +21,7 @@ if (class_exists('VF_WP_Hero_Blog')) { VF_Plugin::render(VF_Breadcrumbs::get_plugin('vf_wp_hero_blog')); } - if (class_exists('VF_Navigation')) { - VF_Plugin::render(VF_Navigation::get_plugin('vf_navigation')); - } } +} else { if (class_exists('VF_WP_Groups_Header')) { VF_Plugin::render(VF_Breadcrumbs::get_plugin('vf_wp_groups_header')); @@ -71,4 +69,4 @@ } get_footer(); - ?> \ No newline at end of file + ?> diff --git a/wp-content/themes/vf-wp-groups/author.php b/wp-content/themes/vf-wp-groups/author.php index 7da7d27b3..57ab2926f 100644 --- a/wp-content/themes/vf-wp-groups/author.php +++ b/wp-content/themes/vf-wp-groups/author.php @@ -21,9 +21,7 @@ if (class_exists('VF_WP_Hero_Blog')) { VF_Plugin::render(VF_Breadcrumbs::get_plugin('vf_wp_hero_blog')); } - if (class_exists('VF_Navigation')) { - VF_Plugin::render(VF_Navigation::get_plugin('vf_navigation')); - } } +} else { if (class_exists('VF_WP_Groups_Header')) { VF_Plugin::render(VF_Breadcrumbs::get_plugin('vf_wp_groups_header')); @@ -71,4 +69,4 @@ } get_footer(); - ?> \ No newline at end of file + ?> diff --git a/wp-content/themes/vf-wp-groups/functions/groups-theme.php b/wp-content/themes/vf-wp-groups/functions/groups-theme.php index 33ee2372c..85ce5dc4d 100644 --- a/wp-content/themes/vf-wp-groups/functions/groups-theme.php +++ b/wp-content/themes/vf-wp-groups/functions/groups-theme.php @@ -157,7 +157,12 @@ function_exists('embl_taxonomy') * Add VF class to primary menu items */ public function nav_menu_css_class($classes, $item, $args, $depth) { - if (in_array($args->theme_location, array('primary', 'secondary'))) { + $theme_location = isset($args->theme_location) ? $args->theme_location : ''; + + if ( + in_array($theme_location, array('primary', 'secondary')) || + ! empty($args->vf_navigation) + ) { return ['vf-navigation__item']; } return $classes; @@ -167,7 +172,12 @@ public function nav_menu_css_class($classes, $item, $args, $depth) { * Add VF class to primary menu items */ public function nav_menu_link_attributes($atts, $item, $args, $depth) { - if (in_array($args->theme_location, array('primary', 'secondary'))) { + $theme_location = isset($args->theme_location) ? $args->theme_location : ''; + + if ( + in_array($theme_location, array('primary', 'secondary')) || + ! empty($args->vf_navigation) + ) { $atts['class'] = 'vf-navigation__link'; } return $atts; diff --git a/wp-content/themes/vf-wp-groups/index.php b/wp-content/themes/vf-wp-groups/index.php index c26e7719f..7865709f6 100644 --- a/wp-content/themes/vf-wp-groups/index.php +++ b/wp-content/themes/vf-wp-groups/index.php @@ -24,9 +24,7 @@ if (class_exists('VF_WP_Hero_Blog')) { VF_Plugin::render(VF_Breadcrumbs::get_plugin('vf_wp_hero_blog')); } - if (class_exists('VF_Navigation')) { - VF_Plugin::render(VF_Navigation::get_plugin('vf_navigation')); - } } +} else { if (class_exists('VF_WP_Groups_Header')) { VF_Plugin::render(VF_Breadcrumbs::get_plugin('vf_wp_groups_header')); @@ -199,4 +197,4 @@ function generatePagination(totalPages, currentPage) { } get_footer(); - ?> \ No newline at end of file + ?> diff --git a/wp-content/themes/vf-wp-groups/singular.php b/wp-content/themes/vf-wp-groups/singular.php index a31788b46..0a2686b3e 100644 --- a/wp-content/themes/vf-wp-groups/singular.php +++ b/wp-content/themes/vf-wp-groups/singular.php @@ -23,9 +23,7 @@ if (class_exists('VF_WP_Hero_Blog')) { VF_Plugin::render(VF_Breadcrumbs::get_plugin('vf_wp_hero_blog')); } - if (class_exists('VF_Navigation')) { - VF_Plugin::render(VF_Navigation::get_plugin('vf_navigation')); - } } +} else { if (class_exists('VF_WP_Groups_Header')) { VF_Plugin::render(VF_Breadcrumbs::get_plugin('vf_wp_groups_header')); @@ -119,4 +117,4 @@ } get_footer(); - ?> \ No newline at end of file + ?> diff --git a/wp-content/themes/vf-wp-groups/vf-wp-groups-header/group_vf_wp_groups_header.json b/wp-content/themes/vf-wp-groups/vf-wp-groups-header/group_vf_wp_groups_header.json index fc8dab09a..b39ed6987 100644 --- a/wp-content/themes/vf-wp-groups/vf-wp-groups-header/group_vf_wp_groups_header.json +++ b/wp-content/themes/vf-wp-groups/vf-wp-groups-header/group_vf_wp_groups_header.json @@ -170,6 +170,44 @@ "return_format": "value", "ajax": 0, "placeholder": "" + }, + { + "key": "field_67ea9901b0a04", + "label": "Navigation", + "name": "", + "type": "tab", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "placement": "top", + "endpoint": 0 + }, + { + "key": "field_67ea9901b0a05", + "label": "Navigation menu", + "name": "vf_navigation_menu", + "type": "select", + "instructions": "Choose which menu to display in the header navigation.", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "choices": {}, + "default_value": "", + "allow_null": 0, + "multiple": 0, + "ui": 1, + "return_format": "value", + "ajax": 0, + "placeholder": "" } ], "location": [ @@ -189,5 +227,5 @@ "hide_on_screen": "", "active": true, "description": "VF-WP Groups theme global container.", - "modified": 1618817224 -} \ No newline at end of file + "modified": 1774955400 +} diff --git a/wp-content/themes/vf-wp-groups/vf-wp-groups-header/index.php b/wp-content/themes/vf-wp-groups/vf-wp-groups-header/index.php index 4f64151e4..ffdb3ecbd 100644 --- a/wp-content/themes/vf-wp-groups/vf-wp-groups-header/index.php +++ b/wp-content/themes/vf-wp-groups/vf-wp-groups-header/index.php @@ -50,6 +50,10 @@ private function init() { array($this, 'filter_hero_text_cleanup'), 8, 1 ); + add_filter( + 'acf/load_field/name=vf_navigation_menu', + array($this, 'acf_load_navigation_menu') + ); /** * @deprecated add_filter( @@ -220,6 +224,17 @@ public function filter_hero_text_cleanup($text) { return $text; } + public function acf_load_navigation_menu($field) { + $field['choices'] = class_exists('VF_Navigation') + ? VF_Navigation::get_navigation_menu_choices() + : array(); + $field['default_value'] = class_exists('VF_Navigation') + ? VF_Navigation::get_primary_menu_source() + : ''; + + return $field; + } + /** * @deprecated Default filter for hero text diff --git a/wp-content/themes/vf-wp-groups/vf-wp-groups-header/vf-navigation.php b/wp-content/themes/vf-wp-groups/vf-wp-groups-header/vf-navigation.php index cd01538c7..7bf567244 100644 --- a/wp-content/themes/vf-wp-groups/vf-wp-groups-header/vf-navigation.php +++ b/wp-content/themes/vf-wp-groups/vf-wp-groups-header/vf-navigation.php @@ -2,29 +2,39 @@ if ( ! defined( 'ABSPATH' ) ) exit; -?> -