Skip to content

Commit

Permalink
Port migration mechanism from old typography to new
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal authored and youknowriad committed Jun 7, 2021
1 parent 10fce76 commit 27e58b0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,35 @@ 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;
}


add_filter( 'block_type_metadata', 'wp_migrate_old_typography_shape' );

/**
* Helper function that constructs a WP_Query args array from
* a `Query` block properties.
Expand Down

0 comments on commit 27e58b0

Please sign in to comment.