diff --git a/mu-plugins/blocks/global-header-footer/blocks.php b/mu-plugins/blocks/global-header-footer/blocks.php index dce23156d..fb85d0d5e 100644 --- a/mu-plugins/blocks/global-header-footer/blocks.php +++ b/mu-plugins/blocks/global-header-footer/blocks.php @@ -17,6 +17,7 @@ add_filter( 'style_loader_src', __NAMESPACE__ . '\update_google_fonts_url', 10, 2 ); add_filter( 'render_block_core/navigation-link', __NAMESPACE__ . '\swap_submenu_arrow_svg' ); add_filter( 'render_block_core/search', __NAMESPACE__ . '\swap_header_search_action', 10, 2 ); +add_filter( 'render_block_data', __NAMESPACE__ . '\update_block_style_colors' ); /** * Register block types @@ -370,13 +371,23 @@ function render_global_header( $attributes = array() ) { * * API requests also need `` etc so they can get the styles. */ + $head_markup = ''; if ( ! wp_is_block_theme() || $is_rest_request ) { ob_start(); require_once __DIR__ . '/classic-header.php'; - $markup = ob_get_clean() . $markup; + $head_markup = ob_get_clean(); } - return $markup; + $wrapper_attributes = get_block_wrapper_attributes( + array( 'class' => 'global-header wp-block-group' ) + ); + return sprintf( + '%1$s
%3$s
%4$s', + $head_markup, + $wrapper_attributes, + $markup, + wp_kses_post( render_header_alert_banner() ) + ); } /** @@ -784,11 +795,13 @@ function rest_render_global_footer( $request ) { /** * Render the global footer in a block context. * - * @param array $attributes The block attributes. + * @param array $attributes Block attributes. + * @param string $content Block default content. + * @param WP_Block $block Block instance. * - * @return string + * @return string Returns the block markup. */ -function render_global_footer( $attributes = array() ) { +function render_global_footer( $attributes, $content, $block ) { remove_inner_group_container(); if ( is_rosetta_site() ) { @@ -808,17 +821,52 @@ function render_global_footer( $attributes = array() ) { $is_rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST; // Render the classic markup second, so the `wp_footer()` call will execute callbacks that blocks added. + $footer_markup = ''; if ( ! wp_is_block_theme() || $is_rest_request ) { ob_start(); require_once __DIR__ . '/classic-footer.php'; - $markup .= ob_get_clean(); + $footer_markup = ob_get_clean(); } remove_filter( 'render_block_data', __NAMESPACE__ . '\localize_nav_links' ); - return $markup; + $wrapper_attributes = get_block_wrapper_attributes( + array( 'class' => 'global-footer wp-block-group' ) + ); + return sprintf( + '%3$s', + $wrapper_attributes, + $markup, + $footer_markup, + ); } +/** + * Convert the `style` attribute on the footer block to use color settings. + * + * @param array $block The parsed block data. + * + * @return array + */ +function update_block_style_colors( $block ) { + if ( + ! empty( $block['blockName'] ) && + in_array( $block['blockName'], [ 'wporg/global-footer', 'wporg/global-header' ], true ) && + ! empty( $block['attrs']['style'] ) + ) { + if ( 'black-on-white' === $block['attrs']['style'] ) { + $block['attrs']['textColor'] = 'charcoal-2'; + $block['attrs']['backgroundColor'] = 'white'; + } elseif ( 'white-on-blue' === $block['attrs']['style'] ) { + $block['attrs']['textColor'] = 'white'; + $block['attrs']['backgroundColor'] = 'blueberry-1'; + } + } + + return $block; +} + + /** * Localise a `core/navigation-link` block link to point to the Rosetta site resource. * @@ -1025,7 +1073,7 @@ function swap_header_search_action( $block_content, $block ) { return $block_content; } -/* +/** * Translate the tagline with the necessary text domain. */ function get_cip_text() { @@ -1038,28 +1086,3 @@ function get_cip_text() { return $translated; } - -/** - * Generate the classes based on the selected color scheme. - * - * This applies the expected color class using the format of Gutenberg's text - * and background styles, though the actual colors are applied via CSS custom - * properties in `_common.scss`. - */ -function get_container_classes( $color_scheme ) { - $classes = ' has-text-color has-background'; - switch ( $color_scheme ) { - case 'white-on-blue': - $classes .= ' has-white-color has-blueberry-1-background-color'; - break; - case 'black-on-white': - $classes .= ' has-charcoal-2-color has-white-background-color'; - break; - case 'white-on-black': - default: - $classes .= ' has-white-color has-charcoal-2-background-color'; - break; - } - - return $classes; -} diff --git a/mu-plugins/blocks/global-header-footer/footer.php b/mu-plugins/blocks/global-header-footer/footer.php index 76ae0eaf7..d63a2a382 100644 --- a/mu-plugins/blocks/global-header-footer/footer.php +++ b/mu-plugins/blocks/global-header-footer/footer.php @@ -13,115 +13,109 @@ * @var string $locale_title */ -$color_scheme = apply_filters( 'wporg_footer_color_scheme', $attributes['style'] ); +$container_class = 'global-footer'; -$container_class = 'global-footer ' . get_container_classes( $color_scheme ); - -$code_is_poetry_src = str_contains( $container_class, 'has-charcoal-2-color' ) ? +$code_is_poetry_src = isset( $attributes['textColor'] ) && str_contains( $attributes['textColor'], 'charcoal' ) ? plugins_url( '/images/code-is-poetry-for-light-bg.svg', __FILE__ ) : 'https://s.w.org/style/images/code-is-poetry-for-dark-bg.svg'; ?> - - - + + + + + + + + + + + + + + + + + + + diff --git a/mu-plugins/blocks/global-header-footer/header.php b/mu-plugins/blocks/global-header-footer/header.php index 89d1fdc99..3225a7d09 100644 --- a/mu-plugins/blocks/global-header-footer/header.php +++ b/mu-plugins/blocks/global-header-footer/header.php @@ -2,7 +2,7 @@ namespace WordPressdotorg\MU_Plugins\Global_Header_Footer\Header; -use function WordPressdotorg\MU_Plugins\Global_Header_Footer\{ get_home_url, get_download_url, get_container_classes, render_header_alert_banner }; +use function WordPressdotorg\MU_Plugins\Global_Header_Footer\{ get_home_url, get_download_url }; defined( 'WPINC' ) || die(); @@ -15,15 +15,6 @@ * @var string $show_search */ -$container_class = 'global-header'; -if ( ! empty( $locale_title ) ) { - $container_class .= ' global-header__has-locale-title'; -} - -$color_scheme = apply_filters( 'wporg_header_color_scheme', $attributes['style'] ); - -$container_class .= get_container_classes( $color_scheme ); - $search_args = array( 'label' => _x( 'Search', 'button label', 'wporg' ), 'placeholder' => _x( 'Search WP.org...', 'input field placeholder', 'wporg' ), @@ -73,55 +64,50 @@ function recursive_menu( $menu_item, $top_level = true ) { ?> - -
- -
- - - -
- - - - -

- -

- - - - - - - - - - - - - - - - -
- - - -
-
- - + +
+ + + +
+ + + + +

+ +

+ + + + + + + + + + + + + + + + +
+ + + +
diff --git a/mu-plugins/blocks/global-header-footer/postcss/_common.pcss b/mu-plugins/blocks/global-header-footer/postcss/_common.pcss index 8f32c379f..faa474227 100644 --- a/mu-plugins/blocks/global-header-footer/postcss/_common.pcss +++ b/mu-plugins/blocks/global-header-footer/postcss/_common.pcss @@ -81,10 +81,16 @@ html { --wp-global-header--text-color: var(--wp--preset--color--white); } +.has-charcoal-0-color, +.has-charcoal-1-color, .has-charcoal-2-color { --wp-global-header--link-color: var(--wp--preset--color--charcoal-2); --wp-global-header--link-color--active: var(--wp--preset--color--deep-blueberry); --wp-global-header--text-color: var(--wp--preset--color--charcoal-2); + + &.has-background[style*="background-color:"] { + --wp-global-header--background-color--hover: var(--wp--preset--color--light-grey-2); + } } .has-blueberry-1-background-color { diff --git a/mu-plugins/blocks/global-header-footer/postcss/header/header.pcss b/mu-plugins/blocks/global-header-footer/postcss/header/header.pcss index 5e4874f42..65b7ae9d7 100644 --- a/mu-plugins/blocks/global-header-footer/postcss/header/header.pcss +++ b/mu-plugins/blocks/global-header-footer/postcss/header/header.pcss @@ -16,6 +16,7 @@ html { font-size: 21px; height: var(--wp-global-header-height); padding: 0; + box-sizing: content-box; /* Don't include border in header height. */ /* * Some themes set a `z-index` on content elements that follow the header, like `#masthead` in diff --git a/mu-plugins/blocks/global-header-footer/postcss/header/menu.pcss b/mu-plugins/blocks/global-header-footer/postcss/header/menu.pcss index 454be3b51..36f96dd91 100644 --- a/mu-plugins/blocks/global-header-footer/postcss/header/menu.pcss +++ b/mu-plugins/blocks/global-header-footer/postcss/header/menu.pcss @@ -304,13 +304,6 @@ background: var(--wp-global-header--background-color--hover); } } - - & .wp-block-navigation__container { - - @media (--tablet) { - background: var(--wp-global-header--background-color); - } - } } /* Gutenberg bug: Close button is not visible in Safari; override it locally */ diff --git a/mu-plugins/blocks/global-header-footer/postcss/header/search.pcss b/mu-plugins/blocks/global-header-footer/postcss/header/search.pcss index d15ad8502..7e08fd404 100644 --- a/mu-plugins/blocks/global-header-footer/postcss/header/search.pcss +++ b/mu-plugins/blocks/global-header-footer/postcss/header/search.pcss @@ -146,10 +146,14 @@ } } -.wp-block-group.global-header.has-white-background-color .global-header__search .wp-block-search__inside-wrapper { - border: 2px solid var(--wp-global-header--text-color); -} +.wp-block-group.global-header.has-charcoal-0-color, +.wp-block-group.global-header.has-charcoal-1-color, +.wp-block-group.global-header.has-charcoal-2-color { + & .global-header__search .wp-block-search__inside-wrapper { + border: 2px solid var(--wp-global-header--text-color); + } -.wp-block-group.global-header.has-white-background-color .global-header__search .wp-block-navigation__responsive-container-open { - background-image: url(../images/search-for-light-bg.svg); + & .global-header__search .wp-block-navigation__responsive-container-open { + background-image: url(../images/search-for-light-bg.svg); + } } diff --git a/mu-plugins/blocks/global-header-footer/src/footer/block.json b/mu-plugins/blocks/global-header-footer/src/footer/block.json index a6a808560..8a11a6925 100644 --- a/mu-plugins/blocks/global-header-footer/src/footer/block.json +++ b/mu-plugins/blocks/global-header-footer/src/footer/block.json @@ -5,13 +5,28 @@ "title": "Global Footer", "category": "design", "description": "Global footer for all of WordPress.org", - "attributes": { - "style": { - "type": "string", - "default": "white-on-black", - "enum": [ "white-on-black", "black-on-white", "white-on-blue" ] + "supports": { + "color": { + "background": true, + "link": false, + "text": true + }, + "html": false, + "multiple": false, + "reusable": false, + "spacing": { + "margin": [ "top" ], + "padding": false, + "blockGap": false + }, + "__experimentalBorder": { + "color": true, + "radius": false, + "style": true, + "width": true } }, + "attributes": {}, "textdomain": "wporg", "style": "wporg-global-header-footer", "editorStyle": "wporg-global-header-footer", diff --git a/mu-plugins/blocks/global-header-footer/src/footer/index.js b/mu-plugins/blocks/global-header-footer/src/footer/index.js index a3627c4e4..67d298770 100644 --- a/mu-plugins/blocks/global-header-footer/src/footer/index.js +++ b/mu-plugins/blocks/global-header-footer/src/footer/index.js @@ -1,7 +1,6 @@ /** * WordPress dependencies */ -import { __, sprintf } from '@wordpress/i18n'; import { Disabled } from '@wordpress/components'; import { registerBlockType } from '@wordpress/blocks'; import ServerSideRender from '@wordpress/server-side-render'; @@ -12,29 +11,14 @@ import { useBlockProps } from '@wordpress/block-editor'; */ import metadata from './block.json'; -const variations = [ - { label: __( 'White on black (default)', 'wporg' ), value: 'white-on-black' }, - { label: __( 'Black on white', 'wporg' ), value: 'black-on-white' }, - { label: __( 'White on blue', 'wporg' ), value: 'white-on-blue' }, -]; - const Edit = ( { attributes } ) => (
- +
); registerBlockType( metadata.name, { edit: Edit, - - variations: variations.map( ( { value, label } ) => ( { - name: value, - /* translators: %s is the color scheme label. */ - title: sprintf( __( 'Global Footer: %s', 'wporg' ), label ), - isActive: ( blockAttributes, variationAttributes ) => blockAttributes.style === variationAttributes.style, - scope: [ 'transform' ], - attributes: { style: value }, - } ) ), } ); diff --git a/mu-plugins/blocks/global-header-footer/src/header/block.json b/mu-plugins/blocks/global-header-footer/src/header/block.json index b494a8c09..518997452 100644 --- a/mu-plugins/blocks/global-header-footer/src/header/block.json +++ b/mu-plugins/blocks/global-header-footer/src/header/block.json @@ -5,13 +5,28 @@ "title": "Global Header", "category": "design", "description": "Global header for all of WordPress.org", - "attributes": { - "style": { - "type": "string", - "default": "white-on-black", - "enum": [ "white-on-black", "black-on-white", "white-on-blue" ] + "supports": { + "color": { + "background": true, + "link": false, + "text": true + }, + "html": false, + "multiple": false, + "reusable": false, + "spacing": { + "margin": [ "top" ], + "padding": false, + "blockGap": false + }, + "__experimentalBorder": { + "color": true, + "radius": false, + "style": true, + "width": true } }, + "attributes": {}, "textdomain": "wporg", "style": "wporg-global-header-footer", "editorStyle": "wporg-global-header-footer", diff --git a/mu-plugins/blocks/global-header-footer/src/header/index.js b/mu-plugins/blocks/global-header-footer/src/header/index.js index 4cdcc1c63..67d298770 100644 --- a/mu-plugins/blocks/global-header-footer/src/header/index.js +++ b/mu-plugins/blocks/global-header-footer/src/header/index.js @@ -1,7 +1,6 @@ /** * WordPress dependencies */ -import { __, sprintf } from '@wordpress/i18n'; import { Disabled } from '@wordpress/components'; import { registerBlockType } from '@wordpress/blocks'; import ServerSideRender from '@wordpress/server-side-render'; @@ -12,29 +11,14 @@ import { useBlockProps } from '@wordpress/block-editor'; */ import metadata from './block.json'; -const variations = [ - { label: __( 'White on black (default)', 'wporg' ), value: 'white-on-black' }, - { label: __( 'Black on white', 'wporg' ), value: 'black-on-white' }, - { label: __( 'White on blue', 'wporg' ), value: 'white-on-blue' }, -]; - const Edit = ( { attributes } ) => (
- +
); registerBlockType( metadata.name, { edit: Edit, - - variations: variations.map( ( { value, label } ) => ( { - name: value, - /* translators: %s is the color scheme label. */ - title: sprintf( __( 'Global Header: %s', 'wporg' ), label ), - isActive: ( blockAttributes, variationAttributes ) => blockAttributes.style === variationAttributes.style, - scope: [ 'transform' ], - attributes: { style: value }, - } ) ), } );