LLMS_Nav_Menus::render_block( string $block_content, array $block )
Render the navigation link block.
Parameters Parameters
- $block_content
-
(string) (Required) Block content.
- $block
-
(array) (Required) Block data.
Return Return
(string)
Source Source
File: includes/class.llms.nav.menus.php
public function render_block( string $block_content, array $block ): string {
if ( 'llms/navigation-link' !== $block['blockName'] ) {
return $block_content;
}
$items = $this->filter_nav_items( $this->get_nav_items() );
$page = $block['attrs']['page'] ?? 'dashboard';
if ( ! $page ) {
return '';
}
$url = $items[ $page ]['url'] ?? '';
// Support conditional URLs, e.g. when user logged in or not.
if ( ! $url ) {
return '';
}
$label = $block['attrs']['label'] ?? $items[ $page ]['label'] ?? '';
$html = '<li class="wp-block-navigation-item">';
$html .= '<a href="' . esc_url( $url ) . '" class="wp-block-navigation-item__content">';
$html .= '<span class="wp-block-navigation-item__label">';
$html .= esc_html( $label );
$html .= '</span></a></li>';
return $html;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 7.3.0 | Add block name check since filter changed. |
| 7.2.0 | Introduced. |