wp_migrate_old_typography_shape

函数
wp_migrate_old_typography_shape ( $metadata )
参数
  • (array) $metadata Metadata for registering a block type.
    Required:
返回值
  • (array) Filtered metadata for registering a block type.
定义位置
相关方法
wp_render_typography_supportwp_get_computed_fluid_typography_valuewp_apply_typography_supportwp_register_typography_supportwp_get_typography_value_and_unit
引入
5.8.0
弃用
-

wp_migrate_old_typography_shape: 这个函数用来将旧的排版设置转换为WordPress 5.5及以后版本中使用的新格式。它是在将网站升级到最新版本的WordPress时使用的。

将在`supports.*`下声明的排版键转换为`supports.typography.*`。

当检测到使用旧格式的块时,显示一个`_doing_it_wrong()`通知。

function wp_migrate_old_typography_shape( $metadata ) {
	if ( ! isset( $metadata['supports'] ) ) {
		return $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 ) {
			_doing_it_wrong(
				'register_block_type_from_metadata()',
				sprintf(
					/* translators: 1: Block type, 2: Typography supports key, e.g: fontSize, lineHeight, etc. 3: block.json, 4: Old metadata key, 5: New metadata key. */
					__( 'Block "%1$s" is declaring %2$s support in %3$s file under %4$s. %2$s support is now declared under %5$s.' ),
					$metadata['name'],
					"<code>$typography_key</code>",
					'<code>block.json</code>',
					"<code>supports.$typography_key</code>",
					"<code>supports.typography.$typography_key</code>"
				),
				'5.8.0'
			);

			_wp_array_set( $metadata['supports'], array( 'typography', $typography_key ), $support_for_key );
			unset( $metadata['supports'][ $typography_key ] );
		}
	}

	return $metadata;
}

常见问题

FAQs
查看更多 >