mirror of
git://develop.git.wordpress.org/
synced 2025-01-16 20:38:35 +01:00
Editor: update Wordpress npm packages.
Updates the wordpress npm packages and their dependencies to the latest versions, as well as auto-updates to relevant core PHP files. Props youknowriad, joemcgill, spacedmonkey, ramonopoly, peterwilsoncc, bernhard-reiter, tyxla, dmsnell. Fixes #58623. git-svn-id: https://develop.svn.wordpress.org/trunk@56065 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
30d6172eed
commit
a710b97e7c
16
Gruntfile.js
16
Gruntfile.js
@ -1147,7 +1147,7 @@ module.exports = function(grunt) {
|
||||
options: {
|
||||
patterns: [
|
||||
{
|
||||
match: new RegExp( '//# sourceMappingURL=.*\\s*' ),
|
||||
match: new RegExp( '\/\/# sourceMappingURL=.*\\s*', 'g' ),
|
||||
replacement: ''
|
||||
}
|
||||
]
|
||||
@ -1160,6 +1160,14 @@ module.exports = function(grunt) {
|
||||
BUILD_DIR + 'wp-includes/js/underscore.js'
|
||||
],
|
||||
dest: BUILD_DIR + 'wp-includes/js/'
|
||||
},
|
||||
{
|
||||
expand: true,
|
||||
flatten: true,
|
||||
src: [
|
||||
BUILD_DIR + 'wp-includes/js/dist/block-editor.js',
|
||||
],
|
||||
dest: BUILD_DIR + 'wp-includes/js/dist/'
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1459,7 +1467,11 @@ module.exports = function(grunt) {
|
||||
} );
|
||||
grunt.file.write(
|
||||
SOURCE_DIR + 'wp-includes/blocks/blocks-json.php',
|
||||
'<?php return ' + json2php( blocks ) + ';'
|
||||
'<?php return ' + json2php.make( {
|
||||
linebreak: '\n',
|
||||
indent: ' ',
|
||||
shortArraySyntax: false
|
||||
} )( blocks ) + ';'
|
||||
);
|
||||
} );
|
||||
|
||||
|
9874
package-lock.json
generated
9874
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
130
package.json
130
package.json
@ -26,10 +26,10 @@
|
||||
"devDependencies": {
|
||||
"@lodder/grunt-postcss": "^3.1.1",
|
||||
"@pmmmwh/react-refresh-webpack-plugin": "0.5.5",
|
||||
"@wordpress/babel-preset-default": "7.10.2",
|
||||
"@wordpress/dependency-extraction-webpack-plugin": "4.9.1",
|
||||
"@wordpress/e2e-test-utils": "9.3.3",
|
||||
"@wordpress/scripts": "25.3.4",
|
||||
"@wordpress/babel-preset-default": "7.19.1",
|
||||
"@wordpress/dependency-extraction-webpack-plugin": "4.18.1",
|
||||
"@wordpress/e2e-test-utils": "10.6.1",
|
||||
"@wordpress/scripts": "26.6.2",
|
||||
"autoprefixer": "^10.4.13",
|
||||
"chalk": "5.2.0",
|
||||
"check-node-version": "4.2.1",
|
||||
@ -71,76 +71,83 @@
|
||||
"source-map-loader": "4.0.1",
|
||||
"terser-webpack-plugin": "5.3.6",
|
||||
"uglify-js": "^3.17.4",
|
||||
"uuid": "9.0.0",
|
||||
"uuid": "8.3.2",
|
||||
"wait-on": "7.0.1",
|
||||
"webpack": "5.75.0",
|
||||
"webpack-livereload-plugin": "3.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wordpress/a11y": "3.26.1",
|
||||
"@wordpress/annotations": "2.26.4",
|
||||
"@wordpress/api-fetch": "6.23.1",
|
||||
"@wordpress/autop": "3.26.1",
|
||||
"@wordpress/blob": "3.26.1",
|
||||
"@wordpress/block-directory": "4.3.13",
|
||||
"@wordpress/block-editor": "11.3.10",
|
||||
"@wordpress/block-library": "8.3.13",
|
||||
"@emotion/is-prop-valid": "0.8.8",
|
||||
"@emotion/memoize": "0.7.4",
|
||||
"@wordpress/a11y": "3.35.1",
|
||||
"@wordpress/annotations": "2.35.1",
|
||||
"@wordpress/api-fetch": "6.32.1",
|
||||
"@wordpress/autop": "3.35.1",
|
||||
"@wordpress/blob": "3.35.1",
|
||||
"@wordpress/block-directory": "4.12.2",
|
||||
"@wordpress/block-editor": "12.3.2",
|
||||
"@wordpress/block-library": "8.12.2",
|
||||
"@wordpress/block-serialization-default-parser": "4.35.1",
|
||||
"@wordpress/blocks": "12.3.3",
|
||||
"@wordpress/components": "23.3.7",
|
||||
"@wordpress/compose": "6.3.3",
|
||||
"@wordpress/core-data": "6.3.3",
|
||||
"@wordpress/customize-widgets": "4.3.13",
|
||||
"@wordpress/data": "8.3.3",
|
||||
"@wordpress/data-controls": "2.26.3",
|
||||
"@wordpress/date": "4.26.2",
|
||||
"@wordpress/deprecated": "3.26.1",
|
||||
"@wordpress/dom": "3.26.1",
|
||||
"@wordpress/dom-ready": "3.26.1",
|
||||
"@wordpress/edit-post": "7.3.13",
|
||||
"@wordpress/edit-site": "5.3.13",
|
||||
"@wordpress/edit-widgets": "5.3.13",
|
||||
"@wordpress/editor": "13.3.10",
|
||||
"@wordpress/element": "5.3.2",
|
||||
"@wordpress/escape-html": "2.26.1",
|
||||
"@wordpress/format-library": "4.3.10",
|
||||
"@wordpress/hooks": "3.26.1",
|
||||
"@wordpress/html-entities": "3.26.1",
|
||||
"@wordpress/i18n": "4.26.1",
|
||||
"@wordpress/icons": "9.17.2",
|
||||
"@wordpress/interface": "5.3.8",
|
||||
"@wordpress/is-shallow-equal": "4.26.1",
|
||||
"@wordpress/keyboard-shortcuts": "4.3.3",
|
||||
"@wordpress/keycodes": "3.26.2",
|
||||
"@wordpress/list-reusable-blocks": "4.3.7",
|
||||
"@wordpress/media-utils": "4.17.2",
|
||||
"@wordpress/notices": "3.26.3",
|
||||
"@wordpress/blocks": "12.12.1",
|
||||
"@wordpress/commands": "0.6.2",
|
||||
"@wordpress/components": "25.1.2",
|
||||
"@wordpress/compose": "6.12.1",
|
||||
"@wordpress/core-commands": "0.4.2",
|
||||
"@wordpress/core-data": "6.12.2",
|
||||
"@wordpress/customize-widgets": "4.12.2",
|
||||
"@wordpress/data": "9.5.1",
|
||||
"@wordpress/data-controls": "3.4.1",
|
||||
"@wordpress/date": "4.35.1",
|
||||
"@wordpress/deprecated": "3.35.1",
|
||||
"@wordpress/dom": "3.35.1",
|
||||
"@wordpress/dom-ready": "3.35.1",
|
||||
"@wordpress/edit-post": "7.12.2",
|
||||
"@wordpress/edit-site": "5.12.2",
|
||||
"@wordpress/edit-widgets": "5.12.2",
|
||||
"@wordpress/editor": "13.12.2",
|
||||
"@wordpress/element": "5.12.1",
|
||||
"@wordpress/escape-html": "2.35.1",
|
||||
"@wordpress/format-library": "4.12.2",
|
||||
"@wordpress/hooks": "3.35.1",
|
||||
"@wordpress/html-entities": "3.35.1",
|
||||
"@wordpress/i18n": "4.35.1",
|
||||
"@wordpress/icons": "9.26.2",
|
||||
"@wordpress/interface": "5.12.2",
|
||||
"@wordpress/is-shallow-equal": "4.35.1",
|
||||
"@wordpress/keyboard-shortcuts": "4.12.1",
|
||||
"@wordpress/keycodes": "3.35.1",
|
||||
"@wordpress/list-reusable-blocks": "4.12.2",
|
||||
"@wordpress/media-utils": "4.26.1",
|
||||
"@wordpress/notices": "4.3.1",
|
||||
"@wordpress/nux": "6.0.0",
|
||||
"@wordpress/plugins": "5.3.3",
|
||||
"@wordpress/preferences": "3.3.7",
|
||||
"@wordpress/preferences-persistence": "1.18.1",
|
||||
"@wordpress/primitives": "3.24.2",
|
||||
"@wordpress/priority-queue": "2.26.1",
|
||||
"@wordpress/private-apis": "0.8.1",
|
||||
"@wordpress/redux-routine": "4.26.1",
|
||||
"@wordpress/reusable-blocks": "4.3.10",
|
||||
"@wordpress/rich-text": "6.3.4",
|
||||
"@wordpress/server-side-render": "4.3.7",
|
||||
"@wordpress/shortcode": "3.26.1",
|
||||
"@wordpress/style-engine": "1.9.1",
|
||||
"@wordpress/token-list": "2.26.1",
|
||||
"@wordpress/url": "3.27.1",
|
||||
"@wordpress/viewport": "5.3.3",
|
||||
"@wordpress/warning": "2.26.1",
|
||||
"@wordpress/widgets": "3.3.10",
|
||||
"@wordpress/wordcount": "3.26.1",
|
||||
"@wordpress/plugins": "6.3.2",
|
||||
"@wordpress/preferences": "3.12.2",
|
||||
"@wordpress/preferences-persistence": "1.27.1",
|
||||
"@wordpress/primitives": "3.33.1",
|
||||
"@wordpress/priority-queue": "2.35.1",
|
||||
"@wordpress/private-apis": "0.17.1",
|
||||
"@wordpress/redux-routine": "4.35.1",
|
||||
"@wordpress/reusable-blocks": "4.12.2",
|
||||
"@wordpress/rich-text": "6.12.1",
|
||||
"@wordpress/router": "0.4.1",
|
||||
"@wordpress/server-side-render": "4.12.2",
|
||||
"@wordpress/shortcode": "3.35.1",
|
||||
"@wordpress/style-engine": "1.18.1",
|
||||
"@wordpress/token-list": "2.35.1",
|
||||
"@wordpress/url": "3.36.1",
|
||||
"@wordpress/viewport": "5.12.1",
|
||||
"@wordpress/warning": "2.35.1",
|
||||
"@wordpress/widgets": "3.12.2",
|
||||
"@wordpress/wordcount": "3.35.1",
|
||||
"backbone": "1.4.1",
|
||||
"clipboard": "2.0.11",
|
||||
"core-js-url-browser": "3.6.4",
|
||||
"element-closest": "^3.0.2",
|
||||
"formdata-polyfill": "4.0.10",
|
||||
"framer-motion": "10.11.6",
|
||||
"hoverintent": "2.2.1",
|
||||
"imagesloaded": "4.1.4",
|
||||
"is-plain-object": "5.0.0",
|
||||
"jquery": "3.7.0",
|
||||
"jquery-color": "2.2.0",
|
||||
"jquery-form": "4.3.0",
|
||||
@ -148,12 +155,15 @@
|
||||
"json2php": "^0.0.7",
|
||||
"lodash": "4.17.21",
|
||||
"masonry-layout": "4.2.2",
|
||||
"memize": "2.1.0",
|
||||
"moment": "2.29.4",
|
||||
"objectFitPolyfill": "2.3.5",
|
||||
"path-to-regexp": "6.2.1",
|
||||
"polyfill-library": "4.7.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"regenerator-runtime": "0.13.11",
|
||||
"tslib": "2.6.0",
|
||||
"underscore": "1.13.6",
|
||||
"whatwg-fetch": "3.6.2",
|
||||
"wicg-inert": "3.1.2"
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/archives",
|
||||
"title": "Archives",
|
||||
"category": "widgets",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/audio",
|
||||
"title": "Audio",
|
||||
"category": "media",
|
||||
|
@ -16,67 +16,19 @@
|
||||
function render_block_core_avatar( $attributes, $content, $block ) {
|
||||
$size = isset( $attributes['size'] ) ? $attributes['size'] : 96;
|
||||
$wrapper_attributes = get_block_wrapper_attributes();
|
||||
$border_attributes = get_block_core_avatar_border_attributes( $attributes );
|
||||
|
||||
$image_styles = array();
|
||||
// Class gets passed through `esc_attr` via `get_avatar`.
|
||||
$image_classes = ! empty( $border_attributes['class'] )
|
||||
? "wp-block-avatar__image {$border_attributes['class']}"
|
||||
: 'wp-block-avatar__image';
|
||||
|
||||
// Add border width styles.
|
||||
$has_border_width = ! empty( $attributes['style']['border']['width'] );
|
||||
|
||||
if ( $has_border_width ) {
|
||||
$border_width = $attributes['style']['border']['width'];
|
||||
$image_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
|
||||
}
|
||||
|
||||
// Add border radius styles.
|
||||
$has_border_radius = ! empty( $attributes['style']['border']['radius'] );
|
||||
|
||||
if ( $has_border_radius ) {
|
||||
$border_radius = $attributes['style']['border']['radius'];
|
||||
|
||||
if ( is_array( $border_radius ) ) {
|
||||
// Apply styles for individual corner border radii.
|
||||
foreach ( $border_radius as $key => $value ) {
|
||||
if ( null !== $value ) {
|
||||
$name = _wp_to_kebab_case( $key );
|
||||
// Add shared styles for individual border radii.
|
||||
$border_style = sprintf(
|
||||
'border-%s-radius: %s;',
|
||||
esc_attr( $name ),
|
||||
esc_attr( $value )
|
||||
);
|
||||
$image_styles[] = $border_style;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$border_style = sprintf( 'border-radius: %s;', esc_attr( $border_radius ) );
|
||||
$image_styles[] = $border_style;
|
||||
}
|
||||
}
|
||||
|
||||
// Add border color styles.
|
||||
$has_border_color = ! empty( $attributes['style']['border']['color'] );
|
||||
|
||||
if ( $has_border_color ) {
|
||||
$border_color = $attributes['style']['border']['color'];
|
||||
$image_styles[] = sprintf( 'border-color: %s;', esc_attr( $border_color ) );
|
||||
}
|
||||
|
||||
// Add border style (solid, dashed, dotted ).
|
||||
$has_border_style = ! empty( $attributes['style']['border']['style'] );
|
||||
|
||||
if ( $has_border_style ) {
|
||||
$border_style = $attributes['style']['border']['style'];
|
||||
$image_styles[] = sprintf( 'border-style: %s;', esc_attr( $border_style ) );
|
||||
}
|
||||
|
||||
// Add border classes to the avatar image for both custom colors and palette colors.
|
||||
$image_classes = '';
|
||||
if ( $has_border_color || isset( $attributes['borderColor'] ) ) {
|
||||
$image_classes .= 'has-border-color';
|
||||
}
|
||||
if ( isset( $attributes['borderColor'] ) ) {
|
||||
$image_classes .= ' has-' . $attributes['borderColor'] . '-border-color';
|
||||
}
|
||||
// Unlike class, `get_avatar` doesn't filter the styles via `esc_attr`.
|
||||
// The style engine does pass the border styles through
|
||||
// `safecss_filter_attr` however.
|
||||
$image_styles = ! empty( $border_attributes['style'] )
|
||||
? sprintf( ' style="%s"', esc_attr( $border_attributes['style'] ) )
|
||||
: '';
|
||||
|
||||
if ( ! isset( $block->context['commentId'] ) ) {
|
||||
$author_id = isset( $attributes['userId'] ) ? $attributes['userId'] : get_post_field( 'post_author', $block->context['postId'] );
|
||||
@ -89,8 +41,8 @@ function render_block_core_avatar( $attributes, $content, $block ) {
|
||||
'',
|
||||
$alt,
|
||||
array(
|
||||
'extra_attr' => isset( $image_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $image_styles ) ) ) : '',
|
||||
'class' => "wp-block-avatar__image $image_classes ",
|
||||
'extra_attr' => $image_styles,
|
||||
'class' => $image_classes,
|
||||
)
|
||||
);
|
||||
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
|
||||
@ -116,8 +68,8 @@ function render_block_core_avatar( $attributes, $content, $block ) {
|
||||
'',
|
||||
$alt,
|
||||
array(
|
||||
'extra_attr' => isset( $image_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $image_styles ) ) ) : '',
|
||||
'class' => "wp-block-avatar__image $image_classes",
|
||||
'extra_attr' => $image_styles,
|
||||
'class' => $image_classes,
|
||||
)
|
||||
);
|
||||
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] && isset( $comment->comment_author_url ) && '' !== $comment->comment_author_url ) {
|
||||
@ -132,6 +84,58 @@ function render_block_core_avatar( $attributes, $content, $block ) {
|
||||
return sprintf( '<div %1s>%2s</div>', $wrapper_attributes, $avatar_block );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates class names and styles to apply the border support styles for
|
||||
* the Avatar block.
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @return array The border-related classnames and styles for the block.
|
||||
*/
|
||||
function get_block_core_avatar_border_attributes( $attributes ) {
|
||||
$border_styles = array();
|
||||
$sides = array( 'top', 'right', 'bottom', 'left' );
|
||||
|
||||
// Border radius.
|
||||
if ( isset( $attributes['style']['border']['radius'] ) ) {
|
||||
$border_styles['radius'] = $attributes['style']['border']['radius'];
|
||||
}
|
||||
|
||||
// Border style.
|
||||
if ( isset( $attributes['style']['border']['style'] ) ) {
|
||||
$border_styles['style'] = $attributes['style']['border']['style'];
|
||||
}
|
||||
|
||||
// Border width.
|
||||
if ( isset( $attributes['style']['border']['width'] ) ) {
|
||||
$border_styles['width'] = $attributes['style']['border']['width'];
|
||||
}
|
||||
|
||||
// Border color.
|
||||
$preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null;
|
||||
$custom_color = _wp_array_get( $attributes, array( 'style', 'border', 'color' ), null );
|
||||
$border_styles['color'] = $preset_color ? $preset_color : $custom_color;
|
||||
|
||||
// Individual border styles e.g. top, left etc.
|
||||
foreach ( $sides as $side ) {
|
||||
$border = _wp_array_get( $attributes, array( 'style', 'border', $side ), null );
|
||||
$border_styles[ $side ] = array(
|
||||
'color' => isset( $border['color'] ) ? $border['color'] : null,
|
||||
'style' => isset( $border['style'] ) ? $border['style'] : null,
|
||||
'width' => isset( $border['width'] ) ? $border['width'] : null,
|
||||
);
|
||||
}
|
||||
|
||||
$styles = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
|
||||
$attributes = array();
|
||||
if ( ! empty( $styles['classnames'] ) ) {
|
||||
$attributes['class'] = $styles['classnames'];
|
||||
}
|
||||
if ( ! empty( $styles['css'] ) ) {
|
||||
$attributes['style'] = $styles['css'];
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the `core/avatar` block on the server.
|
||||
*/
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/avatar",
|
||||
"title": "Avatar",
|
||||
"category": "theme",
|
||||
@ -48,6 +48,6 @@
|
||||
"__experimentalDuotone": "img"
|
||||
}
|
||||
},
|
||||
"editorStyle": "wp-block-avatar",
|
||||
"editorStyle": "wp-block-avatar-editor",
|
||||
"style": "wp-block-avatar"
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/block",
|
||||
"title": "Reusable block",
|
||||
"title": "Pattern",
|
||||
"category": "reusable",
|
||||
"description": "Create and save content to reuse across your site. Update the block, and the changes apply everywhere it’s used.",
|
||||
"textdomain": "default",
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/button",
|
||||
"title": "Button",
|
||||
"category": "design",
|
||||
@ -16,30 +16,35 @@
|
||||
"type": "string",
|
||||
"source": "attribute",
|
||||
"selector": "a",
|
||||
"attribute": "href"
|
||||
"attribute": "href",
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"source": "attribute",
|
||||
"selector": "a",
|
||||
"attribute": "title"
|
||||
"attribute": "title",
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"text": {
|
||||
"type": "string",
|
||||
"source": "html",
|
||||
"selector": "a"
|
||||
"selector": "a",
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"linkTarget": {
|
||||
"type": "string",
|
||||
"source": "attribute",
|
||||
"selector": "a",
|
||||
"attribute": "target"
|
||||
"attribute": "target",
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"rel": {
|
||||
"type": "string",
|
||||
"source": "attribute",
|
||||
"selector": "a",
|
||||
"attribute": "rel"
|
||||
"attribute": "rel",
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"placeholder": {
|
||||
"type": "string"
|
||||
@ -92,10 +97,16 @@
|
||||
}
|
||||
},
|
||||
"__experimentalBorder": {
|
||||
"color": true,
|
||||
"radius": true,
|
||||
"style": true,
|
||||
"width": true,
|
||||
"__experimentalSkipSerialization": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"radius": true
|
||||
"color": true,
|
||||
"radius": true,
|
||||
"style": true,
|
||||
"width": true
|
||||
}
|
||||
},
|
||||
"__experimentalSelector": ".wp-block-button .wp-block-button__link"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/buttons",
|
||||
"title": "Buttons",
|
||||
"category": "design",
|
||||
@ -10,6 +10,7 @@
|
||||
"supports": {
|
||||
"anchor": true,
|
||||
"align": [ "wide", "full" ],
|
||||
"html": false,
|
||||
"__experimentalExposeControlsToChildren": true,
|
||||
"spacing": {
|
||||
"blockGap": true,
|
||||
@ -31,7 +32,7 @@
|
||||
"fontSize": true
|
||||
}
|
||||
},
|
||||
"__experimentalLayout": {
|
||||
"layout": {
|
||||
"allowSwitching": false,
|
||||
"allowInheriting": false,
|
||||
"default": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/calendar",
|
||||
"title": "Calendar",
|
||||
"category": "widgets",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/categories",
|
||||
"title": "Categories List",
|
||||
"category": "widgets",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/code",
|
||||
"title": "Code",
|
||||
"category": "text",
|
||||
@ -14,6 +14,7 @@
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
"align": [ "wide" ],
|
||||
"anchor": true,
|
||||
"typography": {
|
||||
"fontSize": true,
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/column",
|
||||
"title": "Column",
|
||||
"category": "text",
|
||||
"category": "design",
|
||||
"parent": [ "core/columns" ],
|
||||
"description": "A single column within a columns block.",
|
||||
"textdomain": "default",
|
||||
@ -38,7 +38,8 @@
|
||||
"blockGap": true,
|
||||
"padding": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"padding": true
|
||||
"padding": true,
|
||||
"blockGap": true
|
||||
}
|
||||
},
|
||||
"__experimentalBorder": {
|
||||
@ -64,6 +65,6 @@
|
||||
"fontSize": true
|
||||
}
|
||||
},
|
||||
"__experimentalLayout": true
|
||||
"layout": true
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/columns",
|
||||
"title": "Columns",
|
||||
"category": "design",
|
||||
@ -13,6 +13,10 @@
|
||||
"isStackedOnMobile": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"templateLock": {
|
||||
"type": [ "string", "boolean" ],
|
||||
"enum": [ "all", "insert", "contentOnly", false ]
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
@ -35,10 +39,11 @@
|
||||
"margin": [ "top", "bottom" ],
|
||||
"padding": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"padding": true
|
||||
"padding": true,
|
||||
"blockGap": true
|
||||
}
|
||||
},
|
||||
"__experimentalLayout": {
|
||||
"layout": {
|
||||
"allowSwitching": false,
|
||||
"allowInheriting": false,
|
||||
"allowEditing": false,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comment-author-name",
|
||||
"title": "Comment Author Name",
|
||||
"category": "theme",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comment-content",
|
||||
"title": "Comment Content",
|
||||
"category": "theme",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comment-date",
|
||||
"title": "Comment Date",
|
||||
"category": "theme",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comment-edit-link",
|
||||
"title": "Comment Edit Link",
|
||||
"category": "theme",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comment-reply-link",
|
||||
"title": "Comment Reply Link",
|
||||
"category": "theme",
|
||||
|
@ -25,13 +25,26 @@ function block_core_comment_template_render_comments( $comments, $block ) {
|
||||
|
||||
$content = '';
|
||||
foreach ( $comments as $comment ) {
|
||||
$comment_id = $comment->comment_ID;
|
||||
$filter_block_context = static function( $context ) use ( $comment_id ) {
|
||||
$context['commentId'] = $comment_id;
|
||||
return $context;
|
||||
};
|
||||
|
||||
$block_content = ( new WP_Block(
|
||||
$block->parsed_block,
|
||||
array(
|
||||
'commentId' => $comment->comment_ID,
|
||||
)
|
||||
) )->render( array( 'dynamic' => false ) );
|
||||
/*
|
||||
* We set commentId context through the `render_block_context` filter so
|
||||
* that dynamically inserted blocks (at `render_block` filter stage)
|
||||
* will also receive that context.
|
||||
*/
|
||||
add_filter( 'render_block_context', $filter_block_context );
|
||||
|
||||
/*
|
||||
* We construct a new WP_Block instance from the parsed block so that
|
||||
* it'll receive any changes made by the `render_block_data` filter.
|
||||
*/
|
||||
$block_content = ( new WP_Block( $block->parsed_block ) )->render( array( 'dynamic' => false ) );
|
||||
|
||||
remove_filter( 'render_block_context', $filter_block_context );
|
||||
|
||||
$children = $comment->get_children();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comment-template",
|
||||
"title": "Comment Template",
|
||||
"category": "design",
|
||||
|
@ -26,7 +26,7 @@ function render_block_core_comments_pagination_next( $attributes, $content, $blo
|
||||
$label = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label;
|
||||
$pagination_arrow = get_comments_pagination_arrow( $block, 'next' );
|
||||
|
||||
$filter_link_attributes = function() {
|
||||
$filter_link_attributes = static function() {
|
||||
return get_block_wrapper_attributes();
|
||||
};
|
||||
add_filter( 'next_comments_link_attributes', $filter_link_attributes );
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comments-pagination-next",
|
||||
"title": "Comments Next Page",
|
||||
"category": "theme",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comments-pagination-numbers",
|
||||
"title": "Comments Page Numbers",
|
||||
"category": "theme",
|
||||
|
@ -22,7 +22,7 @@ function render_block_core_comments_pagination_previous( $attributes, $content,
|
||||
$label = $pagination_arrow . $label;
|
||||
}
|
||||
|
||||
$filter_link_attributes = function() {
|
||||
$filter_link_attributes = static function() {
|
||||
return get_block_wrapper_attributes();
|
||||
};
|
||||
add_filter( 'previous_comments_link_attributes', $filter_link_attributes );
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comments-pagination-previous",
|
||||
"title": "Comments Previous Page",
|
||||
"category": "theme",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comments-pagination",
|
||||
"title": "Comments Pagination",
|
||||
"category": "theme",
|
||||
@ -29,7 +29,7 @@
|
||||
"link": true
|
||||
}
|
||||
},
|
||||
"__experimentalLayout": {
|
||||
"layout": {
|
||||
"allowSwitching": false,
|
||||
"allowInheriting": false,
|
||||
"default": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comments-title",
|
||||
"title": "Comments Title",
|
||||
"category": "theme",
|
||||
|
@ -29,13 +29,8 @@ function render_block_core_comments( $attributes, $content, $block ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$comment_args = array(
|
||||
'post_id' => $post_id,
|
||||
'count' => true,
|
||||
'status' => 'approve',
|
||||
);
|
||||
// Return early if there are no comments and comments are closed.
|
||||
if ( ! comments_open( $post_id ) && get_comments( $comment_args ) === 0 ) {
|
||||
if ( ! comments_open( $post_id ) && (int) get_comments_number( $post_id ) === 0 ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@ -212,6 +207,7 @@ function register_legacy_post_comments_block() {
|
||||
* like `_wp_multiple_block_styles`, which is required in this case because
|
||||
* the block has multiple styles.
|
||||
*/
|
||||
/** This filter is documented in wp-includes/blocks.php */
|
||||
$metadata = apply_filters( 'block_type_metadata', $metadata );
|
||||
|
||||
register_block_type( 'core/post-comments', $metadata );
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/comments",
|
||||
"title": "Comments",
|
||||
"category": "theme",
|
||||
@ -18,6 +18,7 @@
|
||||
},
|
||||
"supports": {
|
||||
"align": [ "wide", "full" ],
|
||||
"html": false,
|
||||
"color": {
|
||||
"gradients": true,
|
||||
"link": true,
|
||||
@ -27,7 +28,6 @@
|
||||
"link": true
|
||||
}
|
||||
},
|
||||
"html": false,
|
||||
"spacing": {
|
||||
"margin": true,
|
||||
"padding": true
|
||||
|
@ -34,7 +34,7 @@ function render_block_core_cover( $attributes, $content ) {
|
||||
|
||||
/*
|
||||
* Inserts the featured image between the (1st) cover 'background' `span` and 'inner_container' `div`,
|
||||
* and removes eventual withespace characters between the two (typically introduced at template level)
|
||||
* and removes eventual whitespace characters between the two (typically introduced at template level)
|
||||
*/
|
||||
$inner_container_start = '/<div\b[^>]+wp-block-cover__inner-container[\s|"][^>]*>/U';
|
||||
if ( 1 === preg_match( $inner_container_start, $content, $matches, PREG_OFFSET_CAPTURE ) ) {
|
||||
@ -46,22 +46,19 @@ function render_block_core_cover( $attributes, $content ) {
|
||||
update_post_thumbnail_cache();
|
||||
}
|
||||
$current_featured_image = get_the_post_thumbnail_url();
|
||||
|
||||
$styles = 'background-image:url(' . esc_url( $current_featured_image ) . '); ';
|
||||
|
||||
if ( isset( $attributes['minHeight'] ) ) {
|
||||
$height_unit = empty( $attributes['minHeightUnit'] ) ? 'px' : $attributes['minHeightUnit'];
|
||||
$height = " min-height:{$attributes['minHeight']}{$height_unit}";
|
||||
|
||||
$styles .= $height;
|
||||
if ( ! $current_featured_image ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$content = preg_replace(
|
||||
'/class=\".*?\"/',
|
||||
'${0} style="' . $styles . '"',
|
||||
$content,
|
||||
1
|
||||
);
|
||||
$processor = new WP_HTML_Tag_Processor( $content );
|
||||
$processor->next_tag();
|
||||
|
||||
$styles = $processor->get_attribute( 'style' );
|
||||
$merged_styles = ! empty( $styles ) ? $styles . ';' : '';
|
||||
$merged_styles .= 'background-image:url(' . esc_url( $current_featured_image ) . ');';
|
||||
|
||||
$processor->set_attribute( 'style', $merged_styles );
|
||||
$content = $processor->get_updated_html();
|
||||
}
|
||||
|
||||
return $content;
|
||||
|
@ -1,10 +1,10 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/cover",
|
||||
"title": "Cover",
|
||||
"category": "media",
|
||||
"description": "Add an image or video with a text overlay — great for headers.",
|
||||
"description": "Add an image or video with a text overlay.",
|
||||
"textdomain": "default",
|
||||
"attributes": {
|
||||
"url": {
|
||||
@ -88,14 +88,29 @@
|
||||
"spacing": {
|
||||
"padding": true,
|
||||
"margin": [ "top", "bottom" ],
|
||||
"blockGap": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"padding": true
|
||||
"padding": true,
|
||||
"blockGap": true
|
||||
}
|
||||
},
|
||||
"__experimentalBorder": {
|
||||
"color": true,
|
||||
"radius": true,
|
||||
"style": true,
|
||||
"width": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"color": true,
|
||||
"radius": true,
|
||||
"style": true,
|
||||
"width": true
|
||||
}
|
||||
},
|
||||
"color": {
|
||||
"__experimentalDuotone": "> .wp-block-cover__image-background, > .wp-block-cover__video-background",
|
||||
"text": false,
|
||||
"background": false
|
||||
"text": true,
|
||||
"background": false,
|
||||
"__experimentalSkipSerialization": [ "gradients" ]
|
||||
},
|
||||
"typography": {
|
||||
"fontSize": true,
|
||||
@ -109,6 +124,9 @@
|
||||
"__experimentalDefaultControls": {
|
||||
"fontSize": true
|
||||
}
|
||||
},
|
||||
"layout": {
|
||||
"allowJustification": false
|
||||
}
|
||||
},
|
||||
"editorStyle": "wp-block-cover-editor",
|
||||
|
55
src/wp-includes/blocks/details/block.json
Normal file
55
src/wp-includes/blocks/details/block.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "core/details",
|
||||
"title": "Details",
|
||||
"category": "text",
|
||||
"description": "Hide and show additional content.",
|
||||
"keywords": [ "disclosure", "summary", "hide" ],
|
||||
"textdomain": "default",
|
||||
"attributes": {
|
||||
"showContent": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"summary": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
"align": [ "wide", "full" ],
|
||||
"color": {
|
||||
"gradients": true,
|
||||
"link": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"background": true,
|
||||
"text": true
|
||||
}
|
||||
},
|
||||
"__experimentalBorder": {
|
||||
"color": true,
|
||||
"width": true,
|
||||
"style": true
|
||||
},
|
||||
"html": false,
|
||||
"spacing": {
|
||||
"margin": true,
|
||||
"padding": true
|
||||
},
|
||||
"typography": {
|
||||
"fontSize": true,
|
||||
"lineHeight": true,
|
||||
"__experimentalFontFamily": true,
|
||||
"__experimentalFontWeight": true,
|
||||
"__experimentalFontStyle": true,
|
||||
"__experimentalTextTransform": true,
|
||||
"__experimentalTextDecoration": true,
|
||||
"__experimentalLetterSpacing": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"fontSize": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"editorStyle": "wp-block-details-editor",
|
||||
"style": "wp-block-details"
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/embed",
|
||||
"title": "Embed",
|
||||
"category": "embed",
|
||||
@ -41,7 +41,10 @@
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
"align": true
|
||||
"align": true,
|
||||
"spacing": {
|
||||
"margin": true
|
||||
}
|
||||
},
|
||||
"editorStyle": "wp-block-embed-editor",
|
||||
"style": "wp-block-embed"
|
||||
|
@ -5,18 +5,47 @@
|
||||
* @package WordPress
|
||||
*/
|
||||
|
||||
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
|
||||
/**
|
||||
* Replaces view script for the File block with version using Interactivity API.
|
||||
*
|
||||
* @param array $metadata Block metadata as read in via block.json.
|
||||
*
|
||||
* @return array Filtered block type metadata.
|
||||
*/
|
||||
function gutenberg_block_core_file_update_interactive_view_script( $metadata ) {
|
||||
if ( 'core/file' === $metadata['name'] ) {
|
||||
$metadata['viewScript'] = array( 'file:./interactivity.min.js' );
|
||||
}
|
||||
return $metadata;
|
||||
}
|
||||
add_filter( 'block_type_metadata', 'gutenberg_block_core_file_update_interactive_view_script', 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* When the `core/file` block is rendering, check if we need to enqueue the `'wp-block-file-view` script.
|
||||
*
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $content The block content.
|
||||
* @param array $attributes The block attributes.
|
||||
* @param string $content The block content.
|
||||
* @param WP_Block $block The parsed block.
|
||||
*
|
||||
* @return string Returns the block content.
|
||||
*/
|
||||
function render_block_core_file( $attributes, $content ) {
|
||||
$should_load_view_script = ! empty( $attributes['displayPreview'] ) && ! wp_script_is( 'wp-block-file-view' );
|
||||
if ( $should_load_view_script ) {
|
||||
wp_enqueue_script( 'wp-block-file-view' );
|
||||
function render_block_core_file( $attributes, $content, $block ) {
|
||||
$should_load_view_script = ! empty( $attributes['displayPreview'] );
|
||||
$view_js_file = 'wp-block-file-view';
|
||||
// If the script already exists, there is no point in removing it from viewScript.
|
||||
if ( ! wp_script_is( $view_js_file ) ) {
|
||||
$script_handles = $block->block_type->view_script_handles;
|
||||
|
||||
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
||||
if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
|
||||
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
|
||||
}
|
||||
// If the script is needed, but it was previously removed, add it again.
|
||||
if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
|
||||
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Update object's aria-label attribute if present in block HTML.
|
||||
@ -25,7 +54,7 @@ function render_block_core_file( $attributes, $content ) {
|
||||
$pattern = '@<object.+(?<attribute>aria-label="(?<filename>[^"]+)?")@i';
|
||||
$content = preg_replace_callback(
|
||||
$pattern,
|
||||
function ( $matches ) {
|
||||
static function ( $matches ) {
|
||||
$filename = ! empty( $matches['filename'] ) ? $matches['filename'] : '';
|
||||
$has_filename = ! empty( $filename ) && 'PDF embed' !== $filename;
|
||||
$label = $has_filename ?
|
||||
@ -41,6 +70,17 @@ function render_block_core_file( $attributes, $content ) {
|
||||
$content
|
||||
);
|
||||
|
||||
// If it uses the Interactivity API, add the directives.
|
||||
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && $should_load_view_script ) {
|
||||
$processor = new WP_HTML_Tag_Processor( $content );
|
||||
$processor->next_tag();
|
||||
$processor->set_attribute( 'data-wp-interactive', '' );
|
||||
$processor->next_tag( 'object' );
|
||||
$processor->set_attribute( 'data-wp-bind--hidden', '!selectors.core.file.hasPdfPreview' );
|
||||
$processor->set_attribute( 'hidden', true );
|
||||
return $processor->get_updated_html();
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/file",
|
||||
"title": "File",
|
||||
"category": "media",
|
||||
@ -56,7 +56,16 @@
|
||||
},
|
||||
"supports": {
|
||||
"anchor": true,
|
||||
"align": true
|
||||
"align": true,
|
||||
"color": {
|
||||
"gradients": true,
|
||||
"link": true,
|
||||
"text": false,
|
||||
"__experimentalDefaultControls": {
|
||||
"background": true,
|
||||
"link": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"viewScript": "file:./view.min.js",
|
||||
"editorStyle": "wp-block-file-editor",
|
||||
|
@ -1 +1 @@
|
||||
<?php return array('dependencies' => array(), 'version' => 'ee575fc5e86fe255013d');
|
||||
<?php return array('dependencies' => array(), 'version' => 'e614f07ba8410b17e456');
|
||||
|
@ -1 +1 @@
|
||||
<?php return array('dependencies' => array(), 'version' => '2a20786ca914ea00891f');
|
||||
<?php return array('dependencies' => array(), 'version' => '9d287166f699a66eff3b');
|
||||
|
78
src/wp-includes/blocks/footnotes.php
Normal file
78
src/wp-includes/blocks/footnotes.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Server-side rendering of the `core/footnotes` block.
|
||||
*
|
||||
* @package WordPress
|
||||
*/
|
||||
|
||||
/**
|
||||
* Renders the `core/footnotes` block on the server.
|
||||
*
|
||||
* @param array $attributes Block attributes.
|
||||
* @param string $content Block default content.
|
||||
* @param WP_Block $block Block instance.
|
||||
*
|
||||
* @return string Returns the HTML representing the footnotes.
|
||||
*/
|
||||
function render_block_core_footnotes( $attributes, $content, $block ) {
|
||||
// Bail out early if the post ID is not set for some reason.
|
||||
if ( empty( $block->context['postId'] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( post_password_required( $block->context['postId'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$footnotes = get_post_meta( $block->context['postId'], 'footnotes', true );
|
||||
|
||||
if ( ! $footnotes ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$footnotes = json_decode( $footnotes, true );
|
||||
|
||||
if ( count( $footnotes ) === 0 ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes();
|
||||
|
||||
$block_content = '';
|
||||
|
||||
foreach ( $footnotes as $footnote ) {
|
||||
$block_content .= sprintf(
|
||||
'<li id="%1$s">%2$s <a href="#%1$s-link">↩︎</a></li>',
|
||||
$footnote['id'],
|
||||
$footnote['content']
|
||||
);
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<ol %1$s>%2$s</ol>',
|
||||
$wrapper_attributes,
|
||||
$block_content
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the `core/footnotes` block on the server.
|
||||
*/
|
||||
function register_block_core_footnotes() {
|
||||
register_post_meta(
|
||||
'post',
|
||||
'footnotes',
|
||||
array(
|
||||
'show_in_rest' => true,
|
||||
'single' => true,
|
||||
'type' => 'string',
|
||||
)
|
||||
);
|
||||
register_block_type_from_metadata(
|
||||
__DIR__ . '/footnotes',
|
||||
array(
|
||||
'render_callback' => 'render_block_core_footnotes',
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'init', 'register_block_core_footnotes' );
|
18
src/wp-includes/blocks/footnotes/block.json
Normal file
18
src/wp-includes/blocks/footnotes/block.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "core/footnotes",
|
||||
"title": "Footnotes",
|
||||
"category": "text",
|
||||
"description": "",
|
||||
"keywords": [ "references" ],
|
||||
"textdomain": "default",
|
||||
"usesContext": [ "postId", "postType" ],
|
||||
"supports": {
|
||||
"html": false,
|
||||
"multiple": false,
|
||||
"inserter": false,
|
||||
"reusable": false
|
||||
},
|
||||
"style": "wp-block-footnotes"
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/freeform",
|
||||
"title": "Classic",
|
||||
"category": "text",
|
||||
@ -9,7 +9,7 @@
|
||||
"attributes": {
|
||||
"content": {
|
||||
"type": "string",
|
||||
"source": "html"
|
||||
"source": "raw"
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/gallery",
|
||||
"title": "Gallery",
|
||||
"category": "media",
|
||||
@ -123,7 +123,7 @@
|
||||
"background": true,
|
||||
"gradients": true
|
||||
},
|
||||
"__experimentalLayout": {
|
||||
"layout": {
|
||||
"allowSwitching": false,
|
||||
"allowInheriting": false,
|
||||
"allowEditing": false,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/group",
|
||||
"title": "Group",
|
||||
"category": "design",
|
||||
@ -15,6 +15,9 @@
|
||||
"templateLock": {
|
||||
"type": [ "string", "boolean" ],
|
||||
"enum": [ "all", "insert", "contentOnly", false ]
|
||||
},
|
||||
"allowedBlocks": {
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
@ -72,7 +75,7 @@
|
||||
"fontSize": true
|
||||
}
|
||||
},
|
||||
"__experimentalLayout": {
|
||||
"layout": {
|
||||
"allowSizingOnChildren": true
|
||||
}
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/heading",
|
||||
"title": "Heading",
|
||||
"category": "text",
|
||||
|
@ -98,12 +98,12 @@ function block_core_home_link_build_li_wrapper_attributes( $context ) {
|
||||
$colors['css_classes'],
|
||||
$font_sizes['css_classes']
|
||||
);
|
||||
$classes[] = 'wp-block-navigation-item';
|
||||
$style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] );
|
||||
$css_classes = trim( implode( ' ', $classes ) ) . ' wp-block-navigation-item';
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes(
|
||||
array(
|
||||
'class' => $css_classes,
|
||||
'class' => implode( ' ', $classes ),
|
||||
'style' => $style_attribute,
|
||||
)
|
||||
);
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/home-link",
|
||||
"category": "design",
|
||||
"parent": [ "core/navigation" ],
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/html",
|
||||
"title": "Custom HTML",
|
||||
"category": "widgets",
|
||||
|
@ -14,24 +14,30 @@
|
||||
* @return string Returns the block content with the data-id attribute added.
|
||||
*/
|
||||
function render_block_core_image( $attributes, $content ) {
|
||||
|
||||
$processor = new WP_HTML_Tag_Processor( $content );
|
||||
$processor->next_tag( 'img' );
|
||||
|
||||
if ( $processor->get_attribute( 'src' ) === null ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( isset( $attributes['data-id'] ) ) {
|
||||
// Add the data-id="$id" attribute to the img element
|
||||
// to provide backwards compatibility for the Gallery Block,
|
||||
// which now wraps Image Blocks within innerBlocks.
|
||||
// The data-id attribute is added in a core/gallery `render_block_data` hook.
|
||||
$data_id_attribute = 'data-id="' . esc_attr( $attributes['data-id'] ) . '"';
|
||||
if ( ! str_contains( $content, $data_id_attribute ) ) {
|
||||
$content = str_replace( '<img', '<img ' . $data_id_attribute . ' ', $content );
|
||||
}
|
||||
$processor->set_attribute( 'data-id', $attributes['data-id'] );
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
return $processor->get_updated_html();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the `core/image` block on server.
|
||||
*/
|
||||
function register_block_core_image() {
|
||||
|
||||
register_block_type_from_metadata(
|
||||
__DIR__ . '/image',
|
||||
array(
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/image",
|
||||
"title": "Image",
|
||||
"category": "media",
|
||||
@ -69,6 +69,12 @@
|
||||
"height": {
|
||||
"type": "number"
|
||||
},
|
||||
"aspectRatio": {
|
||||
"type": "string"
|
||||
},
|
||||
"scale": {
|
||||
"type": "string"
|
||||
},
|
||||
"sizeSlug": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -84,16 +90,20 @@
|
||||
},
|
||||
"supports": {
|
||||
"anchor": true,
|
||||
"behaviors": {
|
||||
"lightbox": true
|
||||
},
|
||||
"color": {
|
||||
"__experimentalDuotone": "img, .components-placeholder",
|
||||
"text": false,
|
||||
"background": false
|
||||
},
|
||||
"filter": {
|
||||
"duotone": true
|
||||
},
|
||||
"__experimentalBorder": {
|
||||
"color": true,
|
||||
"radius": true,
|
||||
"width": true,
|
||||
"__experimentalSelector": "img, .wp-block-image__crop-area",
|
||||
"__experimentalSkipSerialization": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"color": true,
|
||||
@ -102,6 +112,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"selectors": {
|
||||
"border": ".wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder",
|
||||
"filter": {
|
||||
"duotone": ".wp-block-image img, .wp-block-image .components-placeholder"
|
||||
}
|
||||
},
|
||||
"styles": [
|
||||
{
|
||||
"name": "default",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/latest-comments",
|
||||
"title": "Latest Comments",
|
||||
"category": "widgets",
|
||||
@ -33,6 +33,19 @@
|
||||
"spacing": {
|
||||
"margin": true,
|
||||
"padding": true
|
||||
},
|
||||
"typography": {
|
||||
"fontSize": true,
|
||||
"lineHeight": true,
|
||||
"__experimentalFontFamily": true,
|
||||
"__experimentalFontWeight": true,
|
||||
"__experimentalFontStyle": true,
|
||||
"__experimentalTextTransform": true,
|
||||
"__experimentalTextDecoration": true,
|
||||
"__experimentalLetterSpacing": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"fontSize": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"editorStyle": "wp-block-latest-comments-editor",
|
||||
|
@ -48,6 +48,14 @@ function render_block_core_latest_posts( $attributes ) {
|
||||
$block_core_latest_posts_excerpt_length = $attributes['excerptLength'];
|
||||
add_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 );
|
||||
|
||||
$filter_latest_posts_excerpt_more = static function( $more ) use ( $attributes ) {
|
||||
$use_excerpt = 'excerpt' === $attributes['displayPostContentRadio'];
|
||||
/* translators: %1$s is a URL to a post, excerpt truncation character, default … */
|
||||
return $use_excerpt ? sprintf( __( ' … <a href="%1$s" rel="noopener noreferrer">Read more</a>', 'gutenberg' ), esc_url( get_permalink() ) ) : $more;
|
||||
};
|
||||
|
||||
add_filter( 'excerpt_more', $filter_latest_posts_excerpt_more );
|
||||
|
||||
if ( isset( $attributes['categories'] ) ) {
|
||||
$args['category__in'] = array_column( $attributes['categories'], 'id' );
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/latest-posts",
|
||||
"title": "Latest Posts",
|
||||
"category": "widgets",
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/legacy-widget",
|
||||
"title": "Legacy Widget",
|
||||
"category": "widgets",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/list-item",
|
||||
"title": "List item",
|
||||
"category": "text",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/list",
|
||||
"title": "List",
|
||||
"category": "text",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/loginout",
|
||||
"title": "Login/out",
|
||||
"category": "theme",
|
||||
@ -20,7 +20,17 @@
|
||||
"supports": {
|
||||
"className": true,
|
||||
"typography": {
|
||||
"fontSize": false
|
||||
"fontSize": true,
|
||||
"lineHeight": true,
|
||||
"__experimentalFontFamily": true,
|
||||
"__experimentalFontWeight": true,
|
||||
"__experimentalFontStyle": true,
|
||||
"__experimentalTextTransform": true,
|
||||
"__experimentalTextDecoration": true,
|
||||
"__experimentalLetterSpacing": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"fontSize": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/media-text",
|
||||
"title": "Media & Text",
|
||||
"category": "media",
|
||||
@ -10,7 +10,7 @@
|
||||
"attributes": {
|
||||
"align": {
|
||||
"type": "string",
|
||||
"default": "wide"
|
||||
"default": "none"
|
||||
},
|
||||
"mediaAlt": {
|
||||
"type": "string",
|
||||
@ -89,6 +89,9 @@
|
||||
},
|
||||
"focalPoint": {
|
||||
"type": "object"
|
||||
},
|
||||
"allowedBlocks": {
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/missing",
|
||||
"title": "Unsupported",
|
||||
"category": "text",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/more",
|
||||
"title": "More",
|
||||
"category": "design",
|
||||
|
@ -181,7 +181,8 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
|
||||
|
||||
$css_classes = trim( implode( ' ', $classes ) );
|
||||
$has_submenu = count( $block->inner_blocks ) > 0;
|
||||
$is_active = ! empty( $attributes['id'] ) && ( get_queried_object_id() === (int) $attributes['id'] );
|
||||
$kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] );
|
||||
$is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind );
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes(
|
||||
array(
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/navigation-link",
|
||||
"title": "Custom Link",
|
||||
"category": "design",
|
||||
|
@ -14,66 +14,6 @@
|
||||
* @param bool $is_sub_menu Whether the block is a sub-menu.
|
||||
* @return array Colors CSS classes and inline styles.
|
||||
*/
|
||||
function block_core_navigation_submenu_build_css_colors( $context, $attributes, $is_sub_menu = false ) {
|
||||
$colors = array(
|
||||
'css_classes' => array(),
|
||||
'inline_styles' => '',
|
||||
);
|
||||
|
||||
// Text color.
|
||||
$named_text_color = null;
|
||||
$custom_text_color = null;
|
||||
|
||||
if ( $is_sub_menu && array_key_exists( 'customOverlayTextColor', $context ) ) {
|
||||
$custom_text_color = $context['customOverlayTextColor'];
|
||||
} elseif ( $is_sub_menu && array_key_exists( 'overlayTextColor', $context ) ) {
|
||||
$named_text_color = $context['overlayTextColor'];
|
||||
} elseif ( array_key_exists( 'customTextColor', $context ) ) {
|
||||
$custom_text_color = $context['customTextColor'];
|
||||
} elseif ( array_key_exists( 'textColor', $context ) ) {
|
||||
$named_text_color = $context['textColor'];
|
||||
} elseif ( isset( $context['style']['color']['text'] ) ) {
|
||||
$custom_text_color = $context['style']['color']['text'];
|
||||
}
|
||||
|
||||
// If has text color.
|
||||
if ( ! is_null( $named_text_color ) ) {
|
||||
// Add the color class.
|
||||
array_push( $colors['css_classes'], 'has-text-color', sprintf( 'has-%s-color', $named_text_color ) );
|
||||
} elseif ( ! is_null( $custom_text_color ) ) {
|
||||
// Add the custom color inline style.
|
||||
$colors['css_classes'][] = 'has-text-color';
|
||||
$colors['inline_styles'] .= sprintf( 'color: %s;', $custom_text_color );
|
||||
}
|
||||
|
||||
// Background color.
|
||||
$named_background_color = null;
|
||||
$custom_background_color = null;
|
||||
|
||||
if ( $is_sub_menu && array_key_exists( 'customOverlayBackgroundColor', $context ) ) {
|
||||
$custom_background_color = $context['customOverlayBackgroundColor'];
|
||||
} elseif ( $is_sub_menu && array_key_exists( 'overlayBackgroundColor', $context ) ) {
|
||||
$named_background_color = $context['overlayBackgroundColor'];
|
||||
} elseif ( array_key_exists( 'customBackgroundColor', $context ) ) {
|
||||
$custom_background_color = $context['customBackgroundColor'];
|
||||
} elseif ( array_key_exists( 'backgroundColor', $context ) ) {
|
||||
$named_background_color = $context['backgroundColor'];
|
||||
} elseif ( isset( $context['style']['color']['background'] ) ) {
|
||||
$custom_background_color = $context['style']['color']['background'];
|
||||
}
|
||||
|
||||
// If has background color.
|
||||
if ( ! is_null( $named_background_color ) ) {
|
||||
// Add the background-color class.
|
||||
array_push( $colors['css_classes'], 'has-background', sprintf( 'has-%s-background-color', $named_background_color ) );
|
||||
} elseif ( ! is_null( $custom_background_color ) ) {
|
||||
// Add the custom background-color inline style.
|
||||
$colors['css_classes'][] = 'has-background';
|
||||
$colors['inline_styles'] .= sprintf( 'background-color: %s;', $custom_background_color );
|
||||
}
|
||||
|
||||
return $colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an array with CSS classes and inline styles defining the font sizes
|
||||
@ -129,7 +69,6 @@ function block_core_navigation_submenu_render_submenu_icon() {
|
||||
* @return string Returns the post content with the legacy widget added.
|
||||
*/
|
||||
function render_block_core_navigation_submenu( $attributes, $content, $block ) {
|
||||
|
||||
$navigation_link_has_id = isset( $attributes['id'] ) && is_numeric( $attributes['id'] );
|
||||
$is_post_type = isset( $attributes['kind'] ) && 'post-type' === $attributes['kind'];
|
||||
$is_post_type = $is_post_type || isset( $attributes['type'] ) && ( 'post' === $attributes['type'] || 'page' === $attributes['type'] );
|
||||
@ -144,17 +83,13 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$colors = block_core_navigation_submenu_build_css_colors( $block->context, $attributes );
|
||||
$font_sizes = block_core_navigation_submenu_build_css_font_sizes( $block->context );
|
||||
$classes = array_merge(
|
||||
$colors['css_classes'],
|
||||
$font_sizes['css_classes']
|
||||
);
|
||||
$style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] );
|
||||
$style_attribute = $font_sizes['inline_styles'];
|
||||
|
||||
$css_classes = trim( implode( ' ', $classes ) );
|
||||
$css_classes = trim( implode( ' ', $font_sizes['css_classes'] ) );
|
||||
$has_submenu = count( $block->inner_blocks ) > 0;
|
||||
$is_active = ! empty( $attributes['id'] ) && ( get_queried_object_id() === (int) $attributes['id'] );
|
||||
$kind = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] );
|
||||
$is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind );
|
||||
|
||||
$show_submenu_indicators = isset( $block->context['showSubmenuIcon'] ) && $block->context['showSubmenuIcon'];
|
||||
$open_on_click = isset( $block->context['openSubmenusOnClick'] ) && $block->context['openSubmenusOnClick'];
|
||||
@ -249,14 +184,33 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
|
||||
}
|
||||
|
||||
if ( $has_submenu ) {
|
||||
$colors = block_core_navigation_submenu_build_css_colors( $block->context, $attributes, $has_submenu );
|
||||
$classes = array_merge(
|
||||
array( 'wp-block-navigation__submenu-container' ),
|
||||
$colors['css_classes']
|
||||
);
|
||||
$css_classes = trim( implode( ' ', $classes ) );
|
||||
// Copy some attributes from the parent block to this one.
|
||||
// Ideally this would happen in the client when the block is created.
|
||||
if ( array_key_exists( 'overlayTextColor', $block->context ) ) {
|
||||
$attributes['textColor'] = $block->context['overlayTextColor'];
|
||||
}
|
||||
if ( array_key_exists( 'overlayBackgroundColor', $block->context ) ) {
|
||||
$attributes['backgroundColor'] = $block->context['overlayBackgroundColor'];
|
||||
}
|
||||
if ( array_key_exists( 'customOverlayTextColor', $block->context ) ) {
|
||||
$attributes['style']['color']['text'] = $block->context['customOverlayTextColor'];
|
||||
}
|
||||
if ( array_key_exists( 'customOverlayBackgroundColor', $block->context ) ) {
|
||||
$attributes['style']['color']['background'] = $block->context['customOverlayBackgroundColor'];
|
||||
}
|
||||
|
||||
$style_attribute = $colors['inline_styles'];
|
||||
// This allows us to be able to get a response from gutenberg_apply_colors_support.
|
||||
$block->block_type->supports['color'] = true;
|
||||
$colors_supports = gutenberg_apply_colors_support( $block->block_type, $attributes );
|
||||
$css_classes = 'wp-block-navigation__submenu-container';
|
||||
if ( array_key_exists( 'class', $colors_supports ) ) {
|
||||
$css_classes .= ' ' . $colors_supports['class'];
|
||||
}
|
||||
|
||||
$style_attribute = '';
|
||||
if ( array_key_exists( 'style', $colors_supports ) ) {
|
||||
$style_attribute = $colors_supports['style'];
|
||||
}
|
||||
|
||||
$inner_blocks_html = '';
|
||||
foreach ( $block->inner_blocks as $inner_block ) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/navigation-submenu",
|
||||
"title": "Submenu",
|
||||
"category": "design",
|
||||
|
@ -65,59 +65,87 @@ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
|
||||
|
||||
return $menu_items_by_parent_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Interactivity API directives to the navigation-submenu and page-list blocks markup using the Tag Processor
|
||||
* The final HTML of the navigation-submenu and the page-list blocks will look similar to this:
|
||||
*
|
||||
* <li
|
||||
* class="has-child"
|
||||
* data-wp-context='{ "core": { "navigation": { "isMenuOpen": false, "overlay": false } } }'
|
||||
* data-wp-effect="effects.core.navigation.initMenu"
|
||||
* data-wp-on.keydown="actions.core.navigation.handleMenuKeydown"
|
||||
* data-wp-on.focusout="actions.core.navigation.handleMenuFocusout"
|
||||
* >
|
||||
* <button
|
||||
* class="wp-block-navigation-submenu__toggle"
|
||||
* data-wp-on.click="actions.core.navigation.openMenu"
|
||||
* data-wp-bind.aria-expanded="context.core.navigation.isMenuOpen"
|
||||
* >
|
||||
* </button>
|
||||
* <span>Title</span>
|
||||
* <ul class="wp-block-navigation__submenu-container">
|
||||
* SUBMENU ITEMS
|
||||
* </ul>
|
||||
* </li>
|
||||
*
|
||||
* @param string $w Markup of the navigation block.
|
||||
* @param array $block_attributes Block attributes.
|
||||
*
|
||||
* @return string Submenu markup with the directives injected.
|
||||
*/
|
||||
function gutenberg_block_core_navigation_add_directives_to_submenu( $w, $block_attributes ) {
|
||||
while ( $w->next_tag(
|
||||
array(
|
||||
'tag_name' => 'LI',
|
||||
'class_name' => 'has-child',
|
||||
)
|
||||
) ) {
|
||||
// Add directives to the parent `<li>`.
|
||||
$w->set_attribute( 'data-wp-interactive', true );
|
||||
$w->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "isMenuOpen": { "click": false, "hover": false }, "overlay": false } } }' );
|
||||
$w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
|
||||
$w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
|
||||
$w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
|
||||
if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
|
||||
$w->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
|
||||
$w->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
|
||||
}
|
||||
|
||||
// Add directives to the toggle submenu button.
|
||||
if ( $w->next_tag(
|
||||
array(
|
||||
'tag_name' => 'BUTTON',
|
||||
'class_name' => 'wp-block-navigation-submenu__toggle',
|
||||
)
|
||||
) ) {
|
||||
$w->set_attribute( 'data-wp-on--click', 'actions.core.navigation.toggleMenuOnClick' );
|
||||
$w->set_attribute( 'data-wp-bind--aria-expanded', 'selectors.core.navigation.isMenuOpen' );
|
||||
};
|
||||
|
||||
// Iterate through subitems if exist.
|
||||
gutenberg_block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
|
||||
}
|
||||
return $w->get_updated_html();
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaces view script for the Navigation block with version using Interactivity API.
|
||||
*
|
||||
* @param array $metadata Block metadata as read in via block.json.
|
||||
*
|
||||
* @return array Filtered block type metadata.
|
||||
*/
|
||||
function gutenberg_block_core_navigation_update_interactive_view_script( $metadata ) {
|
||||
if ( 'core/navigation' === $metadata['name'] ) {
|
||||
$metadata['viewScript'] = array( 'file:./interactivity.min.js' );
|
||||
}
|
||||
return $metadata;
|
||||
}
|
||||
add_filter( 'block_type_metadata', 'gutenberg_block_core_navigation_update_interactive_view_script', 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns menu item data into a nested array of parsed blocks
|
||||
*
|
||||
* @param array $menu_items An array of menu items that represent
|
||||
* an individual level of a menu.
|
||||
* @param array $menu_items_by_parent_id An array keyed by the id of the
|
||||
* parent menu where each element is an
|
||||
* array of menu items that belong to
|
||||
* that parent.
|
||||
* @return array An array of parsed block data.
|
||||
*/
|
||||
function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) {
|
||||
if ( empty( $menu_items ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$blocks = array();
|
||||
|
||||
foreach ( $menu_items as $menu_item ) {
|
||||
$class_name = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null;
|
||||
$id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null;
|
||||
$opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target;
|
||||
$rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null;
|
||||
$kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom';
|
||||
|
||||
$block = array(
|
||||
'blockName' => isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ? 'core/navigation-submenu' : 'core/navigation-link',
|
||||
'attrs' => array(
|
||||
'className' => $class_name,
|
||||
'description' => $menu_item->description,
|
||||
'id' => $id,
|
||||
'kind' => $kind,
|
||||
'label' => $menu_item->title,
|
||||
'opensInNewTab' => $opens_in_new_tab,
|
||||
'rel' => $rel,
|
||||
'title' => $menu_item->attr_title,
|
||||
'type' => $menu_item->object,
|
||||
'url' => $menu_item->url,
|
||||
),
|
||||
);
|
||||
|
||||
$block['innerBlocks'] = isset( $menu_items_by_parent_id[ $menu_item->ID ] )
|
||||
? block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[ $menu_item->ID ], $menu_items_by_parent_id )
|
||||
: array();
|
||||
$block['innerContent'] = array_map( 'serialize_block', $block['innerBlocks'] );
|
||||
|
||||
$blocks[] = $block;
|
||||
}
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an array with CSS classes and inline styles defining the colors
|
||||
@ -248,148 +276,9 @@ function block_core_navigation_render_submenu_icon() {
|
||||
return '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the classic navigation menu to use as a fallback.
|
||||
*
|
||||
* @return object WP_Term The classic navigation.
|
||||
*/
|
||||
function block_core_navigation_get_classic_menu_fallback() {
|
||||
$classic_nav_menus = wp_get_nav_menus();
|
||||
|
||||
// If menus exist.
|
||||
if ( $classic_nav_menus && ! is_wp_error( $classic_nav_menus ) ) {
|
||||
// Handles simple use case where user has a classic menu and switches to a block theme.
|
||||
|
||||
// Returns the menu assigned to location `primary`.
|
||||
$locations = get_nav_menu_locations();
|
||||
if ( isset( $locations['primary'] ) ) {
|
||||
$primary_menu = wp_get_nav_menu_object( $locations['primary'] );
|
||||
if ( $primary_menu ) {
|
||||
return $primary_menu;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a menu if `primary` is its slug.
|
||||
foreach ( $classic_nav_menus as $classic_nav_menu ) {
|
||||
if ( 'primary' === $classic_nav_menu->slug ) {
|
||||
return $classic_nav_menu;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise return the most recently created classic menu.
|
||||
usort(
|
||||
$classic_nav_menus,
|
||||
function( $a, $b ) {
|
||||
return $b->term_id - $a->term_id;
|
||||
}
|
||||
);
|
||||
return $classic_nav_menus[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a classic navigation to blocks.
|
||||
*
|
||||
* @param object $classic_nav_menu WP_Term The classic navigation object to convert.
|
||||
* @return array the normalized parsed blocks.
|
||||
*/
|
||||
function block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_menu ) {
|
||||
// BEGIN: Code that already exists in wp_nav_menu().
|
||||
$menu_items = wp_get_nav_menu_items( $classic_nav_menu->term_id, array( 'update_post_term_cache' => false ) );
|
||||
|
||||
// Set up the $menu_item variables.
|
||||
_wp_menu_item_classes_by_context( $menu_items );
|
||||
|
||||
$sorted_menu_items = array();
|
||||
foreach ( (array) $menu_items as $menu_item ) {
|
||||
$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
|
||||
}
|
||||
|
||||
unset( $menu_items, $menu_item );
|
||||
|
||||
// END: Code that already exists in wp_nav_menu().
|
||||
|
||||
$menu_items_by_parent_id = array();
|
||||
foreach ( $sorted_menu_items as $menu_item ) {
|
||||
$menu_items_by_parent_id[ $menu_item->menu_item_parent ][] = $menu_item;
|
||||
}
|
||||
|
||||
$inner_blocks = block_core_navigation_parse_blocks_from_menu_items(
|
||||
isset( $menu_items_by_parent_id[0] )
|
||||
? $menu_items_by_parent_id[0]
|
||||
: array(),
|
||||
$menu_items_by_parent_id
|
||||
);
|
||||
|
||||
return serialize_blocks( $inner_blocks );
|
||||
}
|
||||
|
||||
/**
|
||||
* If there's a the classic menu then use it as a fallback.
|
||||
*
|
||||
* @return array the normalized parsed blocks.
|
||||
*/
|
||||
function block_core_navigation_maybe_use_classic_menu_fallback() {
|
||||
// See if we have a classic menu.
|
||||
$classic_nav_menu = block_core_navigation_get_classic_menu_fallback();
|
||||
|
||||
if ( ! $classic_nav_menu ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we have a classic menu then convert it to blocks.
|
||||
$classic_nav_menu_blocks = block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_menu );
|
||||
|
||||
if ( empty( $classic_nav_menu_blocks ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new navigation menu from the classic menu.
|
||||
$wp_insert_post_result = wp_insert_post(
|
||||
array(
|
||||
'post_content' => $classic_nav_menu_blocks,
|
||||
'post_title' => $classic_nav_menu->slug,
|
||||
'post_name' => $classic_nav_menu->slug,
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'wp_navigation',
|
||||
),
|
||||
true // So that we can check whether the result is an error.
|
||||
);
|
||||
|
||||
if ( is_wp_error( $wp_insert_post_result ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the most recently published navigation which will be the classic one created above.
|
||||
return block_core_navigation_get_most_recently_published_navigation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the most recently published `wp_navigation` Post.
|
||||
*
|
||||
* @return WP_Post|null the first non-empty Navigation or null.
|
||||
*/
|
||||
function block_core_navigation_get_most_recently_published_navigation() {
|
||||
|
||||
// Default to the most recently created menu.
|
||||
$parsed_args = array(
|
||||
'post_type' => 'wp_navigation',
|
||||
'no_found_rows' => true,
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
'order' => 'DESC',
|
||||
'orderby' => 'date',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1, // get only the most recent.
|
||||
);
|
||||
|
||||
$navigation_post = new WP_Query( $parsed_args );
|
||||
if ( count( $navigation_post->posts ) > 0 ) {
|
||||
return $navigation_post->posts[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out empty "null" blocks from the block list.
|
||||
@ -403,7 +292,7 @@ function block_core_navigation_get_most_recently_published_navigation() {
|
||||
function block_core_navigation_filter_out_empty_blocks( $parsed_blocks ) {
|
||||
$filtered = array_filter(
|
||||
$parsed_blocks,
|
||||
function( $block ) {
|
||||
static function( $block ) {
|
||||
return isset( $block['blockName'] );
|
||||
}
|
||||
);
|
||||
@ -452,15 +341,7 @@ function block_core_navigation_get_fallback_blocks() {
|
||||
// If `core/page-list` is not registered then return empty blocks.
|
||||
$fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();
|
||||
|
||||
// Default to a list of Pages.
|
||||
|
||||
$navigation_post = block_core_navigation_get_most_recently_published_navigation();
|
||||
|
||||
// If there are no navigation posts then try to find a classic menu
|
||||
// and convert it into a block based navigation menu.
|
||||
if ( ! $navigation_post ) {
|
||||
$navigation_post = block_core_navigation_maybe_use_classic_menu_fallback();
|
||||
}
|
||||
$navigation_post = WP_Navigation_Fallback_Gutenberg::get_fallback();
|
||||
|
||||
// Use the first non-empty Navigation as fallback if available.
|
||||
if ( $navigation_post ) {
|
||||
@ -531,7 +412,6 @@ function block_core_navigation_from_block_get_post_ids( $block ) {
|
||||
* @return string Returns the post content with the legacy widget added.
|
||||
*/
|
||||
function render_block_core_navigation( $attributes, $content, $block ) {
|
||||
|
||||
static $seen_menu_names = array();
|
||||
|
||||
// Flag used to indicate whether the rendered output is considered to be
|
||||
@ -562,15 +442,6 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
||||
*/
|
||||
$has_old_responsive_attribute = ! empty( $attributes['isResponsive'] ) && $attributes['isResponsive'];
|
||||
$is_responsive_menu = isset( $attributes['overlayMenu'] ) && 'never' !== $attributes['overlayMenu'] || $has_old_responsive_attribute;
|
||||
$should_load_view_script = ! wp_script_is( 'wp-block-navigation-view' ) && ( $is_responsive_menu || $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] );
|
||||
if ( $should_load_view_script ) {
|
||||
wp_enqueue_script( 'wp-block-navigation-view' );
|
||||
}
|
||||
|
||||
$should_load_modal_view_script = isset( $attributes['overlayMenu'] ) && 'never' !== $attributes['overlayMenu'];
|
||||
if ( $should_load_modal_view_script ) {
|
||||
wp_enqueue_script( 'wp-block-navigation-view-modal' );
|
||||
}
|
||||
|
||||
$inner_blocks = $block->inner_blocks;
|
||||
|
||||
@ -668,7 +539,10 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
||||
|
||||
// Restore legacy classnames for submenu positioning.
|
||||
$layout_class = '';
|
||||
if ( isset( $attributes['layout']['justifyContent'] ) ) {
|
||||
if (
|
||||
isset( $attributes['layout']['justifyContent'] ) &&
|
||||
isset( $layout_justification[ $attributes['layout']['justifyContent'] ] )
|
||||
) {
|
||||
$layout_class .= $layout_justification[ $attributes['layout']['justifyContent'] ];
|
||||
}
|
||||
if ( isset( $attributes['layout']['orientation'] ) && 'vertical' === $attributes['layout']['orientation'] ) {
|
||||
@ -712,14 +586,44 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
||||
'core/site-logo',
|
||||
);
|
||||
|
||||
$block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : '';
|
||||
$style = $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'];
|
||||
$class = implode( ' ', $classes );
|
||||
|
||||
// If the menu name has been used previously then append an ID
|
||||
// to the name to ensure uniqueness across a given post.
|
||||
if ( isset( $seen_menu_names[ $nav_menu_name ] ) && $seen_menu_names[ $nav_menu_name ] > 1 ) {
|
||||
$count = $seen_menu_names[ $nav_menu_name ];
|
||||
$nav_menu_name = $nav_menu_name . ' ' . ( $count );
|
||||
}
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes(
|
||||
array(
|
||||
'class' => $class,
|
||||
'style' => $style,
|
||||
'aria-label' => $nav_menu_name,
|
||||
)
|
||||
);
|
||||
|
||||
$container_attributes = get_block_wrapper_attributes(
|
||||
array(
|
||||
'class' => 'wp-block-navigation__container ' . $class,
|
||||
'style' => $style,
|
||||
)
|
||||
);
|
||||
|
||||
$inner_blocks_html = '';
|
||||
$is_list_open = false;
|
||||
$has_submenus = false;
|
||||
foreach ( $inner_blocks as $inner_block ) {
|
||||
$is_list_item = in_array( $inner_block->name, $list_item_nav_blocks, true );
|
||||
|
||||
if ( $is_list_item && ! $is_list_open ) {
|
||||
$is_list_open = true;
|
||||
$inner_blocks_html .= '<ul class="wp-block-navigation__container">';
|
||||
$inner_blocks_html .= sprintf(
|
||||
'<ul %1$s>',
|
||||
$container_attributes
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! $is_list_item && $is_list_open ) {
|
||||
@ -728,6 +632,15 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
||||
}
|
||||
|
||||
$inner_block_content = $inner_block->render();
|
||||
$p = new WP_HTML_Tag_Processor( $inner_block_content );
|
||||
if ( $p->next_tag(
|
||||
array(
|
||||
'name' => 'LI',
|
||||
'class_name' => 'has-child',
|
||||
)
|
||||
) ) {
|
||||
$has_submenus = true;
|
||||
}
|
||||
if ( ! empty( $inner_block_content ) ) {
|
||||
if ( in_array( $inner_block->name, $needs_list_item_wrapper, true ) ) {
|
||||
$inner_blocks_html .= '<li class="wp-block-navigation-item">' . $inner_block_content . '</li>';
|
||||
@ -741,22 +654,27 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
||||
$inner_blocks_html .= '</ul>';
|
||||
}
|
||||
|
||||
$block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : '';
|
||||
// If the script already exists, there is no point in removing it from viewScript.
|
||||
$should_load_view_script = ( $is_responsive_menu || ( $has_submenus && ( $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ) ) );
|
||||
$view_js_file = 'wp-block-navigation-view';
|
||||
if ( ! wp_script_is( $view_js_file ) ) {
|
||||
$script_handles = $block->block_type->view_script_handles;
|
||||
|
||||
// If the menu name has been used previously then append an ID
|
||||
// to the name to ensure uniqueness across a given post.
|
||||
if ( isset( $seen_menu_names[ $nav_menu_name ] ) && $seen_menu_names[ $nav_menu_name ] > 1 ) {
|
||||
$count = $seen_menu_names[ $nav_menu_name ];
|
||||
$nav_menu_name = $nav_menu_name . ' ' . ( $count );
|
||||
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
||||
if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
|
||||
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file, 'wp-block-navigation-view-2' ) );
|
||||
}
|
||||
// If the script is needed, but it was previously removed, add it again.
|
||||
if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
|
||||
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file, 'wp-block-navigation-view-2' ) );
|
||||
}
|
||||
}
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes(
|
||||
array(
|
||||
'class' => implode( ' ', $classes ),
|
||||
'style' => $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'],
|
||||
'aria-label' => $nav_menu_name,
|
||||
)
|
||||
);
|
||||
// Add directives to the submenu if needed.
|
||||
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && $has_submenus && $should_load_view_script ) {
|
||||
$w = new WP_HTML_Tag_Processor( $inner_blocks_html );
|
||||
$inner_blocks_html = gutenberg_block_core_navigation_add_directives_to_submenu( $w, $attributes );
|
||||
}
|
||||
|
||||
$modal_unique_id = wp_unique_id( 'modal-' );
|
||||
|
||||
@ -795,12 +713,45 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
||||
$toggle_aria_label_open = $should_display_icon_label ? 'aria-label="' . __( 'Open menu' ) . '"' : ''; // Open button label.
|
||||
$toggle_aria_label_close = $should_display_icon_label ? 'aria-label="' . __( 'Close menu' ) . '"' : ''; // Close button label.
|
||||
|
||||
// Add Interactivity API directives to the markup if needed.
|
||||
$nav_element_directives = '';
|
||||
$open_button_directives = '';
|
||||
$responsive_container_directives = '';
|
||||
$responsive_dialog_directives = '';
|
||||
$close_button_directives = '';
|
||||
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && $should_load_view_script ) {
|
||||
$nav_element_directives = '
|
||||
data-wp-interactive
|
||||
data-wp-context=\'{ "core": { "navigation": { "isMenuOpen": { "click": false, "hover": false }, "overlay": true, "roleAttribute": "" } } }\'
|
||||
';
|
||||
$open_button_directives = '
|
||||
data-wp-on--click="actions.core.navigation.openMenuOnClick"
|
||||
data-wp-on--keydown="actions.core.navigation.handleMenuKeydown"
|
||||
';
|
||||
$responsive_container_directives = '
|
||||
data-wp-class--has-modal-open="selectors.core.navigation.isMenuOpen"
|
||||
data-wp-class--is-menu-open="selectors.core.navigation.isMenuOpen"
|
||||
data-wp-effect="effects.core.navigation.initMenu"
|
||||
data-wp-on--keydown="actions.core.navigation.handleMenuKeydown"
|
||||
data-wp-on--focusout="actions.core.navigation.handleMenuFocusout"
|
||||
tabindex="-1"
|
||||
';
|
||||
$responsive_dialog_directives = '
|
||||
data-wp-bind--aria-modal="selectors.core.navigation.isMenuOpen"
|
||||
data-wp-bind--role="selectors.core.navigation.roleAttribute"
|
||||
data-wp-effect="effects.core.navigation.focusFirstElement"
|
||||
';
|
||||
$close_button_directives = '
|
||||
data-wp-on--click="actions.core.navigation.closeMenuOnClick"
|
||||
';
|
||||
}
|
||||
|
||||
$responsive_container_markup = sprintf(
|
||||
'<button aria-haspopup="true" %3$s class="%6$s" data-micromodal-trigger="%1$s">%9$s</button>
|
||||
<div class="%5$s" style="%7$s" id="%1$s">
|
||||
'<button aria-haspopup="true" %3$s class="%6$s" data-micromodal-trigger="%1$s" %11$s>%9$s</button>
|
||||
<div class="%5$s" style="%7$s" id="%1$s" %12$s>
|
||||
<div class="wp-block-navigation__responsive-close" tabindex="-1" data-micromodal-close>
|
||||
<div class="wp-block-navigation__responsive-dialog" aria-label="%8$s">
|
||||
<button %4$s data-micromodal-close class="wp-block-navigation__responsive-container-close">%10$s</button>
|
||||
<div class="wp-block-navigation__responsive-dialog" aria-label="%8$s" %13$s>
|
||||
<button %4$s data-micromodal-close class="wp-block-navigation__responsive-container-close" %14$s>%10$s</button>
|
||||
<div class="wp-block-navigation__responsive-container-content" id="%1$s-content">
|
||||
%2$s
|
||||
</div>
|
||||
@ -816,13 +767,18 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
||||
esc_attr( safecss_filter_attr( $colors['overlay_inline_styles'] ) ),
|
||||
__( 'Menu' ),
|
||||
$toggle_button_content,
|
||||
$toggle_close_button_content
|
||||
$toggle_close_button_content,
|
||||
$open_button_directives,
|
||||
$responsive_container_directives,
|
||||
$responsive_dialog_directives,
|
||||
$close_button_directives
|
||||
);
|
||||
|
||||
return sprintf(
|
||||
'<nav %1$s>%2$s</nav>',
|
||||
'<nav %1$s %3$s>%2$s</nav>',
|
||||
$wrapper_attributes,
|
||||
$responsive_container_markup
|
||||
$responsive_container_markup,
|
||||
$nav_element_directives
|
||||
);
|
||||
}
|
||||
|
||||
@ -876,3 +832,212 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
|
||||
}
|
||||
|
||||
add_filter( 'render_block_data', 'block_core_navigation_typographic_presets_backcompatibility' );
|
||||
|
||||
/**
|
||||
* Turns menu item data into a nested array of parsed blocks
|
||||
*
|
||||
* @param array $menu_items An array of menu items that represent
|
||||
* an individual level of a menu.
|
||||
* @param array $menu_items_by_parent_id An array keyed by the id of the
|
||||
* parent menu where each element is an
|
||||
* array of menu items that belong to
|
||||
* that parent.
|
||||
* @return array An array of parsed block data.
|
||||
*/
|
||||
function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) {
|
||||
|
||||
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::parse_blocks_from_menu_items' );
|
||||
|
||||
if ( empty( $menu_items ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$blocks = array();
|
||||
|
||||
foreach ( $menu_items as $menu_item ) {
|
||||
$class_name = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null;
|
||||
$id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null;
|
||||
$opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target;
|
||||
$rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null;
|
||||
$kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom';
|
||||
|
||||
$block = array(
|
||||
'blockName' => isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ? 'core/navigation-submenu' : 'core/navigation-link',
|
||||
'attrs' => array(
|
||||
'className' => $class_name,
|
||||
'description' => $menu_item->description,
|
||||
'id' => $id,
|
||||
'kind' => $kind,
|
||||
'label' => $menu_item->title,
|
||||
'opensInNewTab' => $opens_in_new_tab,
|
||||
'rel' => $rel,
|
||||
'title' => $menu_item->attr_title,
|
||||
'type' => $menu_item->object,
|
||||
'url' => $menu_item->url,
|
||||
),
|
||||
);
|
||||
|
||||
$block['innerBlocks'] = isset( $menu_items_by_parent_id[ $menu_item->ID ] )
|
||||
? block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[ $menu_item->ID ], $menu_items_by_parent_id )
|
||||
: array();
|
||||
$block['innerContent'] = array_map( 'serialize_block', $block['innerBlocks'] );
|
||||
|
||||
$blocks[] = $block;
|
||||
}
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the classic navigation menu to use as a fallback.
|
||||
*
|
||||
* @return object WP_Term The classic navigation.
|
||||
*/
|
||||
function block_core_navigation_get_classic_menu_fallback() {
|
||||
|
||||
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::get_classic_menu_fallback' );
|
||||
|
||||
$classic_nav_menus = wp_get_nav_menus();
|
||||
|
||||
// If menus exist.
|
||||
if ( $classic_nav_menus && ! is_wp_error( $classic_nav_menus ) ) {
|
||||
// Handles simple use case where user has a classic menu and switches to a block theme.
|
||||
|
||||
// Returns the menu assigned to location `primary`.
|
||||
$locations = get_nav_menu_locations();
|
||||
if ( isset( $locations['primary'] ) ) {
|
||||
$primary_menu = wp_get_nav_menu_object( $locations['primary'] );
|
||||
if ( $primary_menu ) {
|
||||
return $primary_menu;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a menu if `primary` is its slug.
|
||||
foreach ( $classic_nav_menus as $classic_nav_menu ) {
|
||||
if ( 'primary' === $classic_nav_menu->slug ) {
|
||||
return $classic_nav_menu;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise return the most recently created classic menu.
|
||||
usort(
|
||||
$classic_nav_menus,
|
||||
static function( $a, $b ) {
|
||||
return $b->term_id - $a->term_id;
|
||||
}
|
||||
);
|
||||
return $classic_nav_menus[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a classic navigation to blocks.
|
||||
*
|
||||
* @param object $classic_nav_menu WP_Term The classic navigation object to convert.
|
||||
* @return array the normalized parsed blocks.
|
||||
*/
|
||||
function block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_menu ) {
|
||||
|
||||
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::get_classic_menu_fallback_blocks' );
|
||||
|
||||
// BEGIN: Code that already exists in wp_nav_menu().
|
||||
$menu_items = wp_get_nav_menu_items( $classic_nav_menu->term_id, array( 'update_post_term_cache' => false ) );
|
||||
|
||||
// Set up the $menu_item variables.
|
||||
_wp_menu_item_classes_by_context( $menu_items );
|
||||
|
||||
$sorted_menu_items = array();
|
||||
foreach ( (array) $menu_items as $menu_item ) {
|
||||
$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
|
||||
}
|
||||
|
||||
unset( $menu_items, $menu_item );
|
||||
|
||||
// END: Code that already exists in wp_nav_menu().
|
||||
|
||||
$menu_items_by_parent_id = array();
|
||||
foreach ( $sorted_menu_items as $menu_item ) {
|
||||
$menu_items_by_parent_id[ $menu_item->menu_item_parent ][] = $menu_item;
|
||||
}
|
||||
|
||||
$inner_blocks = block_core_navigation_parse_blocks_from_menu_items(
|
||||
isset( $menu_items_by_parent_id[0] )
|
||||
? $menu_items_by_parent_id[0]
|
||||
: array(),
|
||||
$menu_items_by_parent_id
|
||||
);
|
||||
|
||||
return serialize_blocks( $inner_blocks );
|
||||
}
|
||||
|
||||
/**
|
||||
* If there's a the classic menu then use it as a fallback.
|
||||
*
|
||||
* @return array the normalized parsed blocks.
|
||||
*/
|
||||
function block_core_navigation_maybe_use_classic_menu_fallback() {
|
||||
|
||||
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::create_classic_menu_fallback' );
|
||||
|
||||
// See if we have a classic menu.
|
||||
$classic_nav_menu = block_core_navigation_get_classic_menu_fallback();
|
||||
|
||||
if ( ! $classic_nav_menu ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we have a classic menu then convert it to blocks.
|
||||
$classic_nav_menu_blocks = block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_menu );
|
||||
|
||||
if ( empty( $classic_nav_menu_blocks ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new navigation menu from the classic menu.
|
||||
$wp_insert_post_result = wp_insert_post(
|
||||
array(
|
||||
'post_content' => $classic_nav_menu_blocks,
|
||||
'post_title' => $classic_nav_menu->name,
|
||||
'post_name' => $classic_nav_menu->slug,
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'wp_navigation',
|
||||
),
|
||||
true // So that we can check whether the result is an error.
|
||||
);
|
||||
|
||||
if ( is_wp_error( $wp_insert_post_result ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the most recently published navigation which will be the classic one created above.
|
||||
return block_core_navigation_get_most_recently_published_navigation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the most recently published `wp_navigation` Post.
|
||||
*
|
||||
* @return WP_Post|null the first non-empty Navigation or null.
|
||||
*/
|
||||
function block_core_navigation_get_most_recently_published_navigation() {
|
||||
|
||||
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::get_most_recently_published_navigation' );
|
||||
|
||||
// Default to the most recently created menu.
|
||||
$parsed_args = array(
|
||||
'post_type' => 'wp_navigation',
|
||||
'no_found_rows' => true,
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
'order' => 'DESC',
|
||||
'orderby' => 'date',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1, // get only the most recent.
|
||||
);
|
||||
|
||||
$navigation_post = new WP_Query( $parsed_args );
|
||||
if ( count( $navigation_post->posts ) > 0 ) {
|
||||
return $navigation_post->posts[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/navigation",
|
||||
"title": "Navigation",
|
||||
"category": "theme",
|
||||
@ -87,7 +87,6 @@
|
||||
"showSubmenuIcon": "showSubmenuIcon",
|
||||
"openSubmenusOnClick": "openSubmenusOnClick",
|
||||
"style": "style",
|
||||
"orientation": "orientation",
|
||||
"maxNestingLevel": "maxNestingLevel"
|
||||
},
|
||||
"supports": {
|
||||
@ -115,7 +114,7 @@
|
||||
"blockGap": true
|
||||
}
|
||||
},
|
||||
"__experimentalLayout": {
|
||||
"layout": {
|
||||
"allowSwitching": false,
|
||||
"allowInheriting": false,
|
||||
"allowVerticalAlignment": false,
|
||||
|
@ -1 +1 @@
|
||||
<?php return array('dependencies' => array(), 'version' => 'd09326a9acd3f6992aae');
|
||||
<?php return array('dependencies' => array(), 'version' => 'a145d0113e969f692877');
|
||||
|
@ -1 +1 @@
|
||||
<?php return array('dependencies' => array(), 'version' => 'f51363b18f0497ec84da');
|
||||
<?php return array('dependencies' => array(), 'version' => '4922697e0a5370a09f02');
|
||||
|
@ -1 +1 @@
|
||||
<?php return array('dependencies' => array(), 'version' => '4ab20ef60d94f9632256');
|
||||
<?php return array('dependencies' => array(), 'version' => 'e0302ba06467706c7421');
|
||||
|
@ -1 +1 @@
|
||||
<?php return array('dependencies' => array(), 'version' => 'c24330f635f5cb9d5e0e');
|
||||
<?php return array('dependencies' => array(), 'version' => '886680af40b7521d60fc');
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/nextpage",
|
||||
"title": "Page Break",
|
||||
"category": "design",
|
||||
|
14
src/wp-includes/blocks/page-list-item.php
Normal file
14
src/wp-includes/blocks/page-list-item.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Server-side rendering of the `core/page-list-item` block.
|
||||
*
|
||||
* @package WordPress
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers the `core/page-list-item` block on server.
|
||||
*/
|
||||
function register_block_core_page_list_item() {
|
||||
register_block_type_from_metadata( __DIR__ . '/page-list-item' );
|
||||
}
|
||||
add_action( 'init', 'register_block_core_page_list_item' );
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/page-list-item",
|
||||
"title": "Page List Item",
|
||||
"category": "widgets",
|
||||
|
@ -150,7 +150,8 @@ function block_core_page_list_render_nested_page_list( $open_submenus_on_click,
|
||||
if ( empty( $nested_pages ) ) {
|
||||
return;
|
||||
}
|
||||
$markup = '';
|
||||
$front_page_id = (int) get_option( 'page_on_front' );
|
||||
$markup = '';
|
||||
foreach ( (array) $nested_pages as $page ) {
|
||||
$css_class = $page['is_active'] ? ' current-menu-item' : '';
|
||||
$aria_current = $page['is_active'] ? ' aria-current="page"' : '';
|
||||
@ -181,7 +182,6 @@ function block_core_page_list_render_nested_page_list( $open_submenus_on_click,
|
||||
}
|
||||
}
|
||||
|
||||
$front_page_id = (int) get_option( 'page_on_front' );
|
||||
if ( (int) $page['page_id'] === $front_page_id ) {
|
||||
$css_class .= ' menu-item-home';
|
||||
}
|
||||
@ -282,14 +282,14 @@ function render_block_core_page_list( $attributes, $content, $block ) {
|
||||
$pages_with_children[ $page->post_parent ][ $page->ID ] = array(
|
||||
'page_id' => $page->ID,
|
||||
'title' => $page->post_title,
|
||||
'link' => get_permalink( $page->ID ),
|
||||
'link' => get_permalink( $page ),
|
||||
'is_active' => $is_active,
|
||||
);
|
||||
} else {
|
||||
$top_level_pages[ $page->ID ] = array(
|
||||
'page_id' => $page->ID,
|
||||
'title' => $page->post_title,
|
||||
'link' => get_permalink( $page->ID ),
|
||||
'link' => get_permalink( $page ),
|
||||
'is_active' => $is_active,
|
||||
);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/page-list",
|
||||
"title": "Page List",
|
||||
"category": "widgets",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/paragraph",
|
||||
"title": "Paragraph",
|
||||
"category": "text",
|
||||
@ -43,7 +43,11 @@
|
||||
},
|
||||
"spacing": {
|
||||
"margin": true,
|
||||
"padding": true
|
||||
"padding": true,
|
||||
"__experimentalDefaultControls": {
|
||||
"margin": false,
|
||||
"padding": false
|
||||
}
|
||||
},
|
||||
"typography": {
|
||||
"fontSize": true,
|
||||
|
@ -33,6 +33,7 @@ function render_block_core_pattern( $attributes ) {
|
||||
|
||||
$slug = $attributes['slug'];
|
||||
$registry = WP_Block_Patterns_Registry::get_instance();
|
||||
|
||||
if ( ! $registry->is_registered( $slug ) ) {
|
||||
return '';
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/pattern",
|
||||
"title": "Pattern",
|
||||
"title": "Pattern placeholder",
|
||||
"category": "theme",
|
||||
"description": "Show a block pattern.",
|
||||
"supports": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-author-biography",
|
||||
"title": "Post Author Biography",
|
||||
"category": "theme",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-author-name",
|
||||
"title": "Post Author Name",
|
||||
"category": "theme",
|
||||
|
@ -32,7 +32,7 @@ function render_block_core_post_author( $attributes, $content, $block ) {
|
||||
$link = get_author_posts_url( $author_id );
|
||||
$author_name = get_the_author_meta( 'display_name', $author_id );
|
||||
if ( ! empty( $attributes['isLink'] && ! empty( $attributes['linkTarget'] ) ) ) {
|
||||
$author_name = sprintf( '<a href="%1s" target="%2s">%2s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $author_name );
|
||||
$author_name = sprintf( '<a href="%1$s" target="%2$s">%3$s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $author_name );
|
||||
}
|
||||
|
||||
$byline = ! empty( $attributes['byline'] ) ? $attributes['byline'] : false;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-author",
|
||||
"title": "Post Author",
|
||||
"category": "theme",
|
||||
@ -63,6 +63,5 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"editorStyle": "wp-block-post-author-editor",
|
||||
"style": "wp-block-post-author"
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-comments-form",
|
||||
"title": "Post Comments Form",
|
||||
"category": "theme",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-content",
|
||||
"title": "Post Content",
|
||||
"category": "theme",
|
||||
@ -10,7 +10,7 @@
|
||||
"supports": {
|
||||
"align": [ "wide", "full" ],
|
||||
"html": false,
|
||||
"__experimentalLayout": true,
|
||||
"layout": true,
|
||||
"dimensions": {
|
||||
"minHeight": true
|
||||
},
|
||||
|
@ -18,25 +18,34 @@ function render_block_core_post_date( $attributes, $content, $block ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$post_ID = $block->context['postId'];
|
||||
$post_ID = $block->context['postId'];
|
||||
$formatted_date = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
|
||||
$unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
|
||||
$classes = array();
|
||||
|
||||
$classes = array();
|
||||
if ( isset( $attributes['textAlign'] ) ) {
|
||||
$classes[] = 'has-text-align-' . $attributes['textAlign'];
|
||||
}
|
||||
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
|
||||
$classes[] = 'has-link-color';
|
||||
}
|
||||
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
|
||||
|
||||
/*
|
||||
* If the "Display last modified date" setting is enabled,
|
||||
* only display the modified date if it is later than the publishing date.
|
||||
*/
|
||||
if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
|
||||
$formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
|
||||
$unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
|
||||
} else {
|
||||
$formatted_date = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
|
||||
$unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
|
||||
if ( get_the_modified_date( 'Ymdhi', $post_ID ) > get_the_date( 'Ymdhi', $post_ID ) ) {
|
||||
$formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
|
||||
$unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
|
||||
$classes[] = 'wp-block-post-date__modified-date';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
|
||||
|
||||
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
|
||||
$formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $post_ID ), $formatted_date );
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-date",
|
||||
"title": "Post Date",
|
||||
"category": "theme",
|
||||
|
@ -18,14 +18,20 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$excerpt = get_the_excerpt();
|
||||
|
||||
if ( empty( $excerpt ) ) {
|
||||
return '';
|
||||
/*
|
||||
* The purpose of the excerpt length setting is to limit the length of both
|
||||
* automatically generated and user-created excerpts.
|
||||
* Because the excerpt_length filter only applies to auto generated excerpts,
|
||||
* wp_trim_words is used instead.
|
||||
*/
|
||||
$excerpt_length = $attributes['excerptLength'];
|
||||
$excerpt = get_the_excerpt( $block->context['postId'] );
|
||||
if ( isset( $excerpt_length ) ) {
|
||||
$excerpt = wp_trim_words( $excerpt, $excerpt_length );
|
||||
}
|
||||
|
||||
$more_text = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . wp_kses_post( $attributes['moreText'] ) . '</a>' : '';
|
||||
$filter_excerpt_more = function( $more ) use ( $more_text ) {
|
||||
$filter_excerpt_more = static function( $more ) use ( $more_text ) {
|
||||
return empty( $more_text ) ? $more : '';
|
||||
};
|
||||
/**
|
||||
@ -70,3 +76,20 @@ function register_block_core_post_excerpt() {
|
||||
);
|
||||
}
|
||||
add_action( 'init', 'register_block_core_post_excerpt' );
|
||||
|
||||
/**
|
||||
* If themes or plugins filter the excerpt_length, we need to
|
||||
* override the filter in the editor, otherwise
|
||||
* the excerpt length block setting has no effect.
|
||||
* Returns 100 because 100 is the max length in the setting.
|
||||
*/
|
||||
if ( is_admin() ||
|
||||
defined( 'REST_REQUEST' ) && REST_REQUEST ) {
|
||||
add_filter(
|
||||
'excerpt_length',
|
||||
static function() {
|
||||
return 100;
|
||||
},
|
||||
PHP_INT_MAX
|
||||
);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-excerpt",
|
||||
"title": "Post Excerpt",
|
||||
"title": "Excerpt",
|
||||
"category": "theme",
|
||||
"description": "Display a post's excerpt.",
|
||||
"description": "Display the excerpt.",
|
||||
"textdomain": "default",
|
||||
"attributes": {
|
||||
"textAlign": {
|
||||
@ -16,6 +16,10 @@
|
||||
"showMoreOnNewLine": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"excerptLength": {
|
||||
"type": "number",
|
||||
"default": 55
|
||||
}
|
||||
},
|
||||
"usesContext": [ "postId", "postType", "queryId" ],
|
||||
|
@ -42,11 +42,20 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $attributes['height'] ) ) {
|
||||
$extra_styles = "height:{$attributes['height']};";
|
||||
if ( ! empty( $attributes['scale'] ) ) {
|
||||
$extra_styles .= "object-fit:{$attributes['scale']};";
|
||||
}
|
||||
$extra_styles = '';
|
||||
|
||||
// Aspect ratio with a height set needs to override the default width/height.
|
||||
if ( ! empty( $attributes['aspectRatio'] ) ) {
|
||||
$extra_styles .= 'width:100%;height:100%;';
|
||||
} elseif ( ! empty( $attributes['height'] ) ) {
|
||||
$extra_styles .= "height:{$attributes['height']};";
|
||||
}
|
||||
|
||||
if ( ! empty( $attributes['scale'] ) ) {
|
||||
$extra_styles .= "object-fit:{$attributes['scale']};";
|
||||
}
|
||||
|
||||
if ( ! empty( $extra_styles ) ) {
|
||||
$attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles;
|
||||
}
|
||||
|
||||
@ -71,12 +80,19 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
|
||||
$featured_image = $featured_image . $overlay_markup;
|
||||
}
|
||||
|
||||
$width = ! empty( $attributes['width'] ) ? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';' : '';
|
||||
$height = ! empty( $attributes['height'] ) ? esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';' : '';
|
||||
if ( ! $height && ! $width ) {
|
||||
$aspect_ratio = ! empty( $attributes['aspectRatio'] )
|
||||
? esc_attr( safecss_filter_attr( 'aspect-ratio:' . $attributes['aspectRatio'] ) ) . ';'
|
||||
: '';
|
||||
$width = ! empty( $attributes['width'] )
|
||||
? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';'
|
||||
: '';
|
||||
$height = ! empty( $attributes['height'] )
|
||||
? esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';'
|
||||
: '';
|
||||
if ( ! $height && ! $width && ! $aspect_ratio ) {
|
||||
$wrapper_attributes = get_block_wrapper_attributes();
|
||||
} else {
|
||||
$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $width . $height ) );
|
||||
$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $aspect_ratio . $width . $height ) );
|
||||
}
|
||||
return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-featured-image",
|
||||
"title": "Post Featured Image",
|
||||
"category": "theme",
|
||||
@ -11,6 +11,9 @@
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"aspectRatio": {
|
||||
"type": "string"
|
||||
},
|
||||
"width": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-navigation-link",
|
||||
"title": "Post Navigation Link",
|
||||
"category": "theme",
|
||||
|
@ -72,6 +72,11 @@ function render_block_core_post_template( $attributes, $content, $block ) {
|
||||
$classnames .= ' has-link-color';
|
||||
}
|
||||
|
||||
// Ensure backwards compatibility by flagging the number of columns via classname when using grid layout.
|
||||
if ( isset( $attributes['layout']['type'] ) && 'grid' === $attributes['layout']['type'] && ! empty( $attributes['layout']['columnCount'] ) ) {
|
||||
$classnames .= ' ' . sanitize_title( 'columns-' . $attributes['layout']['columnCount'] );
|
||||
}
|
||||
|
||||
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classnames ) ) );
|
||||
|
||||
$content = '';
|
||||
@ -85,17 +90,18 @@ function render_block_core_post_template( $attributes, $content, $block ) {
|
||||
// This ensures that for the inner instances of the Post Template block, we do not render any block supports.
|
||||
$block_instance['blockName'] = 'core/null';
|
||||
|
||||
$post_id = get_the_ID();
|
||||
$post_type = get_post_type();
|
||||
$filter_block_context = static function( $context ) use ( $post_id, $post_type ) {
|
||||
$context['postType'] = $post_type;
|
||||
$context['postId'] = $post_id;
|
||||
return $context;
|
||||
};
|
||||
add_filter( 'render_block_context', $filter_block_context );
|
||||
// Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling
|
||||
// `render_callback` and ensure that no wrapper markup is included.
|
||||
$block_content = (
|
||||
new WP_Block(
|
||||
$block_instance,
|
||||
array(
|
||||
'postType' => get_post_type(),
|
||||
'postId' => get_the_ID(),
|
||||
)
|
||||
)
|
||||
)->render( array( 'dynamic' => false ) );
|
||||
$block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) );
|
||||
remove_filter( 'render_block_context', $filter_block_context );
|
||||
|
||||
// Wrap the render inner blocks in a `li` element with the appropriate post classes.
|
||||
$post_classes = implode( ' ', get_post_class( 'wp-block-post' ) );
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-template",
|
||||
"title": "Post Template",
|
||||
"category": "theme",
|
||||
@ -18,10 +18,8 @@
|
||||
"supports": {
|
||||
"reusable": false,
|
||||
"html": false,
|
||||
"align": true,
|
||||
"__experimentalLayout": {
|
||||
"allowEditing": false
|
||||
},
|
||||
"align": [ "wide", "full" ],
|
||||
"layout": true,
|
||||
"color": {
|
||||
"gradients": true,
|
||||
"link": true,
|
||||
@ -42,6 +40,14 @@
|
||||
"__experimentalDefaultControls": {
|
||||
"fontSize": true
|
||||
}
|
||||
},
|
||||
"spacing": {
|
||||
"blockGap": {
|
||||
"__experimentalDefault": "1.25em"
|
||||
},
|
||||
"__experimentalDefaultControls": {
|
||||
"blockGap": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"style": "wp-block-post-template",
|
||||
|
@ -64,8 +64,8 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
|
||||
function register_block_core_post_terms() {
|
||||
$taxonomies = get_taxonomies(
|
||||
array(
|
||||
'public' => true,
|
||||
'show_in_rest' => true,
|
||||
'publicly_queryable' => true,
|
||||
'show_in_rest' => true,
|
||||
),
|
||||
'objects'
|
||||
);
|
||||
@ -87,6 +87,7 @@ function register_block_core_post_terms() {
|
||||
'term' => $taxonomy->name,
|
||||
),
|
||||
'isActive' => array( 'term' ),
|
||||
'scope' => array( 'inserter', 'transform' ),
|
||||
);
|
||||
// Set the category variation as the default one.
|
||||
if ( 'category' === $taxonomy->name ) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-terms",
|
||||
"title": "Post Terms",
|
||||
"category": "theme",
|
||||
|
@ -19,8 +19,8 @@ function render_block_core_post_title( $attributes, $content, $block ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$post_ID = $block->context['postId'];
|
||||
$title = get_the_title();
|
||||
$post = get_post( $block->context['postId'] );
|
||||
$title = get_the_title( $post );
|
||||
|
||||
if ( ! $title ) {
|
||||
return '';
|
||||
@ -28,12 +28,12 @@ function render_block_core_post_title( $attributes, $content, $block ) {
|
||||
|
||||
$tag_name = 'h2';
|
||||
if ( isset( $attributes['level'] ) ) {
|
||||
$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level'];
|
||||
$tag_name = 'h' . $attributes['level'];
|
||||
}
|
||||
|
||||
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
|
||||
$rel = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
|
||||
$title = sprintf( '<a href="%1$s" target="%2$s" %3$s>%4$s</a>', get_the_permalink( $post_ID ), esc_attr( $attributes['linkTarget'] ), $rel, $title );
|
||||
$title = sprintf( '<a href="%1$s" target="%2$s" %3$s>%4$s</a>', get_the_permalink( $post ), esc_attr( $attributes['linkTarget'] ), $rel, $title );
|
||||
}
|
||||
|
||||
$classes = array();
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/post-title",
|
||||
"title": "Post Title",
|
||||
"title": "Title",
|
||||
"category": "theme",
|
||||
"description": "Displays the title of a post, page, or any other content-type.",
|
||||
"textdomain": "default",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 2,
|
||||
"apiVersion": 3,
|
||||
"name": "core/preformatted",
|
||||
"title": "Preformatted",
|
||||
"category": "text",
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user