Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions src/wp-includes/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@ function wp_register_typography_support( $block_type ) {
return;
}

$has_font_size_support = _wp_array_get( $block_type->supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $block_type->supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $block_type->supports, array( '__experimentalFontWeight' ), false );
$has_line_height_support = _wp_array_get( $block_type->supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $block_type->supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $block_type->supports, array( '__experimentalTextTransform' ), false );

$has_typography_support = $has_font_size_support
|| $has_font_weight_support
$typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
if ( ! $typography_supports ) {
return;
}

$has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
$has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
$has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );

$has_typography_support = $has_font_family_support
|| $has_font_size_support
|| $has_font_style_support
|| $has_font_weight_support
|| $has_line_height_support
|| $has_text_transform_support
|| $has_text_decoration_support;
|| $has_text_decoration_support
|| $has_text_transform_support;

if ( ! $block_type->attributes ) {
$block_type->attributes = array();
Expand Down Expand Up @@ -68,40 +75,41 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
return array();
}

$typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
if ( ! $typography_supports ) {
return array();
}

$skip_typography_serialization = _wp_array_get( $typography_supports, array( '__experimentalSkipSerialization' ), false );
if ( $skip_typography_serialization ) {
return array();
}

$attributes = array();
$classes = array();
$styles = array();

$has_font_family_support = _wp_array_get( $block_type->supports, array( '__experimentalFontFamily' ), false );
$has_font_style_support = _wp_array_get( $block_type->supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $block_type->supports, array( '__experimentalFontWeight' ), false );
$has_font_size_support = _wp_array_get( $block_type->supports, array( 'fontSize' ), false );
$has_line_height_support = _wp_array_get( $block_type->supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $block_type->supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $block_type->supports, array( '__experimentalTextTransform' ), false );

$skip_font_size_support_serialization = _wp_array_get( $block_type->supports, array( '__experimentalSkipFontSizeSerialization' ), false );

// Covers all typography features _except_ font size.
$skip_typography_serialization = _wp_array_get( $block_type->supports, array( '__experimentalSkipTypographySerialization' ), false );
$has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
$has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
$has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );

// Font Size.
if ( $has_font_size_support && ! $skip_font_size_support_serialization ) {
if ( $has_font_size_support ) {
$has_named_font_size = array_key_exists( 'fontSize', $block_attributes );
$has_custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] );

// Apply required class or style.
if ( $has_named_font_size ) {
$classes[] = sprintf( 'has-%s-font-size', $block_attributes['fontSize'] );
} elseif ( $has_custom_font_size ) {
$styles[] = sprintf( 'font-size: %s;', $block_attributes['style']['typography']['fontSize'] );
}
}

