Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowedBlocks field to block.json to specify allowed children #58262

Merged
merged 13 commits into from
Jan 29, 2024

Conversation

jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Jan 25, 2024

Update: The name of the field is now allowedBlocks, not children, and the option on useInnerBlocksProps is not deprecated, merely reserved for specialized, dynamic usage. See #58262 (comment) for details.

block.json now supports new field, children, with a list of blocks that can be the children of this one. Similar to existing parent and ancestor fields where a block can limit who its parents and ancestors can be.

I'm not adding any __experimental prefix because in my opinion there is nothing experimental about this new field. It's a fairly obvious addition, and parent and ancestor are a good prior art.

It replaces the allowedBlocks option that can be passed to useInnerBlocksProps. This option is passed further down, only to be eventually used by useNestedSettingsUpdate which writes it to the block-editor state accessible with .getBlockListSettings().

Then the only place where .getBlockListSettings().allowedBlocks is ever read is the canInsertBlockType selector.

This allowedBlocks functionality will still be there, for backward compatibility, but if the block type defines children, only this list will be used to determine valid children. allowedBlocks is used only as a fallback when the children field is not there.

I migrated the core/list and core/navigation blocks. If folks like what this PR does, I'll migrate all the rest.

The major advantage of this new approach is that the list of allowed children is part of the block type registration, not only of the block's React edit UI. And it can be extended with hooks. A 3rd party block can make itself a valid list item:

addFilter( 'blocks.registerBlockType', 'my-list-item', ( settings, name ) => {
  if ( name === 'core/list' ) {
    return {
      ...settings,
      children: [ ...settings.children ?? [], 'my/list-item' ],
    }
  }
  return settings;
} );

@jsnajdr jsnajdr added [Feature] Block API API that allows to express the block paradigm. [Package] Blocks /packages/blocks labels Jan 25, 2024
@jsnajdr jsnajdr self-assigned this Jan 25, 2024
Copy link

github-actions bot commented Jan 25, 2024

Size Change: +45 B (0%)

Total Size: 1.7 MB

Filename Size Change
build/block-editor/index.min.js 250 kB +36 B (0%)
build/block-library/index.min.js 215 kB -38 B (0%)
build/blocks/index.min.js 51.5 kB +25 B (0%)
build/edit-site/index.min.js 195 kB +22 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 955 B
build/annotations/index.min.js 2.69 kB
build/api-fetch/index.min.js 2.32 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 578 B
build/block-directory/index.min.js 7.22 kB
build/block-directory/style-rtl.css 1.02 kB
build/block-directory/style.css 1.02 kB
build/block-editor/content-rtl.css 4.38 kB
build/block-editor/content.css 4.38 kB
build/block-editor/default-editor-styles-rtl.css 381 B
build/block-editor/default-editor-styles.css 381 B
build/block-editor/style-rtl.css 15.5 kB
build/block-editor/style.css 15.5 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 126 B
build/block-library/blocks/audio/theme.css 126 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 415 B
build/block-library/blocks/button/editor.css 414 B
build/block-library/blocks/button/style-rtl.css 627 B
build/block-library/blocks/button/style.css 626 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 421 B
build/block-library/blocks/columns/style.css 421 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.69 kB
build/block-library/blocks/cover/style.css 1.68 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 98 B
build/block-library/blocks/details/style.css 98 B
build/block-library/blocks/embed/editor-rtl.css 322 B
build/block-library/blocks/embed/editor.css 322 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 126 B
build/block-library/blocks/embed/theme.css 126 B
build/block-library/blocks/file/editor-rtl.css 316 B
build/block-library/blocks/file/editor.css 316 B
build/block-library/blocks/file/style-rtl.css 280 B
build/block-library/blocks/file/style.css 281 B
build/block-library/blocks/file/view.min.js 316 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/form-input/editor-rtl.css 227 B
build/block-library/blocks/form-input/editor.css 227 B
build/block-library/blocks/form-input/style-rtl.css 343 B
build/block-library/blocks/form-input/style.css 343 B
build/block-library/blocks/form-submission-notification/editor-rtl.css 340 B
build/block-library/blocks/form-submission-notification/editor.css 340 B
build/block-library/blocks/form-submit-button/style-rtl.css 69 B
build/block-library/blocks/form-submit-button/style.css 69 B
build/block-library/blocks/form/view.min.js 452 B
build/block-library/blocks/freeform/editor-rtl.css 2.61 kB
build/block-library/blocks/freeform/editor.css 2.61 kB
build/block-library/blocks/gallery/editor-rtl.css 947 B
build/block-library/blocks/gallery/editor.css 952 B
build/block-library/blocks/gallery/style-rtl.css 1.72 kB
build/block-library/blocks/gallery/style.css 1.72 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 189 B
build/block-library/blocks/heading/style.css 189 B
build/block-library/blocks/html/editor-rtl.css 336 B
build/block-library/blocks/html/editor.css 337 B
build/block-library/blocks/image/editor-rtl.css 863 B
build/block-library/blocks/image/editor.css 862 B
build/block-library/blocks/image/style-rtl.css 1.6 kB
build/block-library/blocks/image/style.css 1.59 kB
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 B
build/block-library/blocks/image/view.min.js 2.01 kB
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 505 B
build/block-library/blocks/media-text/style.css 503 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 668 B
build/block-library/blocks/navigation-link/editor.css 669 B
build/block-library/blocks/navigation-link/style-rtl.css 103 B
build/block-library/blocks/navigation-link/style.css 103 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation/editor-rtl.css 2.25 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.24 kB
build/block-library/blocks/navigation/style.css 2.23 kB
build/block-library/blocks/navigation/view.min.js 1.1 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 235 B
build/block-library/blocks/paragraph/editor.css 235 B
build/block-library/blocks/paragraph/style-rtl.css 335 B
build/block-library/blocks/paragraph/style.css 335 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 508 B
build/block-library/blocks/post-comments-form/style.css 508 B
build/block-library/blocks/post-content/editor-rtl.css 74 B
build/block-library/blocks/post-content/editor.css 74 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 666 B
build/block-library/blocks/post-featured-image/editor.css 662 B
build/block-library/blocks/post-featured-image/style-rtl.css 342 B
build/block-library/blocks/post-featured-image/style.css 342 B
build/block-library/blocks/post-navigation-link/style-rtl.css 215 B
build/block-library/blocks/post-navigation-link/style.css 214 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 409 B
build/block-library/blocks/post-template/style.css 408 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 125 B
build/block-library/blocks/preformatted/style.css 125 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 354 B
build/block-library/blocks/pullquote/style.css 354 B
build/block-library/blocks/pullquote/theme-rtl.css 168 B
build/block-library/blocks/pullquote/theme.css 168 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 486 B
build/block-library/blocks/query/editor.css 486 B
build/block-library/blocks/query/style-rtl.css 312 B
build/block-library/blocks/query/style.css 308 B
build/block-library/blocks/query/view.min.js 1.1 kB
build/block-library/blocks/quote/style-rtl.css 237 B
build/block-library/blocks/quote/style.css 237 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 140 B
build/block-library/blocks/read-more/style.css 140 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 184 B
build/block-library/blocks/search/editor.css 184 B
build/block-library/blocks/search/style-rtl.css 614 B
build/block-library/blocks/search/style.css 614 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/search/view.min.js 471 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 234 B
build/block-library/blocks/separator/style.css 234 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 323 B
build/block-library/blocks/shortcode/editor.css 323 B
build/block-library/blocks/site-logo/editor-rtl.css 754 B
build/block-library/blocks/site-logo/editor.css 754 B
build/block-library/blocks/site-logo/style-rtl.css 204 B
build/block-library/blocks/site-logo/style.css 204 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 682 B
build/block-library/blocks/social-links/editor.css 681 B
build/block-library/blocks/social-links/style-rtl.css 1.49 kB
build/block-library/blocks/social-links/style.css 1.49 kB
build/block-library/blocks/spacer/editor-rtl.css 348 B
build/block-library/blocks/spacer/editor.css 348 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 395 B
build/block-library/blocks/table/editor.css 395 B
build/block-library/blocks/table/style-rtl.css 639 B
build/block-library/blocks/table/style.css 639 B
build/block-library/blocks/table/theme-rtl.css 146 B
build/block-library/blocks/table/theme.css 146 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 185 B
build/block-library/blocks/video/style.css 185 B
build/block-library/blocks/video/theme-rtl.css 126 B
build/block-library/blocks/video/theme.css 126 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.1 kB
build/block-library/common.css 1.1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.3 kB
build/block-library/editor.css 12.3 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 472 B
build/block-library/reset.css 472 B
build/block-library/style-rtl.css 14.7 kB
build/block-library/style.css 14.7 kB
build/block-library/theme-rtl.css 688 B
build/block-library/theme.css 693 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/commands/index.min.js 15.5 kB
build/commands/style-rtl.css 921 B
build/commands/style.css 918 B
build/components/index.min.js 235 kB
build/components/style-rtl.css 12 kB
build/components/style.css 12 kB
build/compose/index.min.js 12.6 kB
build/core-commands/index.min.js 2.71 kB
build/core-data/index.min.js 72.7 kB
build/customize-widgets/index.min.js 12.1 kB
build/customize-widgets/style-rtl.css 1.34 kB
build/customize-widgets/style.css 1.33 kB
build/data-controls/index.min.js 640 B
build/data/index.min.js 8.92 kB
build/date/index.min.js 17.8 kB
build/deprecated/index.min.js 451 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.65 kB
build/edit-post/classic-rtl.css 544 B
build/edit-post/classic.css 545 B
build/edit-post/index.min.js 25 kB
build/edit-post/style-rtl.css 5.67 kB
build/edit-post/style.css 5.66 kB
build/edit-site/style-rtl.css 15.3 kB
build/edit-site/style.css 15.3 kB
build/edit-widgets/index.min.js 17.3 kB
build/edit-widgets/style-rtl.css 4.48 kB
build/edit-widgets/style.css 4.48 kB
build/editor/index.min.js 61.6 kB
build/editor/style-rtl.css 5.42 kB
build/editor/style.css 5.42 kB
build/element/index.min.js 4.83 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 7.85 kB
build/format-library/style-rtl.css 478 B
build/format-library/style.css 477 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.58 kB
build/interactivity/file.min.js 440 B
build/interactivity/image.min.js 2.15 kB
build/interactivity/index.min.js 12.8 kB
build/interactivity/navigation.min.js 1.23 kB
build/interactivity/query.min.js 884 B
build/interactivity/router.min.js 971 B
build/interactivity/search.min.js 610 B
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.74 kB
build/keycodes/index.min.js 1.46 kB
build/list-reusable-blocks/index.min.js 2.11 kB
build/list-reusable-blocks/style-rtl.css 836 B
build/list-reusable-blocks/style.css 836 B
build/media-utils/index.min.js 2.9 kB
build/modules/importmap-polyfill.min.js 12.2 kB
build/notices/index.min.js 948 B
build/nux/index.min.js 2 kB
build/nux/style-rtl.css 735 B
build/nux/style.css 732 B
build/patterns/index.min.js 5.46 kB
build/patterns/style-rtl.css 540 B
build/patterns/style.css 539 B
build/plugins/index.min.js 1.8 kB
build/preferences-persistence/index.min.js 2.07 kB
build/preferences/index.min.js 2.81 kB
build/preferences/style-rtl.css 698 B
build/preferences/style.css 700 B
build/primitives/index.min.js 975 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 1 kB
build/react-i18n/index.min.js 623 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 6.78 kB
build/redux-routine/index.min.js 2.7 kB
build/reusable-blocks/index.min.js 2.72 kB
build/reusable-blocks/style-rtl.css 243 B
build/reusable-blocks/style.css 243 B
build/rich-text/index.min.js 10.4 kB
build/router/index.min.js 1.79 kB
build/server-side-render/index.min.js 1.95 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 2.07 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.72 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 957 B
build/warning/index.min.js 249 B
build/widgets/index.min.js 7.21 kB
build/widgets/style-rtl.css 1.15 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

