Skip to content

Commit

Permalink
only append social links to a navigation block if the block opts in
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Oct 5, 2021
1 parent 21c1ed4 commit 3a9f0f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion blockbase/block-template-parts/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<!-- wp:site-logo /-->
<!-- wp:site-title /-->
<!-- wp:site-tagline {"fontSize":"tiny"} /-->
<!-- wp:navigation {"isResponsive":true,"__unstableLocation":"primary"} /-->
<!-- wp:navigation {"isResponsive":true,"__unstableLocation":"primary","__unstableSocialLinks":"social"} /-->
</div>
<!-- /wp:group -->
16 changes: 13 additions & 3 deletions blockbase/inc/social-navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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 );
}
Expand Down

0 comments on commit 3a9f0f5

Please sign in to comment.