diff --git a/src/wp-includes/block-supports/typography.php b/src/wp-includes/block-supports/typography.php index a2ddb5be68e5b..c6e71662d0b64 100644 --- a/src/wp-includes/block-supports/typography.php +++ b/src/wp-includes/block-supports/typography.php @@ -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(); @@ -68,29 +75,32 @@ 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 ) { @@ -98,10 +108,8 @@ function wp_apply_typography_support( $block_type, $block_attributes ) { } } - // 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 ) { @@ -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; } diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 1e7113e1d2e2c..f210858e55943 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -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. diff --git a/src/wp-includes/blocks/post-author/block.json b/src/wp-includes/blocks/post-author/block.json new file mode 100644 index 0000000000000..13862e66042ea --- /dev/null +++ b/src/wp-includes/blocks/post-author/block.json @@ -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" +} diff --git a/src/wp-includes/class-wp-theme-json-resolver.php b/src/wp-includes/class-wp-theme-json-resolver.php index db0747bb842cb..332038b1f7cac 100644 --- a/src/wp-includes/class-wp-theme-json-resolver.php +++ b/src/wp-includes/class-wp-theme-json-resolver.php @@ -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; } diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 5580e39285df7..d13fef2249477 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -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'], diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 5b312b54f1825..b91135c151ea9 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -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.