Edit File by line
/home/zeestwma/redstone.../wp-inclu.../blocks
File: navigation.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/navigation` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Helper functions used to render the navigation block.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.5.0
[10] Fix | Delete
*/
[11] Fix | Delete
class WP_Navigation_Block_Renderer {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Used to determine whether or not a navigation has submenus.
[15] Fix | Delete
*
[16] Fix | Delete
* @since 6.5.0
[17] Fix | Delete
*/
[18] Fix | Delete
private static $has_submenus = false;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Used to determine which blocks need an <li> wrapper.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 6.5.0
[24] Fix | Delete
*
[25] Fix | Delete
* @var array
[26] Fix | Delete
*/
[27] Fix | Delete
private static $needs_list_item_wrapper = array(
[28] Fix | Delete
'core/site-title',
[29] Fix | Delete
'core/site-logo',
[30] Fix | Delete
'core/social-links',
[31] Fix | Delete
);
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Keeps track of all the navigation names that have been seen.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 6.5.0
[37] Fix | Delete
*
[38] Fix | Delete
* @var array
[39] Fix | Delete
*/
[40] Fix | Delete
private static $seen_menu_names = array();
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Returns whether or not this is responsive navigation.
[44] Fix | Delete
*
[45] Fix | Delete
* @since 6.5.0
[46] Fix | Delete
*
[47] Fix | Delete
* @param array $attributes The block attributes.
[48] Fix | Delete
* @return bool Returns whether or not this is responsive navigation.
[49] Fix | Delete
*/
[50] Fix | Delete
private static function is_responsive( $attributes ) {
[51] Fix | Delete
/**
[52] Fix | Delete
* This is for backwards compatibility after the `isResponsive` attribute was been removed.
[53] Fix | Delete
*/
[54] Fix | Delete
[55] Fix | Delete
$has_old_responsive_attribute = ! empty( $attributes['isResponsive'] ) && $attributes['isResponsive'];
[56] Fix | Delete
return isset( $attributes['overlayMenu'] ) && 'never' !== $attributes['overlayMenu'] || $has_old_responsive_attribute;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Returns whether or not a navigation has a submenu.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 6.5.0
[63] Fix | Delete
*
[64] Fix | Delete
* @param WP_Block_List $inner_blocks The list of inner blocks.
[65] Fix | Delete
* @return bool Returns whether or not a navigation has a submenu and also sets the member variable.
[66] Fix | Delete
*/
[67] Fix | Delete
private static function has_submenus( $inner_blocks ) {
[68] Fix | Delete
if ( true === static::$has_submenus ) {
[69] Fix | Delete
return static::$has_submenus;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
foreach ( $inner_blocks as $inner_block ) {
[73] Fix | Delete
// If this is a page list then work out if any of the pages have children.
[74] Fix | Delete
if ( 'core/page-list' === $inner_block->name ) {
[75] Fix | Delete
$all_pages = get_pages(
[76] Fix | Delete
array(
[77] Fix | Delete
'sort_column' => 'menu_order,post_title',
[78] Fix | Delete
'order' => 'asc',
[79] Fix | Delete
)
[80] Fix | Delete
);
[81] Fix | Delete
foreach ( (array) $all_pages as $page ) {
[82] Fix | Delete
if ( $page->post_parent ) {
[83] Fix | Delete
static::$has_submenus = true;
[84] Fix | Delete
break;
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
}
[88] Fix | Delete
// If this is a navigation submenu then we know we have submenus.
[89] Fix | Delete
if ( 'core/navigation-submenu' === $inner_block->name ) {
[90] Fix | Delete
static::$has_submenus = true;
[91] Fix | Delete
break;
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
return static::$has_submenus;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Determine whether the navigation blocks is interactive.
[100] Fix | Delete
*
[101] Fix | Delete
* @since 6.5.0
[102] Fix | Delete
*
[103] Fix | Delete
* @param array $attributes The block attributes.
[104] Fix | Delete
* @param WP_Block_List $inner_blocks The list of inner blocks.
[105] Fix | Delete
* @return bool Returns whether or not to load the view script.
[106] Fix | Delete
*/
[107] Fix | Delete
private static function is_interactive( $attributes, $inner_blocks ) {
[108] Fix | Delete
$has_submenus = static::has_submenus( $inner_blocks );
[109] Fix | Delete
$is_responsive_menu = static::is_responsive( $attributes );
[110] Fix | Delete
return ( $has_submenus && ( $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ) ) || $is_responsive_menu;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Returns whether or not a block needs a list item wrapper.
[115] Fix | Delete
*
[116] Fix | Delete
* @since 6.5.0
[117] Fix | Delete
*
[118] Fix | Delete
* @param WP_Block $block The block.
[119] Fix | Delete
* @return bool Returns whether or not a block needs a list item wrapper.
[120] Fix | Delete
*/
[121] Fix | Delete
private static function does_block_need_a_list_item_wrapper( $block ) {
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Filter the list of blocks that need a list item wrapper.
[125] Fix | Delete
*
[126] Fix | Delete
* Affords the ability to customize which blocks need a list item wrapper when rendered
[127] Fix | Delete
* within a core/navigation block.
[128] Fix | Delete
* This is useful for blocks that are not list items but should be wrapped in a list
[129] Fix | Delete
* item when used as a child of a navigation block.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 6.5.0
[132] Fix | Delete
*
[133] Fix | Delete
* @param array $needs_list_item_wrapper The list of blocks that need a list item wrapper.
[134] Fix | Delete
*/
[135] Fix | Delete
$needs_list_item_wrapper = apply_filters( 'block_core_navigation_listable_blocks', static::$needs_list_item_wrapper );
[136] Fix | Delete
[137] Fix | Delete
return in_array( $block->name, $needs_list_item_wrapper, true );
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Returns the markup for a single inner block.
[142] Fix | Delete
*
[143] Fix | Delete
* @since 6.5.0
[144] Fix | Delete
*
[145] Fix | Delete
* @param WP_Block $inner_block The inner block.
[146] Fix | Delete
* @return string Returns the markup for a single inner block.
[147] Fix | Delete
*/
[148] Fix | Delete
private static function get_markup_for_inner_block( $inner_block ) {
[149] Fix | Delete
$inner_block_content = $inner_block->render();
[150] Fix | Delete
if ( ! empty( $inner_block_content ) ) {
[151] Fix | Delete
if ( static::does_block_need_a_list_item_wrapper( $inner_block ) ) {
[152] Fix | Delete
return '<li class="wp-block-navigation-item">' . $inner_block_content . '</li>';
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
return $inner_block_content;
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Returns the html for the inner blocks of the navigation block.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 6.5.0
[163] Fix | Delete
*
[164] Fix | Delete
* @param array $attributes The block attributes.
[165] Fix | Delete
* @param WP_Block_List $inner_blocks The list of inner blocks.
[166] Fix | Delete
* @return string Returns the html for the inner blocks of the navigation block.
[167] Fix | Delete
*/
[168] Fix | Delete
private static function get_inner_blocks_html( $attributes, $inner_blocks ) {
[169] Fix | Delete
$has_submenus = static::has_submenus( $inner_blocks );
[170] Fix | Delete
$is_interactive = static::is_interactive( $attributes, $inner_blocks );
[171] Fix | Delete
[172] Fix | Delete
$style = static::get_styles( $attributes );
[173] Fix | Delete
$class = static::get_classes( $attributes );
[174] Fix | Delete
$container_attributes = get_block_wrapper_attributes(
[175] Fix | Delete
array(
[176] Fix | Delete
'class' => 'wp-block-navigation__container ' . $class,
[177] Fix | Delete
'style' => $style,
[178] Fix | Delete
)
[179] Fix | Delete
);
[180] Fix | Delete
[181] Fix | Delete
$inner_blocks_html = '';
[182] Fix | Delete
$is_list_open = false;
[183] Fix | Delete
[184] Fix | Delete
foreach ( $inner_blocks as $inner_block ) {
[185] Fix | Delete
$inner_block_markup = static::get_markup_for_inner_block( $inner_block );
[186] Fix | Delete
$p = new WP_HTML_Tag_Processor( $inner_block_markup );
[187] Fix | Delete
$is_list_item = $p->next_tag( 'LI' );
[188] Fix | Delete
[189] Fix | Delete
if ( $is_list_item && ! $is_list_open ) {
[190] Fix | Delete
$is_list_open = true;
[191] Fix | Delete
$inner_blocks_html .= sprintf(
[192] Fix | Delete
'<ul %1$s>',
[193] Fix | Delete
$container_attributes
[194] Fix | Delete
);
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
if ( ! $is_list_item && $is_list_open ) {
[198] Fix | Delete
$is_list_open = false;
[199] Fix | Delete
$inner_blocks_html .= '</ul>';
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
$inner_blocks_html .= $inner_block_markup;
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
if ( $is_list_open ) {
[206] Fix | Delete
$inner_blocks_html .= '</ul>';
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
// Add directives to the submenu if needed.
[210] Fix | Delete
if ( $has_submenus && $is_interactive ) {
[211] Fix | Delete
$tags = new WP_HTML_Tag_Processor( $inner_blocks_html );
[212] Fix | Delete
$inner_blocks_html = block_core_navigation_add_directives_to_submenu( $tags, $attributes );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
return $inner_blocks_html;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Gets the inner blocks for the navigation block from the navigation post.
[220] Fix | Delete
*
[221] Fix | Delete
* @since 6.5.0
[222] Fix | Delete
*
[223] Fix | Delete
* @param array $attributes The block attributes.
[224] Fix | Delete
* @return WP_Block_List Returns the inner blocks for the navigation block.
[225] Fix | Delete
*/
[226] Fix | Delete
private static function get_inner_blocks_from_navigation_post( $attributes ) {
[227] Fix | Delete
$navigation_post = get_post( $attributes['ref'] );
[228] Fix | Delete
if ( ! isset( $navigation_post ) ) {
[229] Fix | Delete
return new WP_Block_List( array(), $attributes );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
// Only published posts are valid. If this is changed then a corresponding change
[233] Fix | Delete
// must also be implemented in `use-navigation-menu.js`.
[234] Fix | Delete
if ( 'publish' === $navigation_post->post_status ) {
[235] Fix | Delete
$parsed_blocks = parse_blocks( $navigation_post->post_content );
[236] Fix | Delete
[237] Fix | Delete
// 'parse_blocks' includes a null block with '\n\n' as the content when
[238] Fix | Delete
// it encounters whitespace. This code strips it.
[239] Fix | Delete
$blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
[240] Fix | Delete
[241] Fix | Delete
// Re-serialize, and run Block Hooks algorithm to inject hooked blocks.
[242] Fix | Delete
// TODO: See if we can move the apply_block_hooks_to_content_from_post_object() call
[243] Fix | Delete
// before the parse_blocks() call further above, to avoid the extra serialization/parsing.
[244] Fix | Delete
$markup = serialize_blocks( $blocks );
[245] Fix | Delete
$markup = apply_block_hooks_to_content_from_post_object( $markup, $navigation_post );
[246] Fix | Delete
$blocks = parse_blocks( $markup );
[247] Fix | Delete
[248] Fix | Delete
// TODO - this uses the full navigation block attributes for the
[249] Fix | Delete
// context which could be refined.
[250] Fix | Delete
return new WP_Block_List( $blocks, $attributes );
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
/**
[255] Fix | Delete
* Gets the inner blocks for the navigation block from the fallback.
[256] Fix | Delete
*
[257] Fix | Delete
* @since 6.5.0
[258] Fix | Delete
*
[259] Fix | Delete
* @param array $attributes The block attributes.
[260] Fix | Delete
* @return WP_Block_List Returns the inner blocks for the navigation block.
[261] Fix | Delete
*/
[262] Fix | Delete
private static function get_inner_blocks_from_fallback( $attributes ) {
[263] Fix | Delete
$fallback_blocks = block_core_navigation_get_fallback_blocks();
[264] Fix | Delete
[265] Fix | Delete
// Fallback my have been filtered so do basic test for validity.
[266] Fix | Delete
if ( empty( $fallback_blocks ) || ! is_array( $fallback_blocks ) ) {
[267] Fix | Delete
return new WP_Block_List( array(), $attributes );
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
return new WP_Block_List( $fallback_blocks, $attributes );
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Gets the inner blocks for the navigation block.
[275] Fix | Delete
*
[276] Fix | Delete
* @since 6.5.0
[277] Fix | Delete
*
[278] Fix | Delete
* @param array $attributes The block attributes.
[279] Fix | Delete
* @param WP_Block $block The parsed block.
[280] Fix | Delete
* @return WP_Block_List Returns the inner blocks for the navigation block.
[281] Fix | Delete
*/
[282] Fix | Delete
private static function get_inner_blocks( $attributes, $block ) {
[283] Fix | Delete
$inner_blocks = $block->inner_blocks;
[284] Fix | Delete
[285] Fix | Delete
// Ensure that blocks saved with the legacy ref attribute name (navigationMenuId) continue to render.
[286] Fix | Delete
if ( array_key_exists( 'navigationMenuId', $attributes ) ) {
[287] Fix | Delete
$attributes['ref'] = $attributes['navigationMenuId'];
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
// If:
[291] Fix | Delete
// - the gutenberg plugin is active
[292] Fix | Delete
// - `__unstableLocation` is defined
[293] Fix | Delete
// - we have menu items at the defined location
[294] Fix | Delete
// - we don't have a relationship to a `wp_navigation` Post (via `ref`).
[295] Fix | Delete
// ...then create inner blocks from the classic menu assigned to that location.
[296] Fix | Delete
if (
[297] Fix | Delete
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN &&
[298] Fix | Delete
array_key_exists( '__unstableLocation', $attributes ) &&
[299] Fix | Delete
! array_key_exists( 'ref', $attributes ) &&
[300] Fix | Delete
! empty( block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] ) )
[301] Fix | Delete
) {
[302] Fix | Delete
$inner_blocks = block_core_navigation_get_inner_blocks_from_unstable_location( $attributes );
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
// Load inner blocks from the navigation post.
[306] Fix | Delete
if ( array_key_exists( 'ref', $attributes ) ) {
[307] Fix | Delete
$inner_blocks = static::get_inner_blocks_from_navigation_post( $attributes );
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
// If there are no inner blocks then fallback to rendering an appropriate fallback.
[311] Fix | Delete
if ( empty( $inner_blocks ) ) {
[312] Fix | Delete
$inner_blocks = static::get_inner_blocks_from_fallback( $attributes );
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
/**
[316] Fix | Delete
* Filter navigation block $inner_blocks.
[317] Fix | Delete
* Allows modification of a navigation block menu items.
[318] Fix | Delete
*
[319] Fix | Delete
* @since 6.1.0
[320] Fix | Delete
*
[321] Fix | Delete
* @param \WP_Block_List $inner_blocks
[322] Fix | Delete
*/
[323] Fix | Delete
$inner_blocks = apply_filters( 'block_core_navigation_render_inner_blocks', $inner_blocks );
[324] Fix | Delete
[325] Fix | Delete
$post_ids = block_core_navigation_get_post_ids( $inner_blocks );
[326] Fix | Delete
if ( $post_ids ) {
[327] Fix | Delete
_prime_post_caches( $post_ids, false, false );
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
return $inner_blocks;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
/**
[334] Fix | Delete
* Gets the name of the current navigation, if it has one.
[335] Fix | Delete
*
[336] Fix | Delete
* @since 6.5.0
[337] Fix | Delete
*
[338] Fix | Delete
* @param array $attributes The block attributes.
[339] Fix | Delete
* @return string Returns the name of the navigation.
[340] Fix | Delete
*/
[341] Fix | Delete
private static function get_navigation_name( $attributes ) {
[342] Fix | Delete
[343] Fix | Delete
$navigation_name = $attributes['ariaLabel'] ?? '';
[344] Fix | Delete
[345] Fix | Delete
if ( ! empty( $navigation_name ) ) {
[346] Fix | Delete
return $navigation_name;
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
// Load the navigation post.
[350] Fix | Delete
if ( array_key_exists( 'ref', $attributes ) ) {
[351] Fix | Delete
$navigation_post = get_post( $attributes['ref'] );
[352] Fix | Delete
if ( ! isset( $navigation_post ) ) {
[353] Fix | Delete
return $navigation_name;
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
// Only published posts are valid. If this is changed then a corresponding change
[357] Fix | Delete
// must also be implemented in `use-navigation-menu.js`.
[358] Fix | Delete
if ( 'publish' === $navigation_post->post_status ) {
[359] Fix | Delete
$navigation_name = $navigation_post->post_title;
[360] Fix | Delete
[361] Fix | Delete
// This is used to count the number of times a navigation name has been seen,
[362] Fix | Delete
// so that we can ensure every navigation has a unique id.
[363] Fix | Delete
if ( isset( static::$seen_menu_names[ $navigation_name ] ) ) {
[364] Fix | Delete
++static::$seen_menu_names[ $navigation_name ];
[365] Fix | Delete
} else {
[366] Fix | Delete
static::$seen_menu_names[ $navigation_name ] = 1;
[367] Fix | Delete
}
[368] Fix | Delete
}
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
return $navigation_name;
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* Returns the layout class for the navigation block.
[376] Fix | Delete
*
[377] Fix | Delete
* @since 6.5.0
[378] Fix | Delete
*
[379] Fix | Delete
* @param array $attributes The block attributes.
[380] Fix | Delete
* @return string Returns the layout class for the navigation block.
[381] Fix | Delete
*/
[382] Fix | Delete
private static function get_layout_class( $attributes ) {
[383] Fix | Delete
$layout_justification = array(
[384] Fix | Delete
'left' => 'items-justified-left',
[385] Fix | Delete
'right' => 'items-justified-right',
[386] Fix | Delete
'center' => 'items-justified-center',
[387] Fix | Delete
'space-between' => 'items-justified-space-between',
[388] Fix | Delete
);
[389] Fix | Delete
[390] Fix | Delete
$layout_class = '';
[391] Fix | Delete
if (
[392] Fix | Delete
isset( $attributes['layout']['justifyContent'] ) &&
[393] Fix | Delete
isset( $layout_justification[ $attributes['layout']['justifyContent'] ] )
[394] Fix | Delete
) {
[395] Fix | Delete
$layout_class .= $layout_justification[ $attributes['layout']['justifyContent'] ];
[396] Fix | Delete
}
[397] Fix | Delete
if ( isset( $attributes['layout']['orientation'] ) && 'vertical' === $attributes['layout']['orientation'] ) {
[398] Fix | Delete
$layout_class .= ' is-vertical';
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
if ( isset( $attributes['layout']['flexWrap'] ) && 'nowrap' === $attributes['layout']['flexWrap'] ) {
[402] Fix | Delete
$layout_class .= ' no-wrap';
[403] Fix | Delete
}
[404] Fix | Delete
return $layout_class;
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
/**
[408] Fix | Delete
* Return classes for the navigation block.
[409] Fix | Delete
*
[410] Fix | Delete
* @since 6.5.0
[411] Fix | Delete
*
[412] Fix | Delete
* @param array $attributes The block attributes.
[413] Fix | Delete
* @return string Returns the classes for the navigation block.
[414] Fix | Delete
*/
[415] Fix | Delete
private static function get_classes( $attributes ) {
[416] Fix | Delete
// Restore legacy classnames for submenu positioning.
[417] Fix | Delete
$layout_class = static::get_layout_class( $attributes );
[418] Fix | Delete
$colors = block_core_navigation_build_css_colors( $attributes );
[419] Fix | Delete
$font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
[420] Fix | Delete
$is_responsive_menu = static::is_responsive( $attributes );
[421] Fix | Delete
[422] Fix | Delete
// Manually add block support text decoration as CSS class.
[423] Fix | Delete
$text_decoration = $attributes['style']['typography']['textDecoration'] ?? null;
[424] Fix | Delete
$text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration );
[425] Fix | Delete
[426] Fix | Delete
$classes = array_merge(
[427] Fix | Delete
$colors['css_classes'],
[428] Fix | Delete
$font_sizes['css_classes'],
[429] Fix | Delete
$is_responsive_menu ? array( 'is-responsive' ) : array(),
[430] Fix | Delete
$layout_class ? array( $layout_class ) : array(),
[431] Fix | Delete
$text_decoration ? array( $text_decoration_class ) : array()
[432] Fix | Delete
);
[433] Fix | Delete
return implode( ' ', $classes );
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
/**
[437] Fix | Delete
* Get styles for the navigation block.
[438] Fix | Delete
*
[439] Fix | Delete
* @since 6.5.0
[440] Fix | Delete
*
[441] Fix | Delete
* @param array $attributes The block attributes.
[442] Fix | Delete
* @return string Returns the styles for the navigation block.
[443] Fix | Delete
*/
[444] Fix | Delete
private static function get_styles( $attributes ) {
[445] Fix | Delete
$colors = block_core_navigation_build_css_colors( $attributes );
[446] Fix | Delete
$font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
[447] Fix | Delete
$block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : '';
[448] Fix | Delete
return $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'];
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
/**
[452] Fix | Delete
* Get the responsive container markup
[453] Fix | Delete
*
[454] Fix | Delete
* @since 6.5.0
[455] Fix | Delete
*
[456] Fix | Delete
* @param array $attributes The block attributes.
[457] Fix | Delete
* @param WP_Block_List $inner_blocks The list of inner blocks.
[458] Fix | Delete
* @param string $inner_blocks_html The markup for the inner blocks.
[459] Fix | Delete
* @return string Returns the container markup.
[460] Fix | Delete
*/
[461] Fix | Delete
private static function get_responsive_container_markup( $attributes, $inner_blocks, $inner_blocks_html ) {
[462] Fix | Delete
$is_interactive = static::is_interactive( $attributes, $inner_blocks );
[463] Fix | Delete
$colors = block_core_navigation_build_css_colors( $attributes );
[464] Fix | Delete
$modal_unique_id = wp_unique_id( 'modal-' );
[465] Fix | Delete
[466] Fix | Delete
$is_hidden_by_default = isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu'];
[467] Fix | Delete
[468] Fix | Delete
$responsive_container_classes = array(
[469] Fix | Delete
'wp-block-navigation__responsive-container',
[470] Fix | Delete
$is_hidden_by_default ? 'hidden-by-default' : '',
[471] Fix | Delete
implode( ' ', $colors['overlay_css_classes'] ),
[472] Fix | Delete
);
[473] Fix | Delete
$open_button_classes = array(
[474] Fix | Delete
'wp-block-navigation__responsive-container-open',
[475] Fix | Delete
$is_hidden_by_default ? 'always-shown' : '',
[476] Fix | Delete
);
[477] Fix | Delete
[478] Fix | Delete
$should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon'];
[479] Fix | Delete
$toggle_button_icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 7.5h16v1.5H4z"></path><path d="M4 15h16v1.5H4z"></path></svg>';
[480] Fix | Delete
if ( isset( $attributes['icon'] ) ) {
[481] Fix | Delete
if ( 'menu' === $attributes['icon'] ) {
[482] Fix | Delete
$toggle_button_icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5 5v1.5h14V5H5z"></path><path d="M5 12.8h14v-1.5H5v1.5z"></path><path d="M5 19h14v-1.5H5V19z"></path></svg>';
[483] Fix | Delete
}
[484] Fix | Delete
}
[485] Fix | Delete
$toggle_button_content = $should_display_icon_label ? $toggle_button_icon : __( 'Menu' );
[486] Fix | Delete
$toggle_close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z"></path></svg>';
[487] Fix | Delete
$toggle_close_button_content = $should_display_icon_label ? $toggle_close_button_icon : __( 'Close' );
[488] Fix | Delete
$toggle_aria_label_open = $should_display_icon_label ? 'aria-label="' . __( 'Open menu' ) . '"' : ''; // Open button label.
[489] Fix | Delete
$toggle_aria_label_close = $should_display_icon_label ? 'aria-label="' . __( 'Close menu' ) . '"' : ''; // Close button label.
[490] Fix | Delete
[491] Fix | Delete
// Add Interactivity API directives to the markup if needed.
[492] Fix | Delete
$open_button_directives = '';
[493] Fix | Delete
$responsive_container_directives = '';
[494] Fix | Delete
$responsive_dialog_directives = '';
[495] Fix | Delete
$close_button_directives = '';
[496] Fix | Delete
if ( $is_interactive ) {
[497] Fix | Delete
$open_button_directives = '
[498] Fix | Delete
data-wp-on--click="actions.openMenuOnClick"
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function