@skorasaurus
Copy link
Member

skorasaurus commented Jan 25, 2024

This would fulfill #16560

@Mamaduka Mamaduka added the [Type] New API New API to be used by plugin developers or package users. label Jan 26, 2024
@@ -73,6 +73,13 @@
"type": "string"
}
},
"children": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nit-picking but I feel like a more descriptive name would be better. E.g. validChildren or allowedChildren would indicate its a property imposing limitations/constraints on the block.

I was just thinking about people using .children, I can easily see people thinking "Are these my blocks actual children, or allowed children?".

I don't feel super strongly about this so if you think it's fine as-is I'm open to that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be consistent with the existing parent and ancestor fields. They aren't named validParents or allowedAncestors either. That's why I chose the plain children.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense. Like I said, was a nit-pick above anything else so fine with me. 👍🏻

@jsnajdr jsnajdr requested a review from gziolo January 26, 2024 09:17
Copy link
Contributor

@tjcafferkey tjcafferkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests well for me and besides my comment #58262 (comment) which has been addressed, this change LGTM.

Worth noting that even though it's not a regression, using the Block Hooks API you're still able to insert non-allowed children into blocks (e.g. the Navigation block). This is fine as its how it works currently, but I'm raising incase this is something we want to think about/address in the future.

@jsnajdr
Copy link
Member Author

jsnajdr commented Jan 26, 2024

using the Block Hooks API you're still able to insert non-allowed children into blocks (e.g. the Navigation block).

Yes, that's probably because the Block Hooks API runs on the server, and the block parser (wp.blocks.parse) doesn't check the block structure: it will parse any well-formed block markup. Maybe we should add these checks to the block parser validation step.

