PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/scripts/block-library/navigation-link.php +75 -22 23.3.2 → 24.1.0 View file →
@@ -6,9 +6,8 @@
6 6 */
7 7
8 8 require_once __DIR__ . '/navigation-link/shared/item-should-render.php';
9 9 require_once __DIR__ . '/navigation-link/shared/render-submenu-icon.php';
10 -require_once __DIR__ . '/navigation-link/shared/build-css-font-sizes.php';
11 10
12 11 /**
13 12 * Build an array with CSS classes and inline styles defining the colors
14 13 * which will be applied to the navigation markup in the front-end.
@@ -14,11 +13,11 @@
14 13 * which will be applied to the navigation markup in the front-end.
15 14 *
16 15 * @since 5.9.0
17 16 *
18 - * @param array $context Navigation block context.
19 - * @param array $attributes Block attributes.
20 - * @param bool $is_sub_menu Whether the link is part of a sub-menu. Default false.
17 + * @param array $context Navigation block context.
18 + * @param array $attributes Block attributes.
19 + * @param bool $is_sub_menu Whether the link is part of a sub-menu. Default false.
21 20 * @return array Colors CSS classes and inline styles.
22 21 */
23 22 function gutenberg_block_core_navigation_link_build_css_colors( $context, $attributes, $is_sub_menu = false ) {
24 23 $colors = array(
@@ -81,8 +80,68 @@
81 80 return $colors;
82 81 }
83 82
84 83 /**
84 + * Build an array with CSS classes and inline styles defining the font sizes
85 + * which will be applied to the navigation markup in the front-end.
86 + *
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 + * @since 5.9.0
91 + * @deprecated 7.0.0
92 + *
93 + * @param array $context Navigation block context.
94 + * @return array Font size CSS classes and inline styles.
95 + */
96 +function gutenberg_block_core_navigation_link_build_css_font_sizes( $context ) {
97 + _deprecated_function( __FUNCTION__, '7.0.0' );
98 +
99 + // CSS classes.
100 + $font_sizes = array(
101 + 'css_classes' => array(),
102 + 'inline_styles' => '',
103 + );
104 +
105 + $has_named_font_size = array_key_exists( 'fontSize', $context );
106 + $has_custom_font_size = isset( $context['style']['typography']['fontSize'] );
107 +
108 + if ( $has_named_font_size ) {
109 + // Add the font size class.
110 + $font_sizes['css_classes'][] = sprintf( 'has-%s-font-size', $context['fontSize'] );
111 + } elseif ( $has_custom_font_size ) {
112 + // Add the custom font size inline style.
113 + $font_sizes['inline_styles'] = sprintf(
114 + 'font-size: %s;',
115 + gutenberg_get_typography_font_size_value(
116 + array(
117 + 'size' => $context['style']['typography']['fontSize'],
118 + )
119 + )
120 + );
121 + }
122 +
123 + return $font_sizes;
124 +}
125 +
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 +/**
85 144 * Decodes a url if it's encoded, returning the same url if not.
86 145 *
87 146 * @since 6.2.0
88 147 *
@@ -90,8 +149,12 @@
90 149 *
91 150 * @return string $url Returns the decoded url.
92 151 */
93 152 function gutenberg_block_core_navigation_link_maybe_urldecode( $url ) {
153 + if ( ! is_string( $url ) ) {
154 + return '';
155 + }
156 +
94 157 $is_url_encoded = false;
95 158 $query = parse_url( $url, PHP_URL_QUERY );
96 159 $query_params = wp_parse_args( $query );
97 160
@@ -127,12 +190,15 @@
127 190 */
128 191 function gutenberg_render_block_core_navigation_link( $attributes, $content, $block ) {
129 192 // Check if this navigation item should render based on post status.
130 193 if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
131 - if ( ! gutenberg_block_core_shared_navigation_item_should_render( $attributes, $block ) ) {
132 - return '';
133 - }
194 + $should_render = gutenberg_block_core_shared_navigation_item_should_render( $attributes, $block );
195 + } else {
196 + $should_render = block_core_shared_navigation_item_should_render( $attributes, $block );
134 197 }
198 + if ( ! $should_render ) {
199 + return '';
200 + }
135 201
136 202 // Don't render the block's subtree if it has no label.
137 203 if ( empty( $attributes['label'] ) ) {
138 204 return '';
@@ -137,21 +203,9 @@
137 203 if ( empty( $attributes['label'] ) ) {
138 204 return '';
139 205 }
140 206
141 - // The build system prefixes this function with "gutenberg_" to avoid
142 - // collisions with the core version. Until this function is backported to
143 - // core, we need to guard its use and only call the prefixed name in
144 - // the plugin.
145 - if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
146 - $font_sizes = gutenberg_block_core_shared_navigation_build_css_font_sizes( $block->context );
147 - } else {
148 - $font_sizes = block_core_shared_navigation_build_css_font_sizes( $block->context );
149 - }
150 - $classes = array_merge(
151 - $font_sizes['css_classes']
152 - );
153 - $style_attribute = $font_sizes['inline_styles'];
207 + $classes = array();
154 208
155 209 // Render inner blocks first to check if any menu items will actually display.
156 210 $inner_blocks_html = '';
157 211 foreach ( $block->inner_blocks as $inner_block ) {
@@ -173,9 +227,8 @@
173 227 $wrapper_attributes = get_block_wrapper_attributes(
174 228 array(
175 229 'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) .
176 230 ( $is_active ? ' current-menu-item' : '' ),
177 - 'style' => $style_attribute,
178 231 )
179 232 );
180 233 $html = '<li ' . $wrapper_attributes . '>' .
181 234 '<a class="wp-block-navigation-item__content" ';
@@ -254,9 +307,9 @@
254 307 *
255 308 * @since 5.9.0
256 309 *
257 310 * @param WP_Taxonomy|WP_Post_Type $entity post type or taxonomy entity.
258 - * @param string $kind string of value 'taxonomy' or 'post-type'.
311 + * @param string $kind string of value 'taxonomy' or 'post-type'.
259 312 *
260 313 * @return array
261 314 */
262 315 function gutenberg_build_variation_for_navigation_link( $entity, $kind ) {