Skip to content

Commit

Permalink
prep build 03/02
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Mar 2, 2024
2 parents b5bcded + 63acff0 commit 38d6e5b
Show file tree
Hide file tree
Showing 155 changed files with 4,013 additions and 2,604 deletions.
538 changes: 9 additions & 529 deletions changelog.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/contributors/versions-in-wordpress.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ If anything looks incorrect here, please bring it up in #core-editor in [WordPre

| Gutenberg Versions | WordPress Version |
| ------------------ | ----------------- |
| 16.8-17.7 | 6.5 |
| 16.2-16.7 | 6.4.3 |
| 16.2-16.7 | 6.4.2 |
| 16.2-16.7 | 6.4.1 |
Expand Down
16 changes: 15 additions & 1 deletion docs/reference-guides/theme-json-reference/theme-json-living.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ Setting that enables the following UI tools:

- background: backgroundImage, backgroundSize
- border: color, radius, style, width
- color: link
- color: link, heading, button, caption
- dimensions: aspectRatio, minHeight
- position: sticky
- spacing: blockGap, margin, padding
- typography: lineHeight
- shadow: defaultPresets


---
Expand Down Expand Up @@ -203,6 +204,19 @@ Generate custom CSS custom properties of the form `--wp--custom--{key}--{nested-
## Styles


### background

Background styles

| Property | Type | Props |
| --- | --- |--- |
| backgroundImage | string, object | |
| backgroundPosition | string, object | |
| backgroundRepeat | string, object | |
| backgroundSize | string, object | |

---

### border

Border styles.
Expand Down
53 changes: 25 additions & 28 deletions lib/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ function gutenberg_register_background_support( $block_type ) {
}
}

/**
* Given a theme.json or block background styles, returns the background styles for a block.
*
* @since 6.6.0
*
* @param array $background_styles Background style properties.
* @return array Style engine array of CSS string and style declarations.
*/
function gutenberg_get_background_support_styles( $background_styles = array() ) {
$background_image_source = isset( $background_styles['backgroundImage']['source'] ) ? $background_styles['backgroundImage']['source'] : null;
$background_styles['backgroundSize'] = ! empty( $background_styles['backgroundSize'] ) ? $background_styles['backgroundSize'] : 'cover';

if ( 'file' === $background_image_source && ! empty( $background_styles['backgroundImage']['url'] ) ) {
// If the background size is set to `contain` and no position is set, set the position to `center`.
if ( 'contain' === $background_styles['backgroundSize'] && ! isset( $background_styles['backgroundPosition'] ) ) {
$background_styles['backgroundPosition'] = 'center';
}
}

return gutenberg_style_engine_get_styles( array( 'background' => $background_styles ) );
}

/**
* Renders the background styles to the block wrapper.
* This block support uses the `render_block` hook to ensure that
Expand All @@ -46,38 +68,13 @@ function gutenberg_render_background_support( $block_content, $block ) {

if (
! $has_background_image_support ||
wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundImage' )
wp_should_skip_block_supports_serialization( $block_type, 'background', 'backgroundImage' ) ||
! isset( $block_attributes['style']['background'] )
) {
return $block_content;
}

$background_image_source = $block_attributes['style']['background']['backgroundImage']['source'] ?? null;
$background_image_url = $block_attributes['style']['background']['backgroundImage']['url'] ?? null;
$background_size = $block_attributes['style']['background']['backgroundSize'] ?? 'cover';
$background_position = $block_attributes['style']['background']['backgroundPosition'] ?? null;
$background_repeat = $block_attributes['style']['background']['backgroundRepeat'] ?? null;

$background_block_styles = array();

if (
'file' === $background_image_source &&
$background_image_url
) {
// Set file based background URL.
// TODO: In a follow-up, similar logic could be added to inject a featured image url.
$background_block_styles['backgroundImage']['url'] = $background_image_url;
// Only output the background size and repeat when an image url is set.
$background_block_styles['backgroundSize'] = $background_size;
$background_block_styles['backgroundRepeat'] = $background_repeat;
$background_block_styles['backgroundPosition'] = $background_position;

// If the background size is set to `contain` and no position is set, set the position to `center`.
if ( 'contain' === $background_size && ! isset( $background_position ) ) {
$background_block_styles['backgroundPosition'] = 'center';
}
}

$styles = gutenberg_style_engine_get_styles( array( 'background' => $background_block_styles ) );
$styles = gutenberg_get_background_support_styles( $block_attributes['style']['background'] );

if ( ! empty( $styles['css'] ) ) {
// Inject background styles to the first element, presuming it's the wrapper, if it exists.
Expand Down
18 changes: 9 additions & 9 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
'declarations' => $child_layout_declarations,
);

/**
/*
* If columnSpan is set, and the parent grid is responsive, i.e. if it has a minimumColumnWidth set,
* the columnSpan should be removed on small grids. If there's a minimumColumnWidth, the grid is responsive.
* But if the minimumColumnWidth value wasn't changed, it won't be set. In that case, if columnCount doesn't
Expand All @@ -606,7 +606,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$parent_column_value = floatval( $parent_column_width );
$parent_column_unit = explode( $parent_column_value, $parent_column_width );

/**
/*
* If there is no unit, the width has somehow been mangled so we reset both unit and value
* to defaults.
* Additionally, the unit should be one of px, rem or em, so that also needs to be checked.
Expand All @@ -622,7 +622,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
}
}

/**
/*
* A default gap value is used for this computation because custom gap values may not be
* viable to use in the computation of the container query value.
*/
Expand All @@ -639,7 +639,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
);
}

/**
/*
* Add to the style engine store to enqueue and render layout styles.
* Return styles here just to check if any exist.
*/
Expand Down Expand Up @@ -800,7 +800,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
}
}

/**
/*
* Attempts to refer to the inner-block wrapping element by its class attribute.
*
* When examining a block's inner content, if a block has inner blocks, then
Expand Down Expand Up @@ -890,13 +890,13 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
return $processor->get_updated_html();
}

/**
/*
* Add a `render_block_data` filter to fetch the parent block layout data.
*/
add_filter(
'render_block_data',
function ( $parsed_block, $source_block, $parent_block ) {
/**
/*
* Check if the parent block exists and if it has a layout attribute.
* If it does, add the parent layout to the parsed block.
*/
Expand Down Expand Up @@ -945,7 +945,7 @@ function gutenberg_restore_group_inner_container( $block_content, $block ) {
return $block_content;
}

/**
/*
* This filter runs after the layout classnames have been added to the block, so they
* have to be removed from the outer wrapper and then added to the inner.
*/
Expand All @@ -961,7 +961,7 @@ function gutenberg_restore_group_inner_container( $block_content, $block ) {
}
}
} else {
/**
/*
* The class_list method was only added in 6.4 so this needs a temporary fallback.
* This fallback should be removed when the minimum supported version is 6.4.
*/
Expand Down
19 changes: 18 additions & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,18 @@ class WP_Theme_JSON_Gutenberg {
* removed the `--wp--style--block-gap` property.
* @since 6.2.0 Added `outline-*`, and `min-height` properties.
* @since 6.3.0 Added `writing-mode` property.
* @since 6.6.0 Added `background-[image|position|repeat|size]` properties.
*
* @var array
*/
const PROPERTIES_METADATA = array(
'aspect-ratio' => array( 'dimensions', 'aspectRatio' ),
'background' => array( 'color', 'gradient' ),
'background-color' => array( 'color', 'background' ),
'background-image' => array( 'background', 'backgroundImage' ),
'background-position' => array( 'background', 'backgroundPosition' ),
'background-repeat' => array( 'background', 'backgroundRepeat' ),
'background-size' => array( 'background', 'backgroundSize' ),
'border-radius' => array( 'border', 'radius' ),
'border-top-left-radius' => array( 'border', 'radius', 'topLeft' ),
'border-top-right-radius' => array( 'border', 'radius', 'topRight' ),
Expand Down Expand Up @@ -461,10 +466,17 @@ class WP_Theme_JSON_Gutenberg {
* added new property `shadow`,
* updated `blockGap` to be allowed at any level.
* @since 6.2.0 Added `outline`, and `minHeight` properties.
* @since 6.6.0 Added `background` sub properties to top-level only.
*
* @var array
*/
const VALID_STYLES = array(
'background' => array(
'backgroundImage' => 'top',
'backgroundPosition' => 'top',
'backgroundRepeat' => 'top',
'backgroundSize' => 'top',
),
'border' => array(
'color' => null,
'radius' => null,
Expand Down Expand Up @@ -1334,7 +1346,6 @@ public function get_block_custom_css_nodes() {
return $block_nodes;
}


/**
* Returns the global styles custom CSS for a single block.
*
Expand Down Expand Up @@ -2120,6 +2131,12 @@ protected static function compute_style_properties( $styles, $settings = array()
}
}

// Processes background styles.
if ( 'background' === $value_path[0] && isset( $styles['background'] ) ) {
$background_styles = gutenberg_get_background_support_styles( $styles['background'] );
$value = $background_styles['declarations'][ $css_property ] ?? $value;
}

// Skip if empty and not "0" or value represents array of longhand values.
$has_missing_value = empty( $value ) && ! is_numeric( $value );
if ( $has_missing_value || is_array( $value ) ) {
Expand Down
25 changes: 22 additions & 3 deletions lib/compat/wordpress-6.5/block-bindings/pattern-overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,30 @@
* @return mixed The value computed for the source.
*/
function gutenberg_block_bindings_pattern_overrides_callback( $source_attrs, $block_instance, $attribute_name ) {
if ( empty( $block_instance->attributes['metadata']['id'] ) ) {
if ( ! isset( $block_instance->context['pattern/overrides'] ) ) {
return null;
}
$block_id = $block_instance->attributes['metadata']['id'];
return _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id, 'values', $attribute_name ), null );

$override_content = $block_instance->context['pattern/overrides'];

// Back compat. Pattern overrides previously used a metadata `id` instead of `name`.
// We check first for the name, and if it exists, use that value.
if ( isset( $block_instance->attributes['metadata']['name'] ) ) {
$metadata_name = $block_instance->attributes['metadata']['name'];
if ( array_key_exists( $metadata_name, $override_content ) ) {
return _wp_array_get( $override_content, array( $metadata_name, $attribute_name ), null );
}
}

// Next check for the `id`.
if ( isset( $block_instance->attributes['metadata']['id'] ) ) {
$metadata_id = $block_instance->attributes['metadata']['id'];
if ( array_key_exists( $metadata_id, $override_content ) ) {
return _wp_array_get( $override_content, array( $metadata_id, $attribute_name ), null );
}
}

return null;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions lib/compat/wordpress-6.5/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ function array_is_list( $arr ) {
return true;
}
}

/**
* Sets a global JS variable used to flag whether to direct the Site Logo block's admin urls
* to the Customizer. This allows Gutenberg running on versions of WordPress < 6.5.0 to
* support the previous location for the Site Icon settings. This function should not be
* backported to core, and should be removed when the required WP core version for Gutenberg
* is >= 6.5.0.
*/
function gutenberg_add_use_customizer_site_logo_url_flag() {
if ( ! is_wp_version_compatible( '6.5' ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalUseCustomizerSiteLogoUrl = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_add_use_customizer_site_logo_url_flag' );
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,21 @@ protected function sanitize_src( $value ) {
*/
protected function handle_font_file_upload( $file ) {
add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );
add_filter( 'upload_dir', 'wp_get_font_dir' );

/*
* Set the upload directory to the fonts directory.
*
* wp_get_font_dir() contains the 'font_dir' hook, whose callbacks are
* likely to call wp_get_upload_dir().
*
* To avoid an infinite loop, don't hook wp_get_font_dir() to 'upload_dir'.
* Instead, just pass its return value to the 'upload_dir' callback.
*/
$font_dir = wp_get_font_dir();
$set_upload_dir = function () use ( $font_dir ) {
return $font_dir;
};
add_filter( 'upload_dir', $set_upload_dir );

$overrides = array(
'upload_error_handler' => array( $this, 'handle_font_file_upload_error' ),
Expand All @@ -875,8 +889,7 @@ protected function handle_font_file_upload( $file ) {
);

$uploaded_file = wp_handle_upload( $file, $overrides );

remove_filter( 'upload_dir', 'wp_get_font_dir' );
remove_filter( 'upload_dir', $set_upload_dir );
remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );

return $uploaded_file;
Expand Down
27 changes: 9 additions & 18 deletions lib/compat/wordpress-6.5/fonts/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,6 @@ function gutenberg_register_font_collections() {
*
* @since 6.5.0
*
* @param array $defaults {
* Array of information about the upload directory.
*
* @type string $path Base directory and subdirectory or full path to the fonts upload directory.
* @type string $url Base URL and subdirectory or absolute URL to the fonts upload directory.
* @type string $subdir Subdirectory
* @type string $basedir Path without subdir.
* @type string $baseurl URL path without subdir.
* @type string|false $error False or error message.
* }
* @return array $defaults {
* Array of information about the upload directory.
*
Expand All @@ -222,19 +212,20 @@ function gutenberg_register_font_collections() {
* @type string|false $error False or error message.
* }
*/
function wp_get_font_dir( $defaults = array() ) {
function wp_get_font_dir() {
$site_path = '';
if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) {
$site_path = '/sites/' . get_current_blog_id();
}

// Sets the defaults.
$defaults['path'] = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path;
$defaults['url'] = untrailingslashit( content_url( 'fonts' ) ) . $site_path;
$defaults['subdir'] = '';
$defaults['basedir'] = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path;
$defaults['baseurl'] = untrailingslashit( content_url( 'fonts' ) ) . $site_path;
$defaults['error'] = false;
$defaults = array(
'path' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
'url' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
'subdir' => '',
'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
'baseurl' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
'error' => false,
);

/**
* Filters the fonts directory data.
Expand Down
Loading

0 comments on commit 38d6e5b

Please sign in to comment.