| 1 |
<?php |
| 2 |
/** |
| 3 |
* Server-side rendering of the `gutenify/section-title` block. |
| 4 |
* |
| 5 |
* @package WordPress |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Renders the `gutenify/section-title` block on the server. |
| 10 |
* |
| 11 |
* @param array $attributes Block attributes. |
| 12 |
* |
| 13 |
* @return string Returns the filtered post title for the current post wrapped inside "h1" tags. |
| 14 |
*/ |
| 15 |
function gutenify_render_block_navigation_menu( $attributes ) { |
| 16 |
$content_justification = ! empty( $attributes['contentJustification'] ) ? 'is-content-justification-' . $attributes['contentJustification'] : ''; |
| 17 |
ob_start(); |
| 18 |
if ( has_nav_menu( 'primary' ) ) : ?> |
| 19 |
<div class="wp-block-gutenify-navitation-menu <?php echo esc_attr( $content_justification ); ?>"> |
| 20 |
<div class="gutenify-navitation-menu-section"> |
| 21 |
<nav id="site-navigation" class="primary-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Primary menu', 'hello-gutenify' ); ?>"> |
| 22 |
<div class="menu-button-container"> |
| 23 |
<button id="primary-mobile-menu" class="button" aria-controls="primary-menu-list" aria-expanded="false"> |
| 24 |
<span class="dropdown-icon open"> |
| 25 |
<i class="ion-navicon-round"></i> |
| 26 |
</span> |
| 27 |
<span class="dropdown-icon close"> |
| 28 |
<i class="ion-close"></i> |
| 29 |
</span> |
| 30 |
</button><!-- #primary-mobile-menu --> |
| 31 |
</div><!-- .menu-button-container --> |
| 32 |
<?php |
| 33 |
wp_nav_menu( |
| 34 |
array( |
| 35 |
'theme_location' => 'primary', |
| 36 |
'menu_class' => 'menu-wrapper', |
| 37 |
'container_class' => 'primary-menu-container', |
| 38 |
'items_wrap' => '<ul id="primary-menu-list" class="%2$s">%3$s</ul>', |
| 39 |
'fallback_cb' => false, |
| 40 |
) |
| 41 |
); |
| 42 |
?> |
| 43 |
</nav><!-- #site-navigation --> |
| 44 |
</div> |
| 45 |
</div> |
| 46 |
<?php |
| 47 |
endif; |
| 48 |
$output = ob_get_contents(); |
| 49 |
ob_end_clean(); |
| 50 |
return $output; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Registers the `gutenify/section-title` block on the server. |
| 55 |
*/ |
| 56 |
function gutenify_register_block_navigation_menu() { |
| 57 |
// Return early if this function does not exist. |
| 58 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
// Load attributes from block.json. |
| 63 |
ob_start(); |
| 64 |
include GUTENIFY_PLUGIN_DIR . 'src/blocks/section-title/block.json'; |
| 65 |
$metadata = json_decode( ob_get_clean(), true ); |
| 66 |
register_block_type( |
| 67 |
'gutenify/navigation-menu', |
| 68 |
array( |
| 69 |
'render_callback' => 'gutenify_render_block_navigation_menu', |
| 70 |
'editor_script' => 'gutenify-editor', |
| 71 |
'editor_style' => 'gutenify-editor', |
| 72 |
'style' => 'gutenify-frontend', |
| 73 |
'attributes' => $metadata['attributes'], |
| 74 |
) |
| 75 |
); |
| 76 |
} |
| 77 |
add_action( 'init', 'gutenify_register_block_navigation_menu' ); |
| 78 |
|