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/post-navigation-link.php +94 -5 23.7.0 → 24.1.0 View file →
@@ -29,13 +29,9 @@
29 29 $classes = "post-navigation-link-$navigation_type";
30 30 if ( isset( $attributes['textAlign'] ) ) {
31 31 $classes .= " has-text-align-{$attributes['textAlign']}";
32 32 }
33 - $wrapper_attributes = get_block_wrapper_attributes(
34 - array(
35 - 'class' => $classes,
36 - )
37 - );
33 +
38 34 // Set default values.
39 35 $format = '%link';
40 36 $link = 'next' === $navigation_type ? _x( 'Next', 'label for next post link' ) : _x( 'Previous', 'label for previous post link' );
41 37 $label = '';
@@ -115,12 +111,105 @@
115 111 } else {
116 112 $content = $get_link_function( $format, $link );
117 113 }
118 114
115 + // The `{next,previous}_post_link` filters can return null, which renders as no link.
116 + $content = (string) $content;
117 +
118 + /*
119 + * Border, shadow and spacing serialization is skipped for this block so
120 + * those styles can be withheld from the empty wrapper rendered when there is
121 + * no adjacent post. The wrapper itself is kept for backward compatibility.
122 + */
123 + $support_styles = '' === $content
124 + ? array(
125 + 'class' => '',
126 + 'style' => '',
127 + )
128 + : gutenberg_block_core_post_navigation_link_get_support_styles( $attributes );
129 +
130 + if ( '' !== $support_styles['class'] ) {
131 + $classes .= " {$support_styles['class']}";
132 + }
133 +
134 + $wrapper_attributes = get_block_wrapper_attributes(
135 + array(
136 + 'class' => $classes,
137 + 'style' => $support_styles['style'],
138 + )
139 + );
140 +
119 141 return sprintf(
120 142 '<div %1$s>%2$s</div>',
121 143 $wrapper_attributes,
122 144 $content
145 + );
146 +}
147 +
148 +/**
149 + * Generates the border, shadow and spacing class names and inline styles for
150 + * the `core/post-navigation-link` block.
151 + *
152 + * Mirrors the default border, shadow and spacing block support serialization,
153 + * which the block opts out of so the styles are only applied when a link is
154 + * rendered.
155 + *
156 + * @since 7.2.0
157 + *
158 + * @param array $attributes The block attributes.
159 + * @return array {
160 + * Border, shadow and spacing class names and inline styles.
161 + *
162 + * @type string $class Class names generated by the style engine, or an empty string.
163 + * @type string $style Inline styles generated by the style engine, or an empty string.
164 + * }
165 + */
166 +function gutenberg_block_core_post_navigation_link_get_support_styles( $attributes ) {
167 + $block_styles = $attributes['style'] ?? array();
168 + $border = $block_styles['border'] ?? array();
169 + $border_styles = array();
170 +
171 + // Border radius and width accept unitless numbers from the original implementation.
172 + if ( isset( $border['radius'] ) ) {
173 + $border_styles['radius'] = is_numeric( $border['radius'] ) ? "{$border['radius']}px" : $border['radius'];
174 + }
175 +
176 + if ( isset( $border['width'] ) ) {
177 + $border_styles['width'] = is_numeric( $border['width'] ) ? "{$border['width']}px" : $border['width'];
178 + }
179 +
180 + if ( isset( $border['style'] ) ) {
181 + $border_styles['style'] = $border['style'];
182 + }
183 +
184 + // A preset border color is stored in its own attribute rather than under `style`.
185 + $border_styles['color'] = isset( $attributes['borderColor'] )
186 + ? "var:preset|color|{$attributes['borderColor']}"
187 + : ( $border['color'] ?? null );
188 +
189 + // Individual border sides e.g. top, left etc.
190 + foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
191 + $border_styles[ $side ] = array(
192 + 'width' => $border[ $side ]['width'] ?? null,
193 + 'color' => $border[ $side ]['color'] ?? null,
194 + 'style' => $border[ $side ]['style'] ?? null,
195 + );
196 + }
197 +
198 + $styles = gutenberg_style_engine_get_styles(
199 + array(
200 + 'border' => $border_styles,
201 + 'shadow' => $block_styles['shadow'] ?? null,
202 + 'spacing' => array(
203 + 'margin' => $block_styles['spacing']['margin'] ?? null,
204 + 'padding' => $block_styles['spacing']['padding'] ?? null,
205 + ),
206 + )
207 + );
208 +
209 + return array(
210 + 'class' => $styles['classnames'] ?? '',
211 + 'style' => $styles['css'] ?? '',
123 212 );
124 213 }
125 214
126 215 /**