From 3a9f0f5a6c98b3866d5b08e1da588a7bd30f3d58 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Tue, 5 Oct 2021 13:06:54 +0100 Subject: [PATCH] only append social links to a navigation block if the block opts in --- blockbase/block-template-parts/header.html | 2 +- blockbase/inc/social-navigation.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/blockbase/block-template-parts/header.html b/blockbase/block-template-parts/header.html index ee9829a999..6eb5ee742e 100644 --- a/blockbase/block-template-parts/header.html +++ b/blockbase/block-template-parts/header.html @@ -3,6 +3,6 @@ - + diff --git a/blockbase/inc/social-navigation.php b/blockbase/inc/social-navigation.php index a4be60a410..b29da176a5 100644 --- a/blockbase/inc/social-navigation.php +++ b/blockbase/inc/social-navigation.php @@ -23,12 +23,22 @@ function blockbase_condition_to_render_social_menu( $block ) { return false; } + // The block should have a social links attribute. + if ( empty( $block['attrs']['__unstableSocialLinks'] ) ) { + return false; + } + return true; } -function get_social_menu_as_social_links_block() { +function get_social_menu_as_social_links_block( $block ) { + if ( empty( $block['attrs']['__unstableSocialLinks'] ) ) { + return false; + } + + $social_links_location = $block['attrs']['__unstableSocialLinks']; $nav_menu_locations = get_nav_menu_locations(); - $social_menu_id = $nav_menu_locations['social']; + $social_menu_id = $nav_menu_locations[ $social_links_location ]; $class_name = 'is-style-logos-only'; if( ! empty( $block['attrs']['itemsJustification'] ) ) { $class_name .= ' items-justified-' . $block['attrs']['itemsJustification']; @@ -58,7 +68,7 @@ function append_social_links_block_to_primary_navigation( $primary_navigation, $ function blockbase_social_menu_render( $block_content, $block ) { if ( blockbase_condition_to_render_social_menu( $block ) ) { - $social_links_block = get_social_menu_as_social_links_block(); + $social_links_block = get_social_menu_as_social_links_block( $block ); return append_social_links_block_to_primary_navigation( $block_content, $social_links_block ); }