diff --git a/lib/compat/wordpress-6.5/blocks.php b/lib/compat/wordpress-6.5/blocks.php index d8c24b3772125..dbcdc433788ab 100644 --- a/lib/compat/wordpress-6.5/blocks.php +++ b/lib/compat/wordpress-6.5/blocks.php @@ -57,7 +57,7 @@ function gutenberg_register_metadata_attribute( $args ) { */ function gutenberg_block_bindings_replace_html( $block_content, $block_name, string $attribute_name, $source_value ) { $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name ); - if ( ! isset( $block_type->attributes[ $attribute_name ] ) ) { + if ( ! isset( $block_type->attributes[ $attribute_name ]['source'] ) ) { return $block_content; } @@ -160,7 +160,7 @@ function gutenberg_process_block_bindings( $block_content, $parsed_block, $block $supported_block_attrs = array( 'core/paragraph' => array( 'content' ), 'core/heading' => array( 'content' ), - 'core/image' => array( 'url', 'title', 'alt' ), + 'core/image' => array( 'id', 'url', 'title', 'alt' ), 'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), ); diff --git a/packages/block-library/src/avatar/index.php b/packages/block-library/src/avatar/index.php index d404fb81ca357..303b35458eb1a 100644 --- a/packages/block-library/src/avatar/index.php +++ b/packages/block-library/src/avatar/index.php @@ -31,7 +31,18 @@ function render_block_core_avatar( $attributes, $content, $block ) { : ''; if ( ! isset( $block->context['commentId'] ) ) { - $author_id = isset( $attributes['userId'] ) ? $attributes['userId'] : get_post_field( 'post_author', $block->context['postId'] ); + if ( isset( $attributes['userId'] ) ) { + $author_id = $attributes['userId']; + } elseif ( isset( $block->context['postId'] ) ) { + $author_id = get_post_field( 'post_author', $block->context['postId'] ); + } else { + $author_id = get_query_var( 'author' ); + } + + if ( empty( $author_id ) ) { + return ''; + } + $author_name = get_the_author_meta( 'display_name', $author_id ); // translators: %s is the Author name. $alt = sprintf( __( '%s Avatar' ), $author_name ); diff --git a/packages/block-library/src/gallery/edit.js b/packages/block-library/src/gallery/edit.js index 226e4da673d95..0a9dd631dfe52 100644 --- a/packages/block-library/src/gallery/edit.js +++ b/packages/block-library/src/gallery/edit.js @@ -73,6 +73,7 @@ const MOBILE_CONTROL_PROPS_RANGE_CONTROL = Platform.isNative ? { type: 'stepper' } : {}; +const DEFAULT_BLOCK = { name: 'core/image' }; const EMPTY_ARRAY = []; function GalleryEdit( props ) { @@ -496,6 +497,8 @@ function GalleryEdit( props ) { }; const innerBlocksProps = useInnerBlocksProps( blockProps, { + defaultBlock: DEFAULT_BLOCK, + directInsert: true, orientation: 'horizontal', renderAppender: false, ...nativeInnerBlockProps, diff --git a/packages/block-library/src/navigation/constants.js b/packages/block-library/src/navigation/constants.js index ff13309d1e4e7..154c490e83839 100644 --- a/packages/block-library/src/navigation/constants.js +++ b/packages/block-library/src/navigation/constants.js @@ -23,5 +23,3 @@ export const SELECT_NAVIGATION_MENUS_ARGS = [ 'wp_navigation', PRELOADED_NAVIGATION_MENUS_QUERY, ]; - -export const NAVIGATION_MOBILE_COLLAPSE = '600px'; diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 14ef6fc73d48f..3cacd814119e6 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -42,7 +42,7 @@ import { import { __, sprintf } from '@wordpress/i18n'; import { speak } from '@wordpress/a11y'; import { close, Icon } from '@wordpress/icons'; -import { useInstanceId, useMediaQuery } from '@wordpress/compose'; +import { useInstanceId } from '@wordpress/compose'; /** * Internal dependencies @@ -71,7 +71,6 @@ import MenuInspectorControls from './menu-inspector-controls'; import DeletedNavigationWarning from './deleted-navigation-warning'; import AccessibleDescription from './accessible-description'; import AccessibleMenuDescription from './accessible-menu-description'; -import { NAVIGATION_MOBILE_COLLAPSE } from '../constants'; import { unlock } from '../../lock-unlock'; function Navigation( { @@ -298,14 +297,6 @@ function Navigation( { [ clientId ] ); const isResponsive = 'never' !== overlayMenu; - const isMobileBreakPoint = useMediaQuery( - `(max-width: ${ NAVIGATION_MOBILE_COLLAPSE })` - ); - - const isCollapsed = - ( 'mobile' === overlayMenu && isMobileBreakPoint ) || - 'always' === overlayMenu; - const blockProps = useBlockProps( { ref: navRef, className: classnames( @@ -319,7 +310,6 @@ function Navigation( { 'is-vertical': orientation === 'vertical', 'no-wrap': flexWrap === 'nowrap', 'is-responsive': isResponsive, - 'is-collapsed': isCollapsed, 'has-text-color': !! textColor.color || !! textColor?.class, [ getColorClassName( 'color', textColor?.slug ) ]: !! textColor?.slug, diff --git a/packages/block-library/src/navigation/editor.scss b/packages/block-library/src/navigation/editor.scss index eb796ae696541..107fb6e6de5fd 100644 --- a/packages/block-library/src/navigation/editor.scss +++ b/packages/block-library/src/navigation/editor.scss @@ -429,7 +429,7 @@ $color-control-label-height: 20px; // These needs extra specificity in the editor. .wp-block-navigation__responsive-container:not(.is-menu-open) { .components-button.wp-block-navigation__responsive-container-close { - .is-collapsed & { + @include break-small { display: none; } } diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index f1292e5d2e723..5dcada62f6feb 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -218,7 +218,7 @@ private static function get_inner_blocks_from_navigation_post( $attributes ) { // it encounters whitespace. This code strips it. $blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks ); - if ( function_exists( 'get_hooked_block_markup' ) ) { + if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) ) { // Run Block Hooks algorithm to inject hooked blocks. $markup = block_core_navigation_insert_hooked_blocks( $blocks, $navigation_post ); $root_nav_block = parse_blocks( $markup )[0]; @@ -390,25 +390,16 @@ private static function get_classes( $attributes ) { $text_decoration = $attributes['style']['typography']['textDecoration'] ?? null; $text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration ); - // Sets the is-collapsed class when the navigation is set to always use the overlay. - // This saves us from needing to do this check in the view.js file (see the collapseNav function). - $is_collapsed_class = static::is_always_overlay( $attributes ) ? array( 'is-collapsed' ) : array(); - $classes = array_merge( $colors['css_classes'], $font_sizes['css_classes'], $is_responsive_menu ? array( 'is-responsive' ) : array(), $layout_class ? array( $layout_class ) : array(), - $text_decoration ? array( $text_decoration_class ) : array(), - $is_collapsed_class + $text_decoration ? array( $text_decoration_class ) : array() ); return implode( ' ', $classes ); } - private static function is_always_overlay( $attributes ) { - return isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu']; - } - /** * Get styles for the navigation block. * @@ -435,12 +426,16 @@ private static function get_responsive_container_markup( $attributes, $inner_blo $colors = block_core_navigation_build_css_colors( $attributes ); $modal_unique_id = wp_unique_id( 'modal-' ); + $is_hidden_by_default = isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu']; + $responsive_container_classes = array( 'wp-block-navigation__responsive-container', + $is_hidden_by_default ? 'hidden-by-default' : '', implode( ' ', $colors['overlay_css_classes'] ), ); $open_button_classes = array( 'wp-block-navigation__responsive-container-open', + $is_hidden_by_default ? 'always-shown' : '', ); $should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon']; @@ -538,7 +533,7 @@ private static function get_nav_wrapper_attributes( $attributes, $inner_blocks ) ); if ( $is_responsive_menu ) { - $nav_element_directives = static::get_nav_element_directives( $is_interactive, $attributes ); + $nav_element_directives = static::get_nav_element_directives( $is_interactive ); $wrapper_attributes .= ' ' . $nav_element_directives; } @@ -552,7 +547,7 @@ private static function get_nav_wrapper_attributes( $attributes, $inner_blocks ) * @param array $attributes The block attributes. * @return string the directives for the navigation element. */ - private static function get_nav_element_directives( $is_interactive, $attributes ) { + private static function get_nav_element_directives( $is_interactive ) { if ( ! $is_interactive ) { return ''; } @@ -569,16 +564,6 @@ private static function get_nav_element_directives( $is_interactive, $attributes data-wp-interactive="core/navigation"' . $nav_element_context; - /* - * When the navigation's 'overlayMenu' attribute is set to 'always', JavaScript - * is not needed for collapsing the menu because the class is set manually. - */ - if ( ! static::is_always_overlay( $attributes ) ) { - $nav_element_directives .= 'data-wp-init="callbacks.initNav"'; - $nav_element_directives .= ' '; // space separator - $nav_element_directives .= 'data-wp-class--is-collapsed="context.isCollapsed"'; - } - return $nav_element_directives; } @@ -1024,7 +1009,7 @@ function block_core_navigation_get_fallback_blocks() { // In this case default to the (Page List) fallback. $fallback_blocks = ! empty( $maybe_fallback ) ? $maybe_fallback : $fallback_blocks; - if ( function_exists( 'get_hooked_block_markup' ) ) { + if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) ) { // Run Block Hooks algorithm to inject hooked blocks. // We have to run it here because we need the post ID of the Navigation block to track ignored hooked blocks. $markup = block_core_navigation_insert_hooked_blocks( $fallback_blocks, $navigation_post ); @@ -1369,25 +1354,28 @@ function block_core_navigation_get_most_recently_published_navigation() { } /** - * Insert hooked blocks into a Navigation block. - * - * Given a Navigation block's inner blocks and its corresponding `wp_navigation` post object, - * this function inserts hooked blocks into it, and returns the serialized inner blocks in a - * mock Navigation block wrapper. + * Accepts the serialized markup of a block and its inner blocks, and returns serialized markup of the inner blocks. * - * If there are any hooked blocks that need to be inserted as the Navigation block's first or last - * children, the `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is checked to see if any - * of those hooked blocks should be exempted from insertion. + * @param string $serialized_block The serialized markup of a block and its inner blocks. + * @return string + */ +function block_core_navigation_remove_serialized_parent_block( $serialized_block ) { + $start = strpos( $serialized_block, '-->' ) + strlen( '-->' ); + $end = strrpos( $serialized_block, '' ) + strlen( '-->' ); - $end = strrpos( $content, ' +
+`, + status: 'publish', + } ); + + await admin.createNewPost(); + + await editor.insertBlock( { + name: 'core/block', + attributes: { ref: id }, + } ); + + const imageBlock = editor.canvas.getByRole( 'document', { + name: 'Block: Image', + } ); + await editor.selectBlocks( imageBlock ); + await imageBlock + .getByTestId( 'form-file-upload-input' ) + .setInputFiles( TEST_IMAGE_FILE_PATH ); + await expect( imageBlock.getByRole( 'img' ) ).toHaveCount( 1 ); + await expect( imageBlock.getByRole( 'img' ) ).toHaveAttribute( + 'src', + /\/wp-content\/uploads\// + ); + + await editor.publishPost(); + await page.reload(); + + await editor.selectBlocks( imageBlock ); + await editor.showBlockToolbar(); + const blockToolbar = page.getByRole( 'toolbar', { + name: 'Block tools', + } ); + await expect( imageBlock.getByRole( 'img' ) ).toHaveAttribute( + 'src', + /\/wp-content\/uploads\// + ); + await expect( + blockToolbar.getByRole( 'button', { name: 'Replace' } ) + ).toBeEnabled(); + await expect( + blockToolbar.getByRole( 'button', { + name: 'Upload to Media Library', + } ) + ).toBeHidden(); + } ); } );