author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
18 | 1 |
<?php |
2 |
/** |
|
3 |
* Server-side rendering of the `core/pages` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Build an array with CSS classes and inline styles defining the colors |
|
10 |
* which will be applied to the pages markup in the front-end when it is a descendant of navigation. |
|
11 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
12 |
* @since 5.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
13 |
* |
19 | 14 |
* @param array $attributes Block attributes. |
15 |
* @param array $context Navigation block context. |
|
18 | 16 |
* @return array Colors CSS classes and inline styles. |
17 |
*/ |
|
19 | 18 |
function block_core_page_list_build_css_colors( $attributes, $context ) { |
18 | 19 |
$colors = array( |
19 | 20 |
'css_classes' => array(), |
21 |
'inline_styles' => '', |
|
22 |
'overlay_css_classes' => array(), |
|
23 |
'overlay_inline_styles' => '', |
|
18 | 24 |
); |
25 |
||
26 |
// Text color. |
|
27 |
$has_named_text_color = array_key_exists( 'textColor', $context ); |
|
19 | 28 |
$has_picked_text_color = array_key_exists( 'customTextColor', $context ); |
18 | 29 |
$has_custom_text_color = isset( $context['style']['color']['text'] ); |
30 |
||
31 |
// If has text color. |
|
19 | 32 |
if ( $has_custom_text_color || $has_picked_text_color || $has_named_text_color ) { |
18 | 33 |
// Add has-text-color class. |
34 |
$colors['css_classes'][] = 'has-text-color'; |
|
35 |
} |
|
36 |
||
37 |
if ( $has_named_text_color ) { |
|
38 |
// Add the color class. |
|
19 | 39 |
$colors['css_classes'][] = sprintf( 'has-%s-color', _wp_to_kebab_case( $context['textColor'] ) ); |
40 |
} elseif ( $has_picked_text_color ) { |
|
41 |
$colors['inline_styles'] .= sprintf( 'color: %s;', $context['customTextColor'] ); |
|
18 | 42 |
} elseif ( $has_custom_text_color ) { |
43 |
// Add the custom color inline style. |
|
44 |
$colors['inline_styles'] .= sprintf( 'color: %s;', $context['style']['color']['text'] ); |
|
45 |
} |
|
46 |
||
47 |
// Background color. |
|
48 |
$has_named_background_color = array_key_exists( 'backgroundColor', $context ); |
|
19 | 49 |
$has_picked_background_color = array_key_exists( 'customBackgroundColor', $context ); |
18 | 50 |
$has_custom_background_color = isset( $context['style']['color']['background'] ); |
51 |
||
52 |
// If has background color. |
|
19 | 53 |
if ( $has_custom_background_color || $has_picked_background_color || $has_named_background_color ) { |
18 | 54 |
// Add has-background class. |
55 |
$colors['css_classes'][] = 'has-background'; |
|
56 |
} |
|
57 |
||
58 |
if ( $has_named_background_color ) { |
|
59 |
// Add the background-color class. |
|
19 | 60 |
$colors['css_classes'][] = sprintf( 'has-%s-background-color', _wp_to_kebab_case( $context['backgroundColor'] ) ); |
61 |
} elseif ( $has_picked_background_color ) { |
|
62 |
$colors['inline_styles'] .= sprintf( 'background-color: %s;', $context['customBackgroundColor'] ); |
|
18 | 63 |
} elseif ( $has_custom_background_color ) { |
64 |
// Add the custom background-color inline style. |
|
65 |
$colors['inline_styles'] .= sprintf( 'background-color: %s;', $context['style']['color']['background'] ); |
|
66 |
} |
|
67 |
||
19 | 68 |
// Overlay text color. |
69 |
$has_named_overlay_text_color = array_key_exists( 'overlayTextColor', $context ); |
|
70 |
$has_picked_overlay_text_color = array_key_exists( 'customOverlayTextColor', $context ); |
|
71 |
||
72 |
// If it has a text color. |
|
73 |
if ( $has_named_overlay_text_color || $has_picked_overlay_text_color ) { |
|
74 |
$colors['overlay_css_classes'][] = 'has-text-color'; |
|
75 |
} |
|
76 |
||
77 |
// Give overlay colors priority, fall back to Navigation block colors, then global styles. |
|
78 |
if ( $has_named_overlay_text_color ) { |
|
79 |
$colors['overlay_css_classes'][] = sprintf( 'has-%s-color', _wp_to_kebab_case( $context['overlayTextColor'] ) ); |
|
80 |
} elseif ( $has_picked_overlay_text_color ) { |
|
81 |
$colors['overlay_inline_styles'] .= sprintf( 'color: %s;', $context['customOverlayTextColor'] ); |
|
82 |
} |
|
83 |
||
84 |
// Overlay background colors. |
|
85 |
$has_named_overlay_background_color = array_key_exists( 'overlayBackgroundColor', $context ); |
|
86 |
$has_picked_overlay_background_color = array_key_exists( 'customOverlayBackgroundColor', $context ); |
|
87 |
||
88 |
// If has background color. |
|
89 |
if ( $has_named_overlay_background_color || $has_picked_overlay_background_color ) { |
|
90 |
$colors['overlay_css_classes'][] = 'has-background'; |
|
91 |
} |
|
92 |
||
93 |
if ( $has_named_overlay_background_color ) { |
|
94 |
$colors['overlay_css_classes'][] = sprintf( 'has-%s-background-color', _wp_to_kebab_case( $context['overlayBackgroundColor'] ) ); |
|
95 |
} elseif ( $has_picked_overlay_background_color ) { |
|
96 |
$colors['overlay_inline_styles'] .= sprintf( 'background-color: %s;', $context['customOverlayBackgroundColor'] ); |
|
97 |
} |
|
98 |
||
18 | 99 |
return $colors; |
100 |
} |
|
101 |
||
102 |
/** |
|
103 |
* Build an array with CSS classes and inline styles defining the font sizes |
|
104 |
* which will be applied to the pages markup in the front-end when it is a descendant of navigation. |
|
105 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
106 |
* @since 5.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
107 |
* |
18 | 108 |
* @param array $context Navigation block context. |
109 |
* @return array Font size CSS classes and inline styles. |
|
110 |
*/ |
|
111 |
function block_core_page_list_build_css_font_sizes( $context ) { |
|
112 |
// CSS classes. |
|
113 |
$font_sizes = array( |
|
114 |
'css_classes' => array(), |
|
115 |
'inline_styles' => '', |
|
116 |
); |
|
117 |
||
118 |
$has_named_font_size = array_key_exists( 'fontSize', $context ); |
|
119 |
$has_custom_font_size = isset( $context['style']['typography']['fontSize'] ); |
|
120 |
||
121 |
if ( $has_named_font_size ) { |
|
122 |
// Add the font size class. |
|
123 |
$font_sizes['css_classes'][] = sprintf( 'has-%s-font-size', $context['fontSize'] ); |
|
124 |
} elseif ( $has_custom_font_size ) { |
|
125 |
// Add the custom font size inline style. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
$font_sizes['inline_styles'] = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
'font-size: %s;', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
wp_get_typography_font_size_value( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
129 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
130 |
'size' => $context['style']['typography']['fontSize'], |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
132 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
133 |
); |
18 | 134 |
} |
135 |
||
136 |
return $font_sizes; |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* Outputs Page list markup from an array of pages with nested children. |
|
141 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
* @since 5.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
* |
19 | 144 |
* @param boolean $open_submenus_on_click Whether to open submenus on click instead of hover. |
145 |
* @param boolean $show_submenu_icons Whether to show submenu indicator icons. |
|
146 |
* @param boolean $is_navigation_child If block is a child of Navigation block. |
|
147 |
* @param array $nested_pages The array of nested pages. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
148 |
* @param boolean $is_nested Whether the submenu is nested or not. |
19 | 149 |
* @param array $active_page_ancestor_ids An array of ancestor ids for active page. |
150 |
* @param array $colors Color information for overlay styles. |
|
151 |
* @param integer $depth The nesting depth. |
|
18 | 152 |
* |
153 |
* @return string List markup. |
|
154 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
155 |
function block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 ) { |
18 | 156 |
if ( empty( $nested_pages ) ) { |
157 |
return; |
|
158 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
159 |
$front_page_id = (int) get_option( 'page_on_front' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
160 |
$markup = ''; |
18 | 161 |
foreach ( (array) $nested_pages as $page ) { |
19 | 162 |
$css_class = $page['is_active'] ? ' current-menu-item' : ''; |
163 |
$aria_current = $page['is_active'] ? ' aria-current="page"' : ''; |
|
164 |
$style_attribute = ''; |
|
165 |
||
166 |
$css_class .= in_array( $page['page_id'], $active_page_ancestor_ids, true ) ? ' current-menu-ancestor' : ''; |
|
18 | 167 |
if ( isset( $page['children'] ) ) { |
168 |
$css_class .= ' has-child'; |
|
169 |
} |
|
19 | 170 |
|
171 |
if ( $is_navigation_child ) { |
|
172 |
$css_class .= ' wp-block-navigation-item'; |
|
173 |
||
174 |
if ( $open_submenus_on_click ) { |
|
175 |
$css_class .= ' open-on-click'; |
|
176 |
} elseif ( $show_submenu_icons ) { |
|
177 |
$css_class .= ' open-on-hover-click'; |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
$navigation_child_content_class = $is_navigation_child ? ' wp-block-navigation-item__content' : ''; |
|
182 |
||
183 |
// If this is the first level of submenus, include the overlay colors. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
184 |
if ( ( ( 0 < $depth && ! $is_nested ) || $is_nested ) && isset( $colors['overlay_css_classes'], $colors['overlay_inline_styles'] ) ) { |
19 | 185 |
$css_class .= ' ' . trim( implode( ' ', $colors['overlay_css_classes'] ) ); |
186 |
if ( '' !== $colors['overlay_inline_styles'] ) { |
|
187 |
$style_attribute = sprintf( ' style="%s"', esc_attr( $colors['overlay_inline_styles'] ) ); |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
if ( (int) $page['page_id'] === $front_page_id ) { |
|
192 |
$css_class .= ' menu-item-home'; |
|
193 |
} |
|
194 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
195 |
$title = wp_kses_post( $page['title'] ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
196 |
$title = $title ? $title : __( '(no title)' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
197 |
|
19 | 198 |
$aria_label = sprintf( |
199 |
/* translators: Accessibility text. %s: Parent page title. */ |
|
200 |
__( '%s submenu' ), |
|
201 |
wp_strip_all_tags( $title ) |
|
202 |
); |
|
203 |
||
204 |
$markup .= '<li class="wp-block-pages-list__item' . esc_attr( $css_class ) . '"' . $style_attribute . '>'; |
|
205 |
||
206 |
if ( isset( $page['children'] ) && $is_navigation_child && $open_submenus_on_click ) { |
|
207 |
$markup .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="' . esc_attr( $navigation_child_content_class ) . ' wp-block-navigation-submenu__toggle" aria-expanded="false">' . esc_html( $title ) . |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
208 |
'</button><span class="wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg></span>'; |
19 | 209 |
} else { |
210 |
$markup .= '<a class="wp-block-pages-list__item__link' . esc_attr( $navigation_child_content_class ) . '" href="' . esc_url( $page['link'] ) . '"' . $aria_current . '>' . $title . '</a>'; |
|
211 |
} |
|
212 |
||
18 | 213 |
if ( isset( $page['children'] ) ) { |
19 | 214 |
if ( $is_navigation_child && $show_submenu_icons && ! $open_submenus_on_click ) { |
215 |
$markup .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="wp-block-navigation__submenu-icon wp-block-navigation-submenu__toggle" aria-expanded="false">'; |
|
216 |
$markup .= '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>'; |
|
217 |
$markup .= '</button>'; |
|
218 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
219 |
$markup .= '<ul class="wp-block-navigation__submenu-container">'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
220 |
$markup .= block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $page['children'], $is_nested, $active_page_ancestor_ids, $colors, $depth + 1 ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
221 |
$markup .= '</ul>'; |
18 | 222 |
} |
223 |
$markup .= '</li>'; |
|
224 |
} |
|
225 |
return $markup; |
|
226 |
} |
|
227 |
||
228 |
/** |
|
229 |
* Outputs nested array of pages |
|
230 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
231 |
* @since 5.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
* |
18 | 233 |
* @param array $current_level The level being iterated through. |
234 |
* @param array $children The children grouped by parent post ID. |
|
235 |
* |
|
236 |
* @return array The nested array of pages. |
|
237 |
*/ |
|
238 |
function block_core_page_list_nest_pages( $current_level, $children ) { |
|
239 |
if ( empty( $current_level ) ) { |
|
240 |
return; |
|
241 |
} |
|
242 |
foreach ( (array) $current_level as $key => $current ) { |
|
243 |
if ( isset( $children[ $key ] ) ) { |
|
244 |
$current_level[ $key ]['children'] = block_core_page_list_nest_pages( $children[ $key ], $children ); |
|
245 |
} |
|
246 |
} |
|
247 |
return $current_level; |
|
248 |
} |
|
249 |
||
250 |
/** |
|
251 |
* Renders the `core/page-list` block on server. |
|
252 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
253 |
* @since 5.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
254 |
* |
19 | 255 |
* @param array $attributes The block attributes. |
256 |
* @param string $content The saved content. |
|
257 |
* @param WP_Block $block The parsed block. |
|
18 | 258 |
* |
259 |
* @return string Returns the page list markup. |
|
260 |
*/ |
|
261 |
function render_block_core_page_list( $attributes, $content, $block ) { |
|
262 |
static $block_id = 0; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
263 |
++$block_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
264 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
$parent_page_id = $attributes['parentPageID']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
$is_nested = $attributes['isNested']; |
18 | 267 |
|
268 |
$all_pages = get_pages( |
|
269 |
array( |
|
19 | 270 |
'sort_column' => 'menu_order,post_title', |
18 | 271 |
'order' => 'asc', |
272 |
) |
|
273 |
); |
|
274 |
||
19 | 275 |
// If there are no pages, there is nothing to show. |
276 |
if ( empty( $all_pages ) ) { |
|
277 |
return; |
|
278 |
} |
|
279 |
||
18 | 280 |
$top_level_pages = array(); |
281 |
||
282 |
$pages_with_children = array(); |
|
283 |
||
19 | 284 |
$active_page_ancestor_ids = array(); |
285 |
||
18 | 286 |
foreach ( (array) $all_pages as $page ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
287 |
$is_active = ! empty( $page->ID ) && ( get_queried_object_id() === $page->ID ); |
19 | 288 |
|
289 |
if ( $is_active ) { |
|
290 |
$active_page_ancestor_ids = get_post_ancestors( $page->ID ); |
|
291 |
} |
|
292 |
||
18 | 293 |
if ( $page->post_parent ) { |
294 |
$pages_with_children[ $page->post_parent ][ $page->ID ] = array( |
|
19 | 295 |
'page_id' => $page->ID, |
296 |
'title' => $page->post_title, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
297 |
'link' => get_permalink( $page ), |
19 | 298 |
'is_active' => $is_active, |
18 | 299 |
); |
300 |
} else { |
|
301 |
$top_level_pages[ $page->ID ] = array( |
|
19 | 302 |
'page_id' => $page->ID, |
303 |
'title' => $page->post_title, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
'link' => get_permalink( $page ), |
19 | 305 |
'is_active' => $is_active, |
18 | 306 |
); |
307 |
||
308 |
} |
|
309 |
} |
|
310 |
||
19 | 311 |
$colors = block_core_page_list_build_css_colors( $attributes, $block->context ); |
18 | 312 |
$font_sizes = block_core_page_list_build_css_font_sizes( $block->context ); |
313 |
$classes = array_merge( |
|
314 |
$colors['css_classes'], |
|
315 |
$font_sizes['css_classes'] |
|
316 |
); |
|
317 |
$style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] ); |
|
318 |
$css_classes = trim( implode( ' ', $classes ) ); |
|
319 |
||
19 | 320 |
$nested_pages = block_core_page_list_nest_pages( $top_level_pages, $pages_with_children ); |
321 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
322 |
if ( 0 !== $parent_page_id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
323 |
// If the parent page has no child pages, there is nothing to show. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
324 |
if ( ! array_key_exists( $parent_page_id, $pages_with_children ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
325 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
326 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
327 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
328 |
$nested_pages = block_core_page_list_nest_pages( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
329 |
$pages_with_children[ $parent_page_id ], |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
330 |
$pages_with_children |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
331 |
); |
18 | 332 |
} |
333 |
||
19 | 334 |
$is_navigation_child = array_key_exists( 'showSubmenuIcon', $block->context ); |
335 |
||
336 |
$open_submenus_on_click = array_key_exists( 'openSubmenusOnClick', $block->context ) ? $block->context['openSubmenusOnClick'] : false; |
|
337 |
||
338 |
$show_submenu_icons = array_key_exists( 'showSubmenuIcon', $block->context ) ? $block->context['showSubmenuIcon'] : false; |
|
339 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
340 |
$wrapper_markup = $is_nested ? '%2$s' : '<ul %1$s>%2$s</ul>'; |
19 | 341 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
342 |
$items_markup = block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids, $colors ); |
19 | 343 |
|
18 | 344 |
$wrapper_attributes = get_block_wrapper_attributes( |
345 |
array( |
|
346 |
'class' => $css_classes, |
|
347 |
'style' => $style_attribute, |
|
348 |
) |
|
349 |
); |
|
350 |
||
351 |
return sprintf( |
|
352 |
$wrapper_markup, |
|
353 |
$wrapper_attributes, |
|
354 |
$items_markup |
|
355 |
); |
|
356 |
} |
|
357 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
358 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
359 |
* Registers the `core/pages` block on server. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
360 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
361 |
* @since 5.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
362 |
*/ |
18 | 363 |
function register_block_core_page_list() { |
364 |
register_block_type_from_metadata( |
|
365 |
__DIR__ . '/page-list', |
|
366 |
array( |
|
367 |
'render_callback' => 'render_block_core_page_list', |
|
368 |
) |
|
369 |
); |
|
370 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
371 |
add_action( 'init', 'register_block_core_page_list' ); |