@gziolo gziolo added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Jan 26, 2024
Comment on lines 1576 to 1588
// If decision can't be made with `blockType.children` (i.e., it's not there)
// decide using the `allowedBlocks` block list setting (as a legacy fallback).
if ( hasParentAllowedBlock === null ) {
const parentAllowedBlocks = parentBlockListSettings?.allowedBlocks;
hasParentAllowedBlock = checkAllowList(
parentAllowedBlocks,
blockName
);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate you've added this fallback (and the rationale for the name change), yet I still wonder if the value of the name change outweighs the additional code that would need to remain indefinitely to cover the backward compatibility. There's also the long tail of documentation out there that is referencing allowedBlocks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name change is not related to this. Until now the allowedBlocks were a part of the block's edit UI, passed as a prop to the <InnerBlocks> component. Example:

function ColumnsEdit() {
  const blockProps = useBlockProps();
  const props = useInnerBlocksProps( blockProps, { allowedBlocks: [ 'core/column' ] } );
  return <div { ...props } />;
}

This way the allowedBlocks info is buried inside React code and is not extensible.

The core idea of this PR is to move this info to block.json. Currently I'm adding it as a children field, but even if it was allowedBlocks, it remains true that we must continue to support InnerBlocks.allowedBlocks, and that there is a long tail of documentation that references InnerBlocks.allowedBlocks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How confusing would it be if we rename children to allowedBlocks and lean on the idea proposed in that PR that if allowedBlocks is not defined in block.json, the prop passed to InnerBlocks will be used, but if it's defined, it would take precedence?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd support using allowedBlocks instead of children. It's immediately clear what it means, and I don't think it's confusing at all, given that we already have the concept of allowedBlocks. We're just moving the place where they're defined. They even have the same shape!

@ockham
Copy link
Contributor

ockham commented Jan 26, 2024

using the Block Hooks API you're still able to insert non-allowed children into blocks (e.g. the Navigation block).

Yes, that's probably because the Block Hooks API runs on the server, and the block parser (wp.blocks.parse) doesn't check the block structure: it will parse any well-formed block markup. Maybe we should add these checks to the block parser validation step.

My preferred course of action would be to modify Block Hooks to check if a hooked block is allowed by it's designated parent block's children field (if any), and only insert it if it is. (We even have an issue for that: #53989.)
Not a blocker to this PR IMO; it's something we can tackle separately (and will need to anyway, as the Block Hooks code lives in Core).

@gziolo
Copy link
Member

gziolo commented Jan 26, 2024

Overall, I like the direction and appreciate the care for introducing an API similar to parent and ancestor. It looks like the final name is the only remaining decision.

On the implementation side, there is one edge case that needs to be taken into account. It's an ongoing effort that was started to allow serializing the list of allowedBlocks as an attribute so it helps to narrow down what's possible with patterns and in similar cases. Related issue: #15682. Example PR: #49981.

The outcome of that is that whenever the block serializes allowedBlocks like in:

<!-- wp:media-text {"mediaId":8,"mediaLink":"http://localhost:8888/?attachment_id=8","mediaType":"image","allowedBlocks":["core/paragraph"]} -->
<div class="wp-block-media-text is-stacked-on-mobile"><figure class="wp-block-media-text__media"><img src="http://localhost:8888/wp-content/uploads/2023/04/ros-buehne-1001900x400-1-1024x216.jpg" alt="" class="wp-image-8 size-full"/></figure><div class="wp-block-media-text__content"></div></div>
<!-- /wp:media-text -->

The expectation would be that "core/paragraph" would be the only allowed child block. So it feels like it should take precedence over the setting that the block type provides with children. The remaining question is whether, the block attribute should allow any block or only subset of the allowed blocks.

@jsnajdr jsnajdr requested a review from geriux as a code owner January 26, 2024 14:06
@jsnajdr
Copy link
Member Author

jsnajdr commented Jan 26, 2024

The existence of the allowedBlocks attribute on some blocks (Cover, Group, ...) is a very good reason to call the block.json field also allowedBlocks. Then we have three variants:

  • in block.json. Determined by block developer, extensible by plugins, non-overridable by content authors.
  • as a block attribute: intended for content authors, when they want to create a template and then lock it down, limiting what the template users can edit.
  • in InnerBlocks: legacy, shouldn't be used by block developers. Except when implementing the allowedBlocks block attribute 🙂 Then the Edit function reads allowedBlocks from attributes and passes it down to useInnerBlocksProps.


const ALLOWED_BLOCKS = variations.map(
( v ) => `core/social-link-${ v.name }`
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. The web version of the Social Links component specifies allowed children as [ 'core/social-link' ]. But the mobile version enumerates all the variations! That looks wrong, not only because the web version doesn't do it, but also because a plugin can register a custom variation. But Social Links won't know about it, because it only knows the hardcoded list of Core variations.

@jsnajdr
Copy link
Member Author

jsnajdr commented Jan 26, 2024

The core/navigation-submenu block does something with allowedBlocks that can't be converted to a block.json field. It filters the ALLOWED_BLOCKS like this:

const allowedBlocks =
  parentCount >= maxNestingLevel
    ? ALLOWED_BLOCKS.filter(
      ( blockName ) => blockName !== 'core/navigation-submenu'
    )
    : ALLOWED_BLOCKS;

This way, a limit on number of nested navigation submenus is implemented.

@cbravobernal cbravobernal removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Jan 31, 2024
@getdave getdave added the Needs PHP backport Needs PHP backport to Core label Feb 1, 2024
@getdave
Copy link
Contributor

getdave commented Feb 1, 2024

👋 I assume this is targeted for WP 6.5?

Can I confirm these are the correct references?

pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Feb 2, 2024
There is a new block.json field called allowedBlocks, added in Gutenberg in WordPress/gutenberg#58262. This adds support for this new field also on the server. 

Props: gziolo, jsnajdr.
Fixes #60403.




git-svn-id: https://develop.svn.wordpress.org/trunk@57521 602fd350-edb4-49c9-b593-d223f7449a82
@gziolo
Copy link
Member

gziolo commented Feb 2, 2024

Everything back ported to WordPress core with https://core.trac.wordpress.org/changeset/57521.

Copy link

github-actions bot commented Feb 2, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @nerrad.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core SVN

If you're a Core Committer, use this list when committing to wordpress-develop in SVN:

Props: jsnajdr, tomjcafferkey, tyxla, isabel_brison, aristath, mamaduka, bernhard-reiter, ntsekouras, gziolo, skorasaurus, ndiego, noisysocks, youknowriad, cbravobernal, get_dave.

GitHub Merge commits

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: nerrad.

Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: tjcafferkey <tomjcafferkey@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: aristath <aristath@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ockham <bernhard-reiter@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: skorasaurus <skorasaurus@git.wordpress.org>
Co-authored-by: ndiego <ndiego@git.wordpress.org>
Co-authored-by: noisysocks <noisysocks@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

markjaquith pushed a commit to WordPress/WordPress that referenced this pull request Feb 2, 2024
There is a new block.json field called allowedBlocks, added in Gutenberg in WordPress/gutenberg#58262. This adds support for this new field also on the server. 

Props: gziolo, jsnajdr.
Fixes #60403.



Built from https://develop.svn.wordpress.org/trunk@57521


git-svn-id: http://core.svn.wordpress.org/trunk@57022 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to gilzow/wordpress-performance that referenced this pull request Feb 2, 2024
There is a new block.json field called allowedBlocks, added in Gutenberg in WordPress/gutenberg#58262. This adds support for this new field also on the server. 

Props: gziolo, jsnajdr.
Fixes #60403.



Built from https://develop.svn.wordpress.org/trunk@57521


git-svn-id: https://core.svn.wordpress.org/trunk@57022 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@getdave getdave added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Needs PHP backport Needs PHP backport to Core labels Feb 2, 2024
@getdave
Copy link
Contributor

getdave commented Feb 6, 2024

Is there a way to add a block to the allowedBlocks list via PHP filters?

@gziolo
Copy link
Member

gziolo commented Feb 6, 2024

Yes, it should be possible with register_block_type_args.

draganescu pushed a commit to draganescu/wordpress-develop that referenced this pull request Feb 8, 2024
* I18N: Prevent PHP warning in `WP_Textdomain_Registry`.

Prevents a warning upon cache invalidation after language pack updates if the arguments don’t have the expected format.

Follow-up to [57287], [57290], [57298], [57299].

See #58919.

git-svn-id: https://develop.svn.wordpress.org/trunk@57303 602fd350-edb4-49c9-b593-d223f7449a82

* Twenty Twenty-Four: Remove extra tab character inside the text domain.

Follow-up to [57281].

Props sabernhardt.
Fixes #60245.

git-svn-id: https://develop.svn.wordpress.org/trunk@57304 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Fix duplicate `determine_locale()` tests added in [57286].

Props johnbillion.
See #58696.

git-svn-id: https://develop.svn.wordpress.org/trunk@57305 602fd350-edb4-49c9-b593-d223f7449a82

* Embeds: Ensure the deprecated function `print_emoji_styles` isn't used

Ensure that the proper new function wp_enqueue_emoji_styles is used in embeds.

Follow-up to: [56194].

Props peterwilsoncc, bobbingwide, hellofromTonya.
Fixes #59892. See: #58775.



git-svn-id: https://develop.svn.wordpress.org/trunk@57306 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Fix unstable query tests.

Three `WP_Query` tests could randomly fail due to an undefined order because two test posts were using the exact same `post_date`.

Props boonebgorges, flixos90.
Fixes #60288.


git-svn-id: https://develop.svn.wordpress.org/trunk@57308 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Fix several typos in inline comments.

Follow-up to [7747], [27419], [55155].

Props shailu25, sabernhardt.
Fixes #60285.

git-svn-id: https://develop.svn.wordpress.org/trunk@57309 602fd350-edb4-49c9-b593-d223f7449a82

* Media: Redirect inactive attachement pages for logged-out users.

Ensure logged out users are redirected to the media file when attachment pages are inactive. This removes the `read_post` capability check from the canonical redirects as anonymous users lack the permission.

Follow-up to [56657], [56658], [56711].

Props afercia, aristath, chesio, joppuyo, jorbin, lakshmananphp, poena, sergeybiryukov.
Fixes #59866.
See #57913.



git-svn-id: https://develop.svn.wordpress.org/trunk@57310 602fd350-edb4-49c9-b593-d223f7449a82

* Twenty Twenty: Move the Inter font declaration to a separate file and enqueue the file.

This allows the font to be dequeued by a child theme or plugin.

Props poena, markhowellsmead, nielslange, Otto42, SGr33n, mukesh27, joemcgill.
Fixes #48630.

git-svn-id: https://develop.svn.wordpress.org/trunk@57311 602fd350-edb4-49c9-b593-d223f7449a82

* Bootstrap/Load: Introduce functions to check whether WordPress is serving a REST API request.

This changeset introduces two functions:
* `wp_is_serving_rest_request()` returns a boolean for whether WordPress is serving an actual REST API request.
* `wp_is_rest_endpoint()` returns a boolean for whether a WordPress REST API endpoint is currently being used. While this is always the case if `wp_is_serving_rest_request()` returns `true`, the function additionally covers the scenario of internal REST API requests, i.e. where WordPress calls a REST API endpoint within the same request.

Both functions should only be used after the `parse_request` action.

All relevant manual checks have been adjusted to use one of the new functions, depending on the use-case. They were all using the same constant check so far, while in fact some of them were intending to check for an actual REST API request while others were intending to check for REST endpoint usage.

A new filter `wp_is_rest_endpoint` can be used to alter the return value of the `wp_is_rest_endpoint()` function.

Props lots.0.logs, TimothyBlynJacobs, flixos90, joehoyle, peterwilsoncc, swissspidy, SergeyBiryukov, pento, mikejolley, iandunn, hellofromTonya, Cybr, petitphp.
Fixes #42061.


git-svn-id: https://develop.svn.wordpress.org/trunk@57312 602fd350-edb4-49c9-b593-d223f7449a82

* Twenty Twenty: Add missing comma in `twentytwenty_classic_editor_styles()`.

This resolves a WPCS error:
{{{
There should be a comma after the last array item in a multi-line array.
}}}

Follow-up to [57311].

See #48630.

git-svn-id: https://develop.svn.wordpress.org/trunk@57313 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Add support for HR element.

Adds support for the following HTML elements to the HTML Processor:

 - HR

Previously, this element was not supported and the HTML Processor would bail when encountering
it. Now, with this patch, it will proceed to parse an HTML document when encountering one.

Developed in WordPress/wordpress-develop#5897

Props jonsurrell, dmsnell
Fixes #60283



git-svn-id: https://develop.svn.wordpress.org/trunk@57314 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Support deferred block variation initialization on the server.

When registering blocks on the server using `register_block_type()` or similar functions, a set of block type variations can also be registered. However, in some cases building this variation data during block registration can be an expensive process, which is not needed in most contexts. 

To address this problem, this adds support to the `WP_Block_Type` object for a new property, `variation_callback`, which can be used to register a callback for building variation data only when the block variations data is needed. The `WP_Block_Type::variations` property has been changed to a private property that is now accessed through the magic `__get()` method. The magic getter makes use of a new public method, `WP_Block_Type::get_variations` which will build variations from a registered callback if variations have not already been built.

Props spacedmonkey, thekt12, Mamaduka, gaambo, gziolo, mukesh27, joemcgill.
Fixes #59969.


git-svn-id: https://develop.svn.wordpress.org/trunk@57315 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Add support for BR, EMBED, & other tags.

Adds support for the following HTML elements to the HTML Processor:

 - AREA, BR, EMBED, KEYGEN, WBR
 - Only the opening BR tag is supported, as the invalid closer `</br>`
   involves more complicated rules, to be implemented later.

Previously, these elements were not supported and the HTML Processor
would bail when encountering them. With this patch it will proceed to
parse an HTML document when encountering those tags as long as other
normal conditions don't cause it to bail (such as complicated format
reconstruction rules).

Props jonsurrell, dmsnell
Fixes #60283



git-svn-id: https://develop.svn.wordpress.org/trunk@57316 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Add support for PRE and LISTING elements.

Adds support for the following HTML elements to the HTML Processor:

 - PRE, LISTING

Previously, these elements were not supported and the HTML Processor would bail when encountering them. Now, with this patch applied, it will proceed to parse an HTML document when encountering those tags.

Developed in WordPress/wordpress-develop#5903

Props jonsurrell, dmsnell
Fixes #60283



git-svn-id: https://develop.svn.wordpress.org/trunk@57317 602fd350-edb4-49c9-b593-d223f7449a82

* Media: Revert [57310].

This commit reintroduced a minor data exposure issue.

Props swissspidy.
See #59866, #57913.



git-svn-id: https://develop.svn.wordpress.org/trunk@57318 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Cleanup tests and list of void elements.

This patch adds newly supported elements to tests that should have been updated
in recent PRs, but which were merged without that. Those PRs removed failing
tests showing that the elements were unsupported, but did not add the elements
to the list of supported ones.

It also removes some elements from the special-exclusion list of unsupported IN
BODY elements. These did not present in failing tests because earlier
conditions in the switch structure caught the tags before hitting the default
block.

Finally it adds some missing elements to the list of void elements. These
elements are not listed as void in the HTML specification because they are
deprecated. However, they are treated as void for the sake of HTML
serialization and the parsing rules indicate that they behave as void elements,
so it's safe to list them within the HTML API as void.

Developed in WordPress/wordpress-develop#5913

Fixes #60307



git-svn-id: https://develop.svn.wordpress.org/trunk@57319 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Correct the placement of `@global` tags in `wp-settings.php`.

Props shailu25, mukesh27.
Fixes #60146.

git-svn-id: https://develop.svn.wordpress.org/trunk@57320 602fd350-edb4-49c9-b593-d223f7449a82

* Plugins: Correct table layout on smaller screens.

This ensures that the message about deleting a plugin or having no plugins installed is displayed in full width.

Follow-up to [26134], [33016].

Props shailu25, mukesh27, passoniate, JavierCasares, sabernhardt.
Fixes #50069.

git-svn-id: https://develop.svn.wordpress.org/trunk@57321 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Expand "imagemin" Grunt task to cover default themes.

Runs `npm run grunt precommit:image` to minify/compress images in the repository.

Props desrosj.
Fixes #58996.

git-svn-id: https://develop.svn.wordpress.org/trunk@57322 602fd350-edb4-49c9-b593-d223f7449a82

* Bundled Theme: Fix a couple of incorrect theme name references.

Corrects the theme name used in docblocks in two places in Twenty Nineteen and Twenty Seventeen.

Props shailu25, mukesh27.
Fixes #60310.


git-svn-id: https://develop.svn.wordpress.org/trunk@57323 602fd350-edb4-49c9-b593-d223f7449a82

* Twenty Twenty-Four: Update license information in readme.

Adds missing license information for bundled fonts.

Props acosmin, shailu25, poena, sabernhardt.
Fixes #59838

git-svn-id: https://develop.svn.wordpress.org/trunk@57324 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Correct the `WP_User Query` location reference in query cache tests.

Follow-up to [1047/tests], [33749], [55657].

See #59651.

git-svn-id: https://develop.svn.wordpress.org/trunk@57325 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Support PARAM, SOURCE, and TRACK tags.

Adds support for the following HTML elements to the HTML Processor:

 - PARAM, SOURCE, TRACK

Previously these elements were not supported and the HTML Processor would bail when encountering them. Now, with this patch applied, it will proceed to parse an HTML document when encountering those tags.

Props jonsurrell, dmsnell
Fixes #60283



git-svn-id: https://develop.svn.wordpress.org/trunk@57326 602fd350-edb4-49c9-b593-d223f7449a82

* Script Modules API: Rename `wp_module` to `wp_script_module`

Renames all mentions to "module" with "script module", including function names, comments, and tests.

Follow up to [57269]

The list of functions renamed are:

 - `wp_module()`          -> `wp_script_module()`.
 - `wp_register_module()` -> `wp_register_script_module()`.
 - `wp_enqueue_module()`  -> `wp_enqueue_script_module()`.
 - `wp_dequeue_module()`  -> `wp_dequeue_script_module()`.
 - `WP_Script_Modules::print_enqueued_modules()` -> `WP_Script_Modules::print_enqueued_script_modules()`.
 - `WP_Script_Modules::print_module_preloads()`  -> `WP_Script_Modules::print_script_module_preloads()`.

It also adds PHP 7 typing to all the functions and improves the types of the `$deps` argument of `wp_register_script_module()` and `wp_enqueue_script_module()` using `@type`.

Props luisherranz, idad5, costdev, nefff, joemcgill, jorbin, swisspidy, jonsurrel, flixos90, gziolo, westonruter, bernhard-reiter, kamranzafar4343
See #56313



git-svn-id: https://develop.svn.wordpress.org/trunk@57327 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: fix classname output on blocks without layout.

Prevents layout classnames from being output on blocks with no layout support and no child layout classnames by returning early from `wp_render_layout_support_flag`.

Props andrewserong.
Fixes #60292.


git-svn-id: https://develop.svn.wordpress.org/trunk@57328 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: fix fluid font division by zero error when min and max viewport widths are equal.

Fixes a division error by returning null when `minViewportWidth` - `maxViewportWidth` is zero in `wp_get_computed_fluid_typography_value`.

Props ramonopoly, mukesh27, andrewserong, audrasjb.
Fixes #60263.


git-svn-id: https://develop.svn.wordpress.org/trunk@57329 602fd350-edb4-49c9-b593-d223f7449a82

* Build Tools: Configure prettier properly.

Allows tools like prettier or VSCode to auto-format JS files propertly.
It pulls the prettier config that is used in the Gutenberg repository.

Props gziolo.
Fixes #60316.

git-svn-id: https://develop.svn.wordpress.org/trunk@57330 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Set show_tagcloud to false for Pattern Categories.

Pattern Categories is a taxonomy used to categories the patterns in the site editor.
It is not meant to be shown in the frontend and show tag clouds.

Props wildworks, mukesh27.
Fixes #60119.

git-svn-id: https://develop.svn.wordpress.org/trunk@57331 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Ensure PHPUnit10 compatibility for ThemeJson unit test.

Expecting E_STRICT, E_NOTICE, and E_USER_NOTICE errors is deprecated in PHPUnit 10.
This updates the test to rely on an exception instead.

Props antonvlasenko.
Fixes #60305.

git-svn-id: https://develop.svn.wordpress.org/trunk@57332 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Update the ThemeJson unit test to cover custom CSS feature.

In #59499 a fix have been shipped to theme.json custom CSS
when applied to blocks with multiple CSS selectors.
This commit covers that fix with a unit test.

Props wildworks.
Fixes #60294.

git-svn-id: https://develop.svn.wordpress.org/trunk@57333 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Define the labels of the pattern category taxonomy.

In WordPress 6.5, the taxonomy is going to be rendered using a standard UI
in the editor, this means that all the labels need to be defined properly.

Props ntsekouras.
Fixes #60322.

git-svn-id: https://develop.svn.wordpress.org/trunk@57334 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Fix back to items label capitalization for the pattern categories.

This uses the same capitalization used in Tags or Link Categories taxonomies.

Props mukesh27.
See #60322.

git-svn-id: https://develop.svn.wordpress.org/trunk@57335 602fd350-edb4-49c9-b593-d223f7449a82

* General: Add $schema property to block and theme JSON files.

Additionally, this changeset fixes some of the `block.json` and `theme.json` files in PHPUnit tests by adding missing `title` properties to satisfy the schema. Those changes have no impact on the runtime whatsoever and do not change the result of unit tests.

Note that some block and theme JSON files still aren't valid according to the schema. Fixing is underway; the required changes will be merged subsequently.

Props jonsurrell, dmsnell, gziolo.
Fixes #60255.

git-svn-id: https://develop.svn.wordpress.org/trunk@57336 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Introduce a more performant localization library.

This introduces a more lightweight library for loading `.mo` translation files which offers increased speed and lower memory usage.
It also supports loading multiple locales at the same time, which makes locale switching faster too.

For plugins interacting with the `$l10n` global variable in core, a shim is added to retain backward compatibility with the existing `pomo` library.

In addition to that, this library supports translations contained in PHP files, avoiding a binary file format and leveraging OPCache if available.
If an `.mo` translation file has a corresponding `.l10n.php` file, the latter will be loaded instead.
This behavior can be adjusted using the new `translation_file_format` and `load_translation_file` filters.

PHP translation files will be typically created by downloading language packs, but can also be generated by plugins.
See https://make.wordpress.org/core/2023/11/08/merging-performant-translations-into-core/ for more context.

Props dd32, swissspidy, flixos90, joemcgill, westonruter, akirk, SergeyBiryukov.
Fixes #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57337 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Add missing variable in string replacement.

Ensures the preferred file name for lookup has the correct extension.

Follow-up to [57337].
See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57338 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Improve edge case handling in `WP_Translation_Controller`.

Prevents PHP warnings for possibly undefined array keys.
Also fixes incorrect `@covers` annotations.

Follow-up to [57337].
See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57339 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Unset reference used in foreach statement.

In PHP it is a good practice to unset $value if it was created by reference in a foreach loop, as the reference is still valid outside the loop, and this avoids accidental bugs.

Props get_dave.
Fixes #60326.

git-svn-id: https://develop.svn.wordpress.org/trunk@57340 602fd350-edb4-49c9-b593-d223f7449a82

* Script Loader: Only emit CDATA wrapper comments in `wp_get_inline_script_tag()` for JavaScript.

This avoids erroneously adding CDATA wrapper comments for non-JavaScript scripts, including those for JSON such as the `importmap` for script modules in #56313.

Props westonruter, flixos90, mukesh27, dmsnell.
See #56313.
Fixes #60320.


git-svn-id: https://develop.svn.wordpress.org/trunk@57341 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Add missing full stop in `WP_Comment_Query::parse_query()` DocBlock.

Props hardik2221.
Fixes #60323.

git-svn-id: https://develop.svn.wordpress.org/trunk@57342 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Support INPUT tags.

Adds support for the following HTML elements to the HTML Processor:

 - INPUT

Previously this element was not supported and the HTML Processor would bail when encountering one. Now, with this patch applied, it will proceed to parse the HTML document.

Developed in https://github.com/WordPress/wordpress-develop/pull/5907
Discussed in https://core.trac.wordpress.org/ticket/60283

Props jonsurrell
See #60283



git-svn-id: https://develop.svn.wordpress.org/trunk@57343 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Improve docblocks after [57337].

Props mukesh27.
See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57344 602fd350-edb4-49c9-b593-d223f7449a82

* Script Loader: Load the modules to the footer in classic themes

Incremental import maps fail if the import map is printed after the module scripts.
This means, we should always render import maps first. This means that for classic themes, we need to move the import map and modules to the footer because we can't know before that which modules are needed.

Props luisherranz, cbravobernal.
Fixes #60240.

git-svn-id: https://develop.svn.wordpress.org/trunk@57345 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Scan all syntax tokens in a document, read modifiable text.

Since its introduction in WordPress 6.2 the HTML Tag Processor has
provided a way to scan through all of the HTML tags in a document and
then read and modify their attributes. In order to reliably do this, it
also needed to be aware of other kinds of HTML syntax, but it didn't
expose those syntax tokens to consumers of the API.

In this patch the Tag Processor introduces a new scanning method and a
few helper methods to read information about or from each token. Most
significantly, this introduces the ability to read `#text` nodes in the
document.

What's new in the Tag Processor?
================================

 - `next_token()` visits every distinct syntax token in a document.
 - `get_token_type()` indicates what kind of token it is.
 - `get_token_name()` returns something akin to `DOMNode.nodeName`.
 - `get_modifiable_text()` returns the text associated with a token.
 - `get_comment_type()` indicates why a token represents an HTML comment.

Example usage.
==============

{{{
<?php
function strip_all_tags( $html ) {
        $text_content = '';
        $processor    = new WP_HTML_Tag_Processor( $html );

        while ( $processor->next_token() ) {
                if ( '#text' !== $processor->get_token_type() ) {
                        continue;
                }

                $text_content .= $processor->get_modifiable_text();
        }

        return $text_content;
}
}}}

What changes in the Tag Processor?
==================================

Previously, the Tag Processor would scan the opening and closing tag of
every HTML element separately. Now, however, there are special tags
which it only visits once, as if those elements were void tags without
a closer.

These are special tags because their content contains no other HTML or
markup, only non-HTML content.

 - SCRIPT elements contain raw text which is isolated from the rest of
   the HTML document and fed separately into a JavaScript engine. There
   are complicated rules to avoid escaping the script context in the HTML.
   The contents are left verbatim, and character references are not decoded.

 - TEXTARA and TITLE elements contain plain text which is decoded
   before display, e.g. transforming `&amp;` into `&`. Any markup which
   resembles tags is treated as verbatim text and not a tag.

 - IFRAME, NOEMBED, NOFRAMES, STYLE, and XMP elements are similar to the
   textarea and title elements, but no character references are decoded.
   For example, `&amp;` inside a STYLE element is passed to the CSS engine
   as the literal string `&amp;` and _not_ as `&`.

Because it's important not treat this inner content separately from the
elements containing it, the Tag Processor combines them when scanning
into a single match and makes their content available as modifiable
text (see below).

This means that the Tag Processor will no longer visit a closing tag for
any of these elements unless that tag is unexpected.

{{{
    <title>There is only a single token in this line</title>
    <title>There are two tokens in this line></title></title>
    </title><title>There are still two tokens in this line></title>
}}}

What are tokens?
================

The term "token" here is a parsing term, which means a primitive unit in
HTML. There are only a few kinds of tokens in HTML:

 - a tag has a name, attributes, and a closing or self-closing flag.
 - a text node, or `#text` node contains plain text which is displayed
   in a browser and which is decoded before display.
 - a DOCTYPE declaration indicates how to parse the document.
 - a comment is hidden from the display on a page but present in the HTML.

There are a few more kinds of tokens that the HTML Tag Processor will
recognize, some of which don't exist as concepts in HTML. These mostly
comprise XML syntax elements that aren't part of HTML (such as CDATA and
processing instructions) and invalid HTML syntax that transforms into
comments.

What is a funky comment?
========================

This patch treats a specific kind of invalid comment in a special way.
A closing tag with an invalid name is considered a "funky comment." In
the browser these become HTML comments just like any other, but their
syntax is convenient for representing a variety of bits of information
in a well-defined way and which cannot be nested or recursive, given
the parsing rules handling this invalid syntax.

 - `</1>`
 - `</%avatar_url>`
 - `</{"wp_bit": {"type": "post-author"}}>`
 - `</[post-author]>`
 - `</__( 'Save Post' );>`

All of these examples become HTML comments in the browser. The content
inside the funky content is easily parsable, whereby the only rule is
that it starts at the `<` and continues until the nearest `>`. There
can be no funky comment inside another, because that would imply having
a `>` inside of one, which would actually terminate the first one.

What is modifiable text?
========================

Modifiable text is similar to the `innerText` property of a DOM node.
It represents the span of text for a given token which may be modified
without changing the structure of the HTML document or the token.

There is currently no mechanism to change the modifiable text, but this
is planned to arrive in a later patch.

Tags
====

Most tags have no modifiable text because they have child nodes where
text nodes are found. Only the special tags mentioned above have
modifiable text.

{{{
    <div class="post">Another day in HTML</div>
    └─ tag ──────────┘└─ text node ─────┘└────┴─ tag
}}}

{{{
    <title>Is <img> &gt; <image>?</title>
    │      └ modifiable text ───┘       │ "Is <img> > <image>?"
    └─ tag ─────────────────────────────┘
}}}

Text nodes
==========

Text nodes are entirely modifiable text.

{{{
    This HTML document has no tags.
    └─ modifiable text ───────────┘
}}}

Comments
========

The modifiable text inside a comment is the portion of the comment that
doesn't form its syntax. This applies for a number of invalid comments.

{{{
    <!-- this is inside a comment -->
    │   └─ modifiable text ──────┘  │
    └─ comment token ───────────────┘
}}}

{{{
    <!-->
    This invalid comment has no modifiable text.
}}}

{{{
    <? this is an invalid comment -->
    │ └─ modifiable text ────────┘  │
    └─ comment token ───────────────┘
}}}

{{{
    <[CDATA[this is an invalid comment]]>
    │       └─ modifiable text ───────┘ │
    └─ comment token ───────────────────┘
}}}

Other token types also have modifiable text. Consult the code or tests
for further information.

Developed in https://github.com/WordPress/wordpress-develop/pull/5683
Discussed in https://core.trac.wordpress.org/ticket/60170

Follows [57575]

Props bernhard-reiter, dlh, dmsnell, jonsurrell, zieladam
Fixes #60170



git-svn-id: https://develop.svn.wordpress.org/trunk@57348 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Fix typo in `_get_block_template_file()` DocBlock.

Follow-up to [55744].

See #59651.

git-svn-id: https://develop.svn.wordpress.org/trunk@57349 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Rename `WP_Translation_Controller::instance()` method to `get_instance()`.

This improves consistency as `get_instance()` is more commonly used in core. 

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57350 602fd350-edb4-49c9-b593-d223f7449a82

* Twenty Twenty-Four: Change font family slug to lowercase.

Ensures referencing the correct CSS custom property.

Props RavanH, poena, onemaggie, huzaifaalmesbah, mukesh27.
Fixes #60325.

git-svn-id: https://develop.svn.wordpress.org/trunk@57351 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Fix Theme.json application of custom root selector for styles.

Theme.json stylesheets attempting to use a custom root selector are generated with in correct styles.

Props aaronrobertshaw, get_dave, mukesh27.
Fixes #60343.

git-svn-id: https://develop.svn.wordpress.org/trunk@57352 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Add video and audio pattern categories.

More categories, better organization for patterns
as they grow and power more WordPress websites.

Props aaronrobertshaw, get_dave.
Fixes #60342.

git-svn-id: https://develop.svn.wordpress.org/trunk@57353 602fd350-edb4-49c9-b593-d223f7449a82

* Block Hooks: Introduce a new `hooked_block_{$block_type}` filter.

Add a new `hooked_block_{$block_type}` filter that allows modifying a hooked block (in parsed block format) prior to insertion, while providing read access to its anchor block (in the same format).

This allows block authors to e.g. set a hooked block's attributes, or its inner blocks; the filter can peruse information about the anchor block when doing so. As such, this filter provides a solution to both #59572 and #60126.

The new filter is designed to strike a good balance and separation of concerns with regard to the existing [https://developer.wordpress.org/reference/hooks/hooked_block_types/ `hooked_block_types` filter], which allows addition or removal of a block to the list of hooked blocks for a given anchor block -- all of which are identified only by their block ''types''. This new filter, on the other hand, only applies to ''one'' hooked block at a time, and allows modifying the entire (parsed) hooked block; it also gives (read) access to the parsed anchor block.

Props gziolo, tomjcafferkey, andrewserong, isabel_brison, timbroddin, yansern.
Fixes #59572, #60126.

git-svn-id: https://develop.svn.wordpress.org/trunk@57354 602fd350-edb4-49c9-b593-d223f7449a82

* Block Hooks: Amend PHPDoc for `hooked_block_{$hooked_block_type}` filter.

Add missing explanation of the dynamic part of the hook name.

Follow-up [57354].
Props swissspidy.
See #59572, #60126.

git-svn-id: https://develop.svn.wordpress.org/trunk@57355 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Fix a few typos in `wp-includes/pomo/po.php`.

Props shailu25.
Fixes #60346.

git-svn-id: https://develop.svn.wordpress.org/trunk@57356 602fd350-edb4-49c9-b593-d223f7449a82

* Media: Redirect inactive attachment pages for logged-out users.

Ensure logged out users are redirected to the media file when attachment pages are inactive. This removes the read_post capability check from the canonical redirects as anonymous users lack the permission.

This was previously committed in [57310] before being reverted in [57318]. This update includes a fix to cover instances where revealing a URL could be considered a data leak and greatly expands the unit tests to ensure that this is covered along with many other instances.

Follow-up to [56657], [56658], [56711], [57310], [57318].

Props peterwilsoncc, jorbin, afercia, aristath, chesio, joppuyo, jorbin, lakshmananphp, poena, sergeybiryukov, swissspidy, johnbillion.
Fixes #59866.
See #57913.


git-svn-id: https://develop.svn.wordpress.org/trunk@57357 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Tests: Ensure set_error_handler is cleaned up.

Follow up to: [57332].

Fixes #60305.



git-svn-id: https://develop.svn.wordpress.org/trunk@57361 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Update third-party GitHub Actions.

This updates the following third-party GitHub Actions to their latest versions:

- `actions/setup-node` from `3.8.1` to `4.0.1`
- `actions/upload-artifact` from `3.1.2` to `4.3.0`
- `shivammathur/setup-php` from `2.28.0` to `2.29.0`
- `actions/cache` from `3.3.2` to `4.0.0`
- `codecov/codecov-action` from `3.1.4` to `3.1.5`

Most notably, these updates silence newly encountered notices as a result of GitHub beginning to transition away from Node.js 16 to Node.js 20 (see https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/).

Props swissspidy.
See #59805.

git-svn-id: https://develop.svn.wordpress.org/trunk@57362 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Update the `caniuse` data.

This updates the `caniuse-lite` database and includes all resulting CSS and built file changes, which are all minor changes due to fluctuations in browser usage.

Props gziolo, jonsurrell.
See #59657.

git-svn-id: https://develop.svn.wordpress.org/trunk@57363 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Add missing escaping in `Custom_Image_Header::step_2()`.

Follow-up to [4673], [14907].

Props nareshbheda, audrasjb, kebbet.
Fixes #59278.

git-svn-id: https://develop.svn.wordpress.org/trunk@57364 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Fix some spaces on block-supports background.

When we run composer format these changes are applied so I guess we should just commit them to avoid seeing the changes again the future.

git-svn-id: https://develop.svn.wordpress.org/trunk@57365 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Add original_source and author_text to the templates REST API.

For the new "All templates" UI to work properly we need the REST API to provide to additional fields original_source, and author_text.

Props ntsekouras, get_dave.
Fixes #60358.

git-svn-id: https://develop.svn.wordpress.org/trunk@57366 602fd350-edb4-49c9-b593-d223f7449a82

* Script Loader: Clarify in docs that `wp_get_inline_script_tag()` and `wp_print_inline_script_tag()` can take non-JS data.

Props vladimiraus.
Fixes #60331.


git-svn-id: https://develop.svn.wordpress.org/trunk@57367 602fd350-edb4-49c9-b593-d223f7449a82

* Tests: Expand `sanitize_text_field()` tests.

This change ensures that the `sanitize_text_field` and `sanitize_textarea_field` filters are correctly invoked for the respective functions.

Follow-up to [38944].

Props pbearne, audrasjb.
Fixes #60357.

git-svn-id: https://develop.svn.wordpress.org/trunk@57368 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Add missing escaping functions to `WP_Customize_Control` and `WP_Customize_Nav_Menu_Location_Control`.

Follow-up to [20295], [32806].

Props nareshbheda, shailu25, sabernhardt, audrasjb.
Fixes #60324.





git-svn-id: https://develop.svn.wordpress.org/trunk@57369 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Improve various globals documentation, as per docblock standards.

Props upadalavipul, audrasjb, shailu25, viralsampat.
Fixes #59255.
See #59651.





git-svn-id: https://develop.svn.wordpress.org/trunk@57370 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Typo correction in `wp_internal_hosts` docblock.

Follow-up to [55289].

Props shailu25.
Fixes #60363.





git-svn-id: https://develop.svn.wordpress.org/trunk@57371 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Use strict type check for `in_array()` in `get_hooked_block_markup()`.

This aims to prevent type juggling causing incorrect results.

Follow-up to [57157].

Props jrf.
See #60279.

git-svn-id: https://develop.svn.wordpress.org/trunk@57372 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Add registry for block binding sources

It is part of the sync from the Gutenberg plugin that introduces the registry for block binding sources required for the new Block Bindings API: https://github.com/WordPress/gutenberg/issues/54536.

See #60282.
Props czapla, artemiosans, santosguillamot, sc0ttkclark, lgladdy, talldanwp, swissspidy, youknowriad, fabiankaegy.



git-svn-id: https://develop.svn.wordpress.org/trunk@57373 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Remove unnecessary access and internal annotations from two functions in WP_REST_Templates_Controller.

This commit removes unnecessary access and internal annotations from two functions that are private and as such don't require the annotation. It also adds the since annotation with the 6.5 release given that the annotation may be useful.

Props swissspidy.
See #60358.

git-svn-id: https://develop.svn.wordpress.org/trunk@57374 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Add Block Bindings API helpers

It is part of the sync from the Gutenberg plugin that introduces the registry for block binding sources required for the new Block Bindings API: WordPress/gutenberg#54536.

See #60282.
Follow-up [57373].
Props czapla, artemiosans, santosguillamot, sc0ttkclark, lgladdy, talldanwp, swissspidy, youknowriad, fabiankaegy, mukesh27.



git-svn-id: https://develop.svn.wordpress.org/trunk@57375 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Update third-party Slack action.

This updates the `slackapi/slack-github-action` from `1.24.0` to `1.25.0`. This fixes more GitHub Action deprecated notices.

Follow up to [57362].

See #59805.

git-svn-id: https://develop.svn.wordpress.org/trunk@57376 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.

This patch, somewhat small brings a lot to WordPress. 
This includes features like:

 - DataViews.
 - Customization tools like box shadow, background size and repeat.
 - UI improvements in the site editor. 
 - Preferences sharing between the post and site editors.
 - Unified panels and editors between post and site editors.
 - Improved template mode in the post editor.
 - Iterations to multiple interactive blocks.
 - Preparing the blocks and UI for pattern overrides.
 - and a lot more.

Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.

git-svn-id: https://develop.svn.wordpress.org/trunk@57377 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Update PHPCS to version 3.8.1.

PHPCS has seen two new releases since the update to WPCS 3.0, with especially the 3.8.0 version containing a huge number of improvements.

References:
* [https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.8.0 PHP_CodeSniffer 3.8.0 release notes]
* [https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.8.1 PHP_CodeSniffer 3.8.1 release notes]

Follow-up to [56695].

Props jrf, swissspidy.
Fixes #60279.

git-svn-id: https://develop.svn.wordpress.org/trunk@57378 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Test against MySQL 8.3

Version 8.3 is the latest short-term innovation release of MySQL.

See #59779.

git-svn-id: https://develop.svn.wordpress.org/trunk@57379 602fd350-edb4-49c9-b593-d223f7449a82

* REST API: Support assigning terms when creating attachments.

Props mukesh27, Dharm1025, Ankit K Gupta, swissspidy, dharm1025, tanjimtc71, timothyblynjacobs, spacedmonkey.
Fixes #57897.

git-svn-id: https://develop.svn.wordpress.org/trunk@57380 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Ensure `.l10n.php` files are deleted when upgrading language packs.

Props amieiro.
See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57381 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Delete `.l10n.php` files when deleting a theme.

Follow-up to [57337] where this was already added for plugins.

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57382 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Fix PHP warning in Layout block support.

strpos was triggering a php warning. 
This also updates the code to use the now supported str_contains.

Props get_dave, dmsnell, ocean90, mukesh27.
Fixes #60327.

git-svn-id: https://develop.svn.wordpress.org/trunk@57383 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Update the minimum compatible version of Gutenberg.

Previous Gutenberg versions are not compatible with recent trunk because of the
WP_Navigation_Block_Renderer classname. It's present in both.

Gutenberg has been updated to avoid the use of this class but we need to auto-disable 
old plugins to avoid fatals.

Props hellofromtonya.
See #60315.

git-svn-id: https://develop.svn.wordpress.org/trunk@57384 602fd350-edb4-49c9-b593-d223f7449a82

* Tests: Remove redundant unregister call in block bindings tear down

Only block bindings sources registered in the tests should get unregistered.

Follow-up for [57375].
See #60282.
Props czapla.



git-svn-id: https://develop.svn.wordpress.org/trunk@57385 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Improve singular lookup of pluralized strings.

Ensures that looking up a singular that is also used as a pluralized string works as expected.
This improves compatibility for cases where for example both `__( 'Product' )` and `_n( 'Product', 'Products’, num )` are used in a project, where both will use the same translation for the singular version.

Although such usage is not really recommended nor documented, it must continue to work in the new i18n library in order to maintain backward compatibility and maintain expected behavior.

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57386 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Add missing space after `foreach` keyword.

Follow-up to [57386].

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57387 602fd350-edb4-49c9-b593-d223f7449a82

* Uploads: Check for and verify ZIP archives.

Props costdev, peterwilsoncc, azaozz, tykoted, johnbillion, desrosj, afragen, jorbin.


git-svn-id: https://develop.svn.wordpress.org/trunk@57388 602fd350-edb4-49c9-b593-d223f7449a82

* Install: When populating options, maybe_serialize instead of always serialize.

Props xknown, peterwilsoncc, jorbin, desrosj.


git-svn-id: https://develop.svn.wordpress.org/trunk@57389 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Fix splitting single text node.

When `next_token()` was introduced, it brought a subtle bug. When encountering a `<` in the HTML stream which did not lead to a tag or comment or other token, it was treating the full text span to that point as one text node, and the following span another text node.

The entire span should be one text node.

In this patch the Tag Processor properly detects this scenario and combines the spans into one text node.

Follow-up to [57348]

Props jonsurrell
Fixes #60385



git-svn-id: https://develop.svn.wordpress.org/trunk@57489 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: reduce specificity of block style variation selector.

Removes duplicate classname from the block style variation selector generated in `WP_Theme_JSON`’s `get_blocks_metadata` function.

Props flixos90, joemcgill, mukesh27, isabel_brison.
Fixes #60312.


git-svn-id: https://develop.svn.wordpress.org/trunk@57490 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: introduce `dimensions.aspectRatio` block support.

Adds front end rendering logic for the `dimensions.aspectRatio` block support as well as the required logic in `WP_Theme_JSON` and the style engine.

Props andrewserong.
Fixes #60365.


git-svn-id: https://develop.svn.wordpress.org/trunk@57491 602fd350-edb4-49c9-b593-d223f7449a82

* Script Modules API: Add import map polyfill for older browsers

Syncs the changes from https://github.com/WordPress/gutenberg/pull/58263. Adds a polyfill to make import maps compatible with unsported browsers (https://caniuse.com/import-maps).

Fixes #60348.
Props cbravobernal, jorbin, luisherranz, jonsurrell.



git-svn-id: https://develop.svn.wordpress.org/trunk@57492 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Add `viewStyle` property to `block.json` for frontend-only block styles

Related issue in Gutenberg: https://github.com/WordPress/gutenberg/issues/54491.

For block scripts there was already `script`, `viewScript` and `editorScript`. For block styles there was only `style` and `editorStyle`. This brings the parity.

Props gaambo.
Fixes #59673. 



git-svn-id: https://develop.svn.wordpress.org/trunk@57493 602fd350-edb4-49c9-b593-d223f7449a82

* REST API: Add route for single styles revisions.

Adds a route for single global styles revisions: /wp/v2/global-styles/${ parentId }/revisions/${ revisionsId }
This fixes the `getRevision` actions in the core-data package.

Props ramonopoly, get_dave.
Fixes #59810.

git-svn-id: https://develop.svn.wordpress.org/trunk@57494 602fd350-edb4-49c9-b593-d223f7449a82

* Twenty Eleven: Fix typo in `twentyeleven_widgets_init()` description.

Follow-up to [17738].

Props harshgajipara.
See #60383.

git-svn-id: https://develop.svn.wordpress.org/trunk@57495 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Sanitize nested array in theme.json properly.

WP_Theme_JSON sanitization is now able to sanitize data contained on indexed arrays. 
So certain data from theme.json, for example, settings.typography.fontFamilies which is a JSON array will be sanitized.

Props mmaattiiaass, mukesh27.
Fixes #60360.

git-svn-id: https://develop.svn.wordpress.org/trunk@57496 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Fix Theme.json font settings in unit test.

These changes fix incorrect font settings when testing the generation of a theme.json stylesheet.

Props aaronrobertshaw, mukesh27.
Fixes #60341.

git-svn-id: https://develop.svn.wordpress.org/trunk@57497 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Fix Theme.json font settings unit test.

This file has been ommitted from the previous commit [57497].

See #60341.

git-svn-id: https://develop.svn.wordpress.org/trunk@57498 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Update WordPress packages to Gutenberg 16.7 RC3.

It brings with a set of iterations and follow-ups to the initial package update.
It also fixes a regression that happened for interactive blocks.

Props gziolo, luisherranz, cbravobernal.
See #60315.

git-svn-id: https://develop.svn.wordpress.org/trunk@57499 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: fix small typos in block bindings API docblocks.

Props shailu25.
See #60282.
Fixes #60386.

git-svn-id: https://develop.svn.wordpress.org/trunk@57500 602fd350-edb4-49c9-b593-d223f7449a82

* HTTP API: Ensure cookie names are cast to strings.

Props nosilver4u, darssen, kraftbj, engahmeds3ed, barry.hughes, schlessera.
Fixes #58566.

git-svn-id: https://develop.svn.wordpress.org/trunk@57501 602fd350-edb4-49c9-b593-d223f7449a82

* Twenty Twenty-Three: Rename Comments template part.

This renames the Comments template part to 'Comments Template Part', to reduce confusion with the 'Comments' block when viewing both in the inserter.

Props mikachan, mukesh27, poena.
Fixes #56999.

git-svn-id: https://develop.svn.wordpress.org/trunk@57502 602fd350-edb4-49c9-b593-d223f7449a82

* Script Loader: Use a global variable in `wp_script_modules()`.

This brings the function more in line with its related `wp_scripts()` and `wp_styles()` functions and makes it easier to reset the class instance in tests.

Props westonruter, luisherranz.
See #56313.

git-svn-id: https://develop.svn.wordpress.org/trunk@57503 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Load new translation library in `wp_load_translations_early()`.

Ensures localization continues to work as expected with the new library in case
translations need to be loaded early in the process.

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57504 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Revert [57386] pending further investigation.

Reverts the change for fallback string lookup due to a performance regression in the bad case scenario.

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57505 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Fix CDATA lookalike matching invalid CDATA

When `next_token()` was introduced to the HTML Tag Processor, it started
classifying comments that look like they were intended to be CDATA sections.
In one of the changes made during development, however, a typo slipped
through code review that treated comments as CDATA even if they only
ended in `]>` and not the required `]]>`.

The consequences of this defect were minor because in all cases these are
treated as HTML comments from invalid syntax, but this patch adds the
missing check to ensure the proper reporting of CDATA-lookalikes.

Follow-up to [57348]

Props jonsurrell
Fixes #60406



git-svn-id: https://develop.svn.wordpress.org/trunk@57506 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Fix void tag nesting with next_token

When `next_token()` was introduced, it introduced a regression in the HTML
Processor whereby void tags remain on the stack of open elements when they
shouldn't. This led to invalid values returned from `get_breadcrumbs()`.

The reason was that calling `next_token()` works through a different code path
than the HTML Processor runs everything else. To solve this, its sub-classed
`next_token()` called `step( self::REPROCESS_CURRENT_TOKEN )` so that the proper
HTML accounting takes place.

Unfortunately that same reprocessing code path skipped the step whereby void
and self-closing elements are popped from the stack of open elements.

In this patch, that step is run with a third mode for `step()`, which is the
new `self::PROCESS_CURRENT_TOKEN`. This mode acts as if `self::PROCESS_NEXT_NODE`
were called, except it doesn't advance the parser.

Developed in https://github.com/WordPress/wordpress-develop/pull/5975
Discussed in https://core.trac.wordpress.org/ticket/60382

Follow-up to [57348]

Props dmsnell, jonsurrell
Fixes #60382



git-svn-id: https://develop.svn.wordpress.org/trunk@57507 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Test cleanup

Rename `$p` variable to `$processor` in tests for clarity.

Use static data providers. A mix of static and non-static data providers were
used in HTML API tests.  Data providers are required to be static in the next
PHPUnit version and there's no harm in using them consistently now.

Follow-up to [57507]

Props jonsurrell
See #59647



git-svn-id: https://develop.svn.wordpress.org/trunk@57508 602fd350-edb4-49c9-b593-d223f7449a82

* Docs: Fix typo in `do_robots()` docblock.

This was introduced in [45928].

Props shailu25, mukesh27.
Fixes #60405.

git-svn-id: https://develop.svn.wordpress.org/trunk@57509 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Remove shadow support via direct attribute.

Shadow block support should always rely on the style attribute instead.

Props madhudollu.
Fixes #60377.

git-svn-id: https://develop.svn.wordpress.org/trunk@57510 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Add deprecated functions from interactivity core blocks.

In 6.5 we are removing a couple of functions in Core blocks that were enqueuing the files needed to add that interactivity. Interactivity is handled with modules, so those functions are not needed anymore and are deprecated.

Props swissspidy, cbravobernal.
Fixes #60380.

git-svn-id: https://develop.svn.wordpress.org/trunk@57511 602fd350-edb4-49c9-b593-d223f7449a82

* Twenty Fifteen: Fix typo in `css/blocks.css`.

Follow-up to [43798].

Props shailu25, harshgajipara.
Fixes #60383.

git-svn-id: https://develop.svn.wordpress.org/trunk@57512 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Improve singular lookup of pluralized strings.

Ensures that string lookup in MO files only uses the singular string.

This matches expected behavior with gettext files and improves compatibility for cases where for example both `__( 'Product' )` and `_n( 'Product', 'Products’, num )` are used in a project, where both will use the same translation for the singular version. Maintains backward compatibility and feature parity with the pomo library and the PHP translation file format.

Replaces [57386], which was reverted in [57505], with a more accurate and performant solution.

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57513 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Add the Block Bindings API.

This introduces the Block Bindings API for WordPress.

The API allows developers to connects block attributes to different sources. In this PR, two such sources are included: "post meta" and "pattern". Attributes connected to sources can have their HTML replaced by values coming from the source in a way defined by the binding.

Props czapla, lgladdy, gziolo, sc0ttkclark, swissspidy, artemiosans, kevin940726, fabiankaegy, santosguillamot, talldanwp, wildworks.
Fixes #60282.

git-svn-id: https://develop.svn.wordpress.org/trunk@57514 602fd350-edb4-49c9-b593-d223f7449a82

* Media: Prevent local edits during media upload.

Prevent `options.allowLocalEdits` from toggling to true during the upload cycle. Otherwise, media meta fields can be edited, but the data will be lost as soon as the upload process is completed.

Props codepo8, oglekler, nicolefurlan, antpb, syamraj24, joedolson.
Fixes #58783, #23374.

git-svn-id: https://develop.svn.wordpress.org/trunk@57515 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Support loading `.l10n.php` translation files on their own.

Adjusts the translation file lookup in `WP_Textdomain_Registry` so that just-in-time translation loading
works even if there is only a `.l10n.php` translation file without a corresponding `.mo` file.

While language packs continue to contain both file types, this makes it easier to use translations in a project
without having to deal with `.mo` or `.po` files.

Props Chrystl.
See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57516 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Introduce Props Bot workflow.

Props Bot is a new GitHub Action that will compile a list of contributors for a given pull request. The bot will leave a comment with a list of contributors formatted for use in both Trac SVN and GitHub.

Props dharm1025, desrosj, jorbin, jeffpaul, dd32, pento, gziolo, swissspidy, talldanwp, noisysocks, youknowriad, peterwilsoncc, joemcgill, chrisdavidmiles, wpscholar, annezazu, chanthaboune, desrosjbot.
See #60417.

git-svn-id: https://develop.svn.wordpress.org/trunk@57517 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Fix plural forms parsing in `WP_Translation_File`.

Ensures the plural expression from the translation file header is correctly parsed.
Prevents silent failures in the attempt to create the plural form function.

Adds additional tests.

Props Chouby.
See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57518 602fd350-edb4-49c9-b593-d223f7449a82

* I18N: Add type declaration to new method missed in [57518].

See #59656.

git-svn-id: https://develop.svn.wordpress.org/trunk@57519 602fd350-edb4-49c9-b593-d223f7449a82

* Administration: Accessibility: Use the default cursor style for labels and disabled form controls.

The native cursor style for labels and form controls is `default`, which is the platform-dependent default cursor. Typically an arrow. Historically, WordPress always used the `pointer` style for all form controls and labels. While this isn't standard, there is some value in using the `pointer` style for form controls. However, labels should use the default style especially when the associated controls are disabled.
Additionally, makes sure the disabled styling works for form controls with an `aria-disabled="true"` attribute.

Props joedolson, afercia.
Fixes #59733.


git-svn-id: https://develop.svn.wordpress.org/trunk@57520 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Add `allowed_blocks` field to block registration and REST API

There is a new block.json field called allowedBlocks, added in Gutenberg in https://github.com/WordPress/gutenberg/pull/58262. This adds support for this new field also on the server. 

Props: gziolo, jsnajdr.
Fixes #60403.




git-svn-id: https://develop.svn.wordpress.org/trunk@57521 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Use strict comparison for functions lookup in plugin/theme editors.

Follow-up to [10607], [44617].

Props upadalavipul.
See #60415.

git-svn-id: https://develop.svn.wordpress.org/trunk@57522 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Some improvements to the Props Bot workflow.

This makes a few improvements made to the Props Bot workflow:

- The bot will no longer run on draft PRs.
- The bot will no longer run on closed PRs.
- The bot will no longer run when a comment is deleted (this should almost never happen).

Props mamaduka, gziolo.
See #60417.

git-svn-id: https://develop.svn.wordpress.org/trunk@57523 602fd350-edb4-49c9-b593-d223f7449a82

* Media: enable AVIF support.

Add support for uploading, editing and saving AVIF images when supported by the server.

Add 'image/avif' to supported mime types. Correctly identify AVIF images and sizes even when PHP doesn't support AVIF. Resize uploaded AVIF files (when supported) and use for front end markup.

Props adamsilverstein, lukefiretoss, ayeshrajans, navjotjsingh, Tyrannous, jb510, gregbenz, nickpagz, JavierCasares, mukesh27, yguyon, swissspidy.
Fixes #51228.



git-svn-id: https://develop.svn.wordpress.org/trunk@57524 602fd350-edb4-49c9-b593-d223f7449a82

* Media: fix AVIF tests.

Follow up to r57524. Properly add AVIF images for unit tests.

Fixes #51228.



git-svn-id: https://develop.svn.wordpress.org/trunk@57525 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Refactor the way block bindings sources are handled

It fixes the coding style issues reported. It goes further and improves the code quality it other places where the logic for block bindings was added.

Follow-up for [57514].
Props: gziolo, mukesh27, youknowriad, santosguillamot.
See #60282.



git-svn-id: https://develop.svn.wordpress.org/trunk@57526 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Reset parser state after seeking to bookmark.

When parser states were introduced, nothing in the `seek()` method reset the
parser state. This is problematic because it could leave the parser in the
wrong state.

In this patch the parser state is reset so that it's properly adjusted on
the successive call to `next_token()`.

Developed in https://github.com/WordPress/wordpress-develop/pull/6021
Discussed in https://core.trac.wordpress.org/ticket/60428

Follow-up to [57211]

Props dmsnell, kevin940726
Fixes #60428



git-svn-id: https://develop.svn.wordpress.org/trunk@57527 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Fix typo setting the wrong self-closing flag.

The HTML Processor tracks whether a token was found with the self-closing flag.
Depending on the context, this flag may or may not indicate that the element is
self closing. Unfortunately it's been tracking the wrong flag: it's been tracking
the end-tag flag, which indicates that a token is an end tag.

In this patch the right flag is set in the HTML Processor. This hasn't been an
issue because the HTML Processor doesn't yet read that stored flag, but it's an
important fix to make before adding support for foreign content (SVG and MathML)
since that behavior depends on reading the correct flag.

Follow-up to [56274].

Props dmsnell.



git-svn-id: https://develop.svn.wordpress.org/trunk@57528 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Use strict comparison in `wp-admin/update-core.php`.

Follow-up to [11273], [25784], [54654].

Props wpfy, mukesh27, azaozz, viralsampat.
Fixes #58061, #60415.

git-svn-id: https://develop.svn.wordpress.org/trunk@57529 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Rename the `$ID` parameter to `$post_id` in `trackback()`.

This resolves a few WPCS warnings:
{{{
Variable "$ID" is not in valid snake_case format, try "$i_d"
}}}

See #59650.

git-svn-id: https://develop.svn.wordpress.org/trunk@57530 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Mock plugin API response in `WP_REST_Plugins_Controller_Test`.

Avoid false test failures due to network conditions in the `WP_REST_Plugins_Controller_Test` class. This mocks HTTP responses from the plugin information endpoint for the link-manager plugin.

Props: peterwilsoncc, costdev.
See #59647.



git-svn-id: https://develop.svn.wordpress.org/trunk@57531 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Rename the `$expires_offset` variable in `cache_javascript_headers()`.

This resolves a WPCS warning:
{{{
Variable "$expiresOffset" is not in valid snake_case format, try "$expires_offset"
}}}

Follow-up to [4109], [21996].

See #59650.

git-svn-id: https://develop.svn.wordpress.org/trunk@57532 602fd350-edb4-49c9-b593-d223f7449a82

* Script Loader: Remove unused `WP_Scripts::get_unaliased_deps()` method.

This private method was introduced in [56033] / #12009 but it's not actually used.
It was part of the inline script implementation which was later reverted before final merge.
The method can be safely removed because it’s private and cannot be used by extenders.

Props joemcgill.
Fixes #60438.

git-svn-id: https://develop.svn.wordpress.org/trunk@57533 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Update the `codecov/codecov-action` action.

This updates the `codecov/codecov-action` from version `3.1.5` to `4.0.1`.

Version 4 switches to using the Codecov CLI to upload test report date, and changes the version of Node.js used for the action to 20.x. This fixes the notices currently shown for the test coverage workflow.

Props: mukesh27.
See #59658.

git-svn-id: https://develop.svn.wordpress.org/trunk@57534 602fd350-edb4-49c9-b593-d223f7449a82

* General: Add tests for `array_is_list` polyfill added in r57337.

Props costdev.
See #55105.

git-svn-id: https://develop.svn.wordpress.org/trunk@57535 602fd350-edb4-49c9-b593-d223f7449a82

* Build/Test Tools: Pass a token to the Codecov action.

Version 4 of the action now requires a token to be provided in order to upload coverage results.

Follow up to [57534].

Props swissspidy.
See #59658.

git-svn-id: https://develop.svn.wordpress.org/trunk@57536 602fd350-edb4-49c9-b593-d223f7449a82

* Upload: Fallback to `PclZip` to validate ZIP file uploads.

`ZipArchive` can fail to validate ZIP files correctly and report valid files as invalid. This introduces a fallback to `PclZip` to check validity of files if `ZipArchive` fails them.

This introduces the new function `wp_zip_file_is_valid()` to validate archives.

Follow up to [57388].

Props audunmb, azaozz, britner, cdevroe, colorful-tones, costdev, courane01, endymion00, feastdesignco, halounsbury, jeffpaul, johnbillion, jorbin, jsandtro, karinclimber, kevincoleman, koesper, maartenbelmans, mathewemoore, melcarthus, mujuonly, nerdpressteam, olegfuture, otto42, peterwilsoncc, room34, sayful, schutzsmith, stephencronin, svitlana41319, swissspidy, tnolte, tobiasbg, vikram6, welaunchio.
Fixes #60398.


git-svn-id: https://develop.svn.wordpress.org/trunk@57537 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Rename the `$oSelf` variable in `WP_MatchesMapRegex::apply()`.

This resolves a WPCS warning:
{{{
Variable "$oSelf" is not in valid snake_case format, try "$o_self"
}}}

Follow-up to [11853], [38376].

See #59650.

git-svn-id: https://develop.svn.wordpress.org/trunk@57538 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Introduce the Font Library post types and low level APIs.

This is the first step towards adding the font library to WordPress.
This commit includes the font library and font face CPTs.
It also adds the necessary APIs and classes to register and manipulate font collections.

This PR backports the font library post types and low level APIs to Core. This is the first step to include the font library entirely into Core. Once this merged, we'll open a PR with the necessary REST API controllers.

Props youknowriad, get_dave, grantmkin, swissspidy, hellofromtonya, mukesh27, mcsf.
See #59166.

git-svn-id: https://develop.svn.wordpress.org/trunk@57539 602fd350-edb4-49c9-b593-d223f7449a82

* Editor: Fix Font Library PHP unit tests.

These font assets files used in phpunit tests were missing in the original commit [57539].

Props mukesh27.
See #59166.

git-svn-id: https://develop.svn.wordpress.org/trunk@57540 602fd350-edb4-49c9-b593-d223f7449a82

* Coding Standards: Fix array key alignment after [57539].

See #59166.

git-svn-id: https://develop.svn.wordpress.org/trunk@57541 602fd350-edb4-49c9-b593-d223f7449a82

* HTML API: Join text nodes on invalid-tag-name boundaries.

A fix was introduced to the Tag Processor to ensure that contiguous text
in an HTML document emerges as a single text node spanning the full
sequence. Unfortunately, that patch was marginally over-zealous in
checking if a "<" started a syntax token or not. It used the following:

{{{
<?php
if ( 'A' <= $c && 'z' >= $c ) { ... }
}}}

This was based on the assumption that the A-Z and a-z letters are
contiguous in the ASCII range; they aren't, and there's a gap of
several characters in between. The result of this is that in some
cases the parser created a text boundary when it didn't need to.
Text boundaries can be surprising and can be created when reaching
invalid syntax, HTML comments, and more hidden elements, so
semantically this wasn't a major bug, but it was an aesthetic
challenge.

In this patch the check is properly compared for both upper- and
lower-case variants that could potentially form tag names.

{{{
<?php
if ( ( 'A' <= $c && 'Z' >= $c ) || ( 'a' <= $c && 'z' >= $c ) ) { ... }
}}}

This solves the problem and ensures that contiguous text appears
as a single text node when scanning tokens.

Developed in https://github.com/WordPress/wordpress-develop/pull/6041
Discussed in https://core.trac.wordpress.org/ticket/60…
@AndrewJMcDonald
Copy link

Are there plans to add an allowedBlocks property to block variations ? That would be so incredibly useful.

@getdave
Copy link
Contributor

getdave commented Feb 12, 2024

That would be so incredibly useful.

Could you describe a likely use case for this?

@jsnajdr
Copy link
Member Author

jsnajdr commented Feb 12, 2024

For block variations, a good approach could be supporting the allowedBlocks attribute and setting it on variations. After all, a block variation is a "block type + certain set of attributes".

@AndrewJMcDonald
Copy link

AndrewJMcDonald commented Feb 12, 2024

@getdave

Lets imagine I were building my client a columns block which is simpler than the core/columns block because it doesn't have features such as column widths, vertical alignment, column spacing etc. I'll take care of the styling for them.
My columns block (my/columns) might allow for my/column and core/image blocks, except when my/columns is a four-column variant, in which case my design might have a requirement that I allow my/column blocks only and not images.

I can currently achieve this by making separate blocks ie my/columns, and my/four-columns which have different allowedBlocks, but it would save me a lot of time of i could set the allowed blocks per variation.

Ps. this is also advantageous because of the way block styles are loaded. My stylesheet might have styles that shared between all of the column variations, and it's less confusing when I don't have to add the same css file to two block types

@draganescu
Copy link
Contributor

hi @AndrewJMcDonald - interesting use case! I would think maybe a combination of block locking and block templates would help more.

What I am saying is allowed blocks should not be used except for limiting children that the parent can't deal with. In your example, your columns block can deal with images fine, but one variation should not contain them for styling reasons and that is not a variation as much as it's a template limitation. You could for instance define a runtime in your columns block that sets a locked template for inner blocks, with a different allowedBlocks for the inner blocks if the number of columns is more than 3.

@jsnajdr
Copy link
Member Author

jsnajdr commented Feb 13, 2024

@AndrewJMcDonald Here's one way how to do this. In block.json, you define a "baseline": all my/columns blocks allow only columns and images, nothing else:

{
  name: 'my/columns',
  allowedBlocks: [ 'my/column', 'core/image' ]
}

Then, in the block's edit function, you can limit it further:

function MyColumnsEdit( { name, attributes } ) {
  const variation = useSelect( ( select ) => select( blocksStore ).getActiveBlockVariation( name, attributes ) );
  let allowedBlocks = undefined;
  if ( variation === 'four-columns' ) {
    allowedBlocks = [ 'my/column' ];
  }
  const props = useInnerBlocksProps( {}, { allowedBlocks } );
  return <div { ...props } />;
}

The key points here are:

  1. Block variation is determined by a matching set of block attributes, nothing else. Variations define an isActive function that looks at the set of attributes and returns a boolean value that says "yes this is me" or "no not me". That's what the getActiveBlockVariation call does. It determines whether we're dealing with the four-columns variation or not.
  2. If the variation is four-columns, create a custom list of allowedBlocks and pass it to useInnerBlocksProps.
  3. The hook returns props that are then passed to an element like div. One of the props is children, and these children contain an <InnerBlocks> component instance that can limit its allowedBlocks, in addition to what is in the block.json.

You can find some very similar prior art in the core/navigation-submenu block. This block can contain a nested core/navigation-submenu and a few other block types. But the nested submenu is not allowed if the nesting level is too deep. The block uses the same technique as in my example above: from the dynamic context (attributes, parent blocks) it determines whether we're dealing with a particular variation or pseudo-variation, and then dynamically determines allowedBlocks for its inner blocks.

I'm not familiar with the block locking and block templates that @draganescu recommends. Maybe they work equally well or even better!

@Mamaduka
Copy link
Member

@jsnajdr, I noticed that allowedBlocks from the block type definition isn't synchronized with block list settings (getBlockListSettings( rootClientId)). Was this omitted intentionally, or was it just an oversight?

P.S. Happy to create a follow-up PR in case of the latter.

@jsnajdr
Copy link
Member Author

jsnajdr commented Feb 26, 2024

Was this omitted intentionally, or was it just an oversight?

I'd say it was somewhat intentional 🙂 The allowedBlocks definition is used only by the canInsertBlockType selector. And the block list settings serve only as a "delivery mechanism" how to pass that value to the canInsertBlockType function.

When the allowedBlocks value is dynamically calculated by the block's edit function, then the block list settings are a good location where to put the value into the block-editor Redux state. But the block type definition value can be read directly, it's already in the blocks store.

I'm wondering what would be the use case for having block type allowedBlocks in the block list settings?

@jsnajdr
Copy link
Member Author

jsnajdr commented Mar 1, 2024

Dev note

Support for new allowedBlocks field in block.json

WordPress 6.5 adds support for new field allowedBlocks in the block.json file. It lets block developers specify which block types can be inserted as children of the given block. It's a companion to the existing parent and ancestor fields that have a similar function, namely specifying allowed parent block types. Example of usage in a block.json file:

{
  "name": "core/list",
  "title": "List",
  "allowedBlocks": [ "core/list-item" ]
}

One of the main advantages of the block.json field is that it can be modified by plugins. For example, you can create a block that acts as a custom list item, and extend the Core List block so that your custom block can be inserted as its child:

addFilter( 'blocks.registerBlockType', 'my-list-item', ( settings, name ) => {
  if ( name === 'core/list' ) {
    const { allowedBlocks = [] } = settings;
    return { ...settings, allowedBlocks: [ ...allowedBlocks, 'my/list-item' ] };
  }
  return settings;
} );

This new API replaces the allowedBlocks option that can be passed to the useInnerBlocksProps hook inside the block's edit function. This option was previously used to implement the same check, but it wasn't extensible: the list of allowed blocks was hardcoded in the block's edit function and couldn't be modified.

The allowedBlocks option on the useInnerBlocksProps hook is still supported and is not deprecated, but you should use it only for specialized use cases. Like when the list of allowed blocks is dynamically calculated for each block: from its attributes, or from its surrounding environment (the parent block etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Feature] Block API API that allows to express the block paradigm. Needs Dev Note Requires a developer note for a major WordPress release cycle [Package] Blocks /packages/blocks [Type] New API New API to be used by plugin developers or package users.
Projects
None yet
Development

Successfully merging this pull request may close these issues.