| @@ -4,10 +4,16 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package WordPress |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -require_once __DIR__ . '/navigation-link/shared/item-should-render.php'; | |
| 9 | -require_once __DIR__ . '/navigation-link/shared/render-submenu-icon.php'; | |
| 8 | +// Path differs between source and build: './shared/' in source, './navigation-link/shared/' in build. | |
| 9 | +if ( file_exists( __DIR__ . '/shared/item-should-render.php' ) ) { | |
| 10 | + require_once __DIR__ . '/shared/item-should-render.php'; | |
| 11 | + require_once __DIR__ . '/shared/render-submenu-icon.php'; | |
| 12 | +} else { | |
| 13 | + require_once __DIR__ . '/navigation-link/shared/item-should-render.php'; | |
| 14 | + require_once __DIR__ . '/navigation-link/shared/render-submenu-icon.php'; | |
| 15 | +} | |
| 10 | 16 | |
| 11 | 17 | /** |
| 12 | 18 | * Build an array with CSS classes and inline styles defining the colors |
| 13 | 19 | * which will be applied to the navigation markup in the front-end. |
| @@ -83,20 +89,14 @@ | ||
| 83 | 89 | /** |
| 84 | 90 | * Build an array with CSS classes and inline styles defining the font sizes |
| 85 | 91 | * which will be applied to the navigation markup in the front-end. |
| 86 | 92 | * |
| 87 | - * This function is no longer used internally and is kept only for backward | |
| 88 | - * compatibility with third-party code that may call it directly. | |
| 89 | - * | |
| 90 | 93 | * @since 5.9.0 |
| 91 | - * @deprecated 7.0.0 | |
| 92 | 94 | * |
| 93 | 95 | * @param array $context Navigation block context. |
| 94 | 96 | * @return array Font size CSS classes and inline styles. |
| 95 | 97 | */ |
| 96 | 98 | function gutenberg_block_core_navigation_link_build_css_font_sizes( $context ) { |
| 97 | - _deprecated_function( __FUNCTION__, '7.0.0' ); | |
| 98 | - | |
| 99 | 99 | // CSS classes. |
| 100 | 100 | $font_sizes = array( |
| 101 | 101 | 'css_classes' => array(), |
| 102 | 102 | 'inline_styles' => '', |
| @@ -123,25 +123,8 @@ | ||
| 123 | 123 | return $font_sizes; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | - * Returns the top-level submenu SVG chevron icon. | |
| 128 | - * | |
| 129 | - * @since 5.9.0 | |
| 130 | - * @deprecated 7.0.0 Use block_core_shared_navigation_render_submenu_icon() instead. | |
| 131 | - * | |
| 132 | - * @return string | |
| 133 | - */ | |
| 134 | -function gutenberg_block_core_navigation_link_render_submenu_icon() { | |
| 135 | - _deprecated_function( | |
| 136 | - __FUNCTION__, | |
| 137 | - '7.0.0', | |
| 138 | - 'block_core_shared_navigation_render_submenu_icon()' | |
| 139 | - ); | |
| 140 | - return block_core_shared_navigation_render_submenu_icon(); | |
| 141 | -} | |
| 142 | - | |
| 143 | -/** | |
| 144 | 127 | * Decodes a url if it's encoded, returning the same url if not. |
| 145 | 128 | * |
| 146 | 129 | * @since 6.2.0 |
| 147 | 130 | * |
| @@ -186,15 +169,12 @@ | ||
| 186 | 169 | */ |
| 187 | 170 | function gutenberg_render_block_core_navigation_link( $attributes, $content, $block ) { |
| 188 | 171 | // Check if this navigation item should render based on post status. |
| 189 | 172 | if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { |
| 190 | - $should_render = gutenberg_block_core_shared_navigation_item_should_render( $attributes, $block ); | |
| 191 | - } else { | |
| 192 | - $should_render = block_core_shared_navigation_item_should_render( $attributes, $block ); | |
| 173 | + if ( ! gutenberg_block_core_shared_navigation_item_should_render( $attributes, $block ) ) { | |
| 174 | + return ''; | |
| 175 | + } | |
| 193 | 176 | } |
| 194 | - if ( ! $should_render ) { | |
| 195 | - return ''; | |
| 196 | - } | |
| 197 | 177 | |
| 198 | 178 | // Don't render the block's subtree if it has no label. |
| 199 | 179 | if ( empty( $attributes['label'] ) ) { |
| 200 | 180 | return ''; |
| @@ -199,9 +179,13 @@ | ||
| 199 | 179 | if ( empty( $attributes['label'] ) ) { |
| 200 | 180 | return ''; |
| 201 | 181 | } |
| 202 | 182 | |
| 203 | - $classes = array(); | |
| 183 | + $font_sizes = gutenberg_block_core_navigation_link_build_css_font_sizes( $block->context ); | |
| 184 | + $classes = array_merge( | |
| 185 | + $font_sizes['css_classes'] | |
| 186 | + ); | |
| 187 | + $style_attribute = $font_sizes['inline_styles']; | |
| 204 | 188 | |
| 205 | 189 | // Render inner blocks first to check if any menu items will actually display. |
| 206 | 190 | $inner_blocks_html = ''; |
| 207 | 191 | foreach ( $block->inner_blocks as $inner_block ) { |
| @@ -223,8 +207,9 @@ | ||
| 223 | 207 | $wrapper_attributes = get_block_wrapper_attributes( |
| 224 | 208 | array( |
| 225 | 209 | 'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) . |
| 226 | 210 | ( $is_active ? ' current-menu-item' : '' ), |
| 211 | + 'style' => $style_attribute, | |
| 227 | 212 | ) |
| 228 | 213 | ); |
| 229 | 214 | $html = '<li ' . $wrapper_attributes . '>' . |
| 230 | 215 | '<a class="wp-block-navigation-item__content" '; |
| @@ -276,15 +261,9 @@ | ||
| 276 | 261 | // End anchor tag content. |
| 277 | 262 | |
| 278 | 263 | if ( isset( $block->context['showSubmenuIcon'] ) && $block->context['showSubmenuIcon'] && $has_submenu ) { |
| 279 | 264 | // The submenu icon can be hidden by a CSS rule on the Navigation Block. |
| 280 | - $html .= '<span class="wp-block-navigation__submenu-icon">'; | |
| 281 | - if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { | |
| 282 | - $html .= gutenberg_block_core_shared_navigation_render_submenu_icon(); | |
| 283 | - } else { | |
| 284 | - $html .= block_core_shared_navigation_render_submenu_icon(); | |
| 285 | - } | |
| 286 | - $html .= '</span>'; | |
| 265 | + $html .= '<span class="wp-block-navigation__submenu-icon">' . block_core_navigation_render_submenu_icon() . '</span>'; | |
| 287 | 266 | } |
| 288 | 267 | |
| 289 | 268 | if ( $has_submenu ) { |
| 290 | 269 | $html .= sprintf( |
| @@ -505,5 +484,5 @@ | ||
| 505 | 484 | /** |
| 506 | 485 | * Creates all variations for post types / taxonomies dynamically (= each time when variations are requested). |
| 507 | 486 | * Do not use variation_callback, to also account for unregistering post types/taxonomies later on. |
| 508 | 487 | */ |
| 509 | -add_filter( 'get_block_type_variations', 'gutenberg_block_core_navigation_link_filter_variations', 10, 2 ); | |
| 488 | +add_action( 'get_block_type_variations', 'gutenberg_block_core_navigation_link_filter_variations', 10, 2 ); | |