// Font Family.
if ( $has_font_family_support && ! $skip_typography_serialization ) {
if ( $has_font_family_support ) {
$has_font_family = isset( $block_attributes['style']['typography']['fontFamily'] );
// Apply required class and style.
if ( $has_font_family ) {
$font_family = $block_attributes['style']['typography']['fontFamily'];
if ( strpos( $font_family, 'var:preset|font-family' ) !== false ) {
Expand All @@ -115,44 +123,36 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
}
}

// Font style.
if ( $has_font_style_support && ! $skip_typography_serialization ) {
// Apply font style.
$font_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'fontStyle', 'font-style' );
if ( $has_font_style_support ) {
$font_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'fontStyle', 'font-style' );
if ( $font_style ) {
$styles[] = $font_style;
}
}

// Font weight.
if ( $has_font_weight_support && ! $skip_typography_serialization ) {
// Apply font weight.
$font_weight = wp_typography_get_css_variable_inline_style( $block_attributes, 'fontWeight', 'font-weight' );
if ( $has_font_weight_support ) {
$font_weight = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'fontWeight', 'font-weight' );
if ( $font_weight ) {
$styles[] = $font_weight;
}
}

// Line Height.
if ( $has_line_height_support && ! $skip_typography_serialization ) {
if ( $has_line_height_support ) {
$has_line_height = isset( $block_attributes['style']['typography']['lineHeight'] );
// Add the style (no classes for line-height).
if ( $has_line_height ) {
$styles[] = sprintf( 'line-height: %s;', $block_attributes['style']['typography']['lineHeight'] );
}
}

// Text Decoration.
if ( $has_text_decoration_support && ! $skip_typography_serialization ) {
$text_decoration_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'textDecoration', 'text-decoration' );
if ( $has_text_decoration_support ) {
$text_decoration_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'textDecoration', 'text-decoration' );
if ( $text_decoration_style ) {
$styles[] = $text_decoration_style;
}
}

// Text Transform.
if ( $has_text_transform_support && ! $skip_typography_serialization ) {
$text_transform_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'textTransform', 'text-transform' );
if ( $has_text_transform_support ) {
$text_transform_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'textTransform', 'text-transform' );
if ( $text_transform_style ) {
$styles[] = $text_transform_style;
}
Expand Down
26 changes: 26 additions & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,32 @@ function block_has_support( $block_type, $feature, $default = false ) {
return true === $block_support || is_array( $block_support );
}

function wp_migrate_old_typography_shape( $metadata ) {
$typography_keys = array(
'__experimentalFontFamily',
'__experimentalFontStyle',
'__experimentalFontWeight',
'__experimentalLetterSpacing',
'__experimentalTextDecoration',
'__experimentalTextTransform',
'fontSize',
'lineHeight',
);
foreach ( $typography_keys as $typography_key ) {
$support_for_key = _wp_array_get( $metadata['supports'], array( $typography_key ), null );
if ( null !== $support_for_key ) {
trigger_error(
/* translators: %1$s: Block type, %2$s: typography supports key e.g: fontSize, lineHeight etc... */
sprintf( __( 'Block %1$s is declaring %2$s support on block.json under supports.%2$s. %2$s support is now declared under supports.typography.%2$s.', 'gutenberg' ), $metadata['name'], $typography_key ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
gutenberg_experimental_set( $metadata['supports'], array( 'typography', $typography_key ), $support_for_key );
unset( $metadata['supports'][ $typography_key ] );
}
}
return $metadata;
}

/**
* Helper function that constructs a WP_Query args array from
* a `Query` block properties.
Expand Down
41 changes: 41 additions & 0 deletions src/wp-includes/blocks/post-author/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"apiVersion": 2,
"name": "core/post-author",
"title": "Post Author",
"category": "design",
"description": "Add the author of this post.",
"textdomain": "default",
"attributes": {
"textAlign": {
"type": "string"
},
"avatarSize": {
"type": "number",
"default": 48
},
"showAvatar": {
"type": "boolean",
"default": true
},
"showBio": {
"type": "boolean"
},
"byline": {
"type": "string"
}
},
"usesContext": [ "postType", "postId" ],
"supports": {
"html": false,
"typography": {
"fontSize": true,
"lineHeight": true
},
"color": {
"gradients": true,
"link": true
}
},
"editorStyle": "wp-block-post-author-editor",
"style": "wp-block-post-author"
}
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static function read_json_file( $file_path ) {

$json_decoding_error = json_last_error();
if ( JSON_ERROR_NONE !== $json_decoding_error ) {
error_log( 'Error when decoding file schema: ' . json_last_error_msg() );
trigger_error( "Error when decoding a theme.json schema at path $file_path " . json_last_error_msg() );
return $config;
}

Expand Down
6 changes: 5 additions & 1 deletion src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,11 @@ private static function compute_preset_classes( $settings, $selector ) {
foreach ( $values as $value ) {
foreach ( $preset['classes'] as $class ) {
$stylesheet .= self::to_ruleset(
self::append_to_selector( $selector, '.has-' . $value['slug'] . '-' . $class['class_suffix'] ),
// We don't want to use kebabCase here,
// see https://github.com/WordPress/gutenberg/issues/32347
// However, we need to make sure the generated class
// doesn't contain spaces.
self::append_to_selector( $selector, '.has-' . preg_replace( '/\s+/', '-', $value['slug'] ) . '-' . $class['class_suffix'] ),
array(
array(
'name' => $class['property_name'],
Expand Down
2 changes: 2 additions & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@
add_filter( 'widget_block_content', 'do_blocks', 9 );
add_filter( 'widget_block_content', 'do_shortcode', 11 );

add_filter( 'block_type_metadata', 'wp_migrate_old_typography_shape' );

add_filter( 'wp_get_custom_css', 'wp_replace_insecure_home_url' );

// RSS filters.
Expand Down