get_raw_data(); $social_links_icon_color_value = 'var(--wp--custom--color--primary)'; $social_links_icon_color = 'primary'; if ( blockbase_theme_has_navigation_social_links_settings( $theme_data ) ) { $social_links_icon_color_value = $theme_data['settings']['custom']['navigation/social-links']['color']['text']; $social_links_icon_color = preg_replace( '/var\(--wp--custom--color--(.+)\)/', '$0 --> $2 $1', $social_links_icon_color_value ); } $social_links_content = '
'; return do_blocks( $social_links_content ); } function append_social_links_block( $parent_content, $social_links_block ) { if ( empty( $parent_content ) ) { return $social_links_block; } $dom = new domDocument; $domXPath = new DomXPath( $dom ); // Since the nav block uses HTML5 element names, we need to suppress the warnings it sends when we loadHTML with HTML5 elements. libxml_use_internal_errors( true ); $dom->loadHTML( '' . $parent_content ); $wp_block_navigation__container = $dom->getElementsByTagName( 'ul' )->item( 0 )->parentNode; $social_links_node = $dom->createDocumentFragment(); $social_links_node->appendXML( $social_links_block ); if ( ! empty( $wp_block_navigation__container ) ) { $wp_block_navigation__container->appendChild( $social_links_node ); } $navigation_block = $dom->getElementsByTagName( 'nav' )->item( 0 ); return $dom->saveXML( $navigation_block ); } function blockbase_social_menu_render( $block_content, $block ) { if ( blockbase_condition_to_render_social_menu( $block_content, $block ) ) { $social_links_block = get_social_menu_as_social_links_block( $block ); return append_social_links_block( $block_content, $social_links_block ); } return $block_content; } /** * Hijack the render of the menu block to inject a social menu. */ add_filter( 'render_block', 'blockbase_social_menu_render', 10, 2 );