From 38243f52e410d13abfc8629f0573768c078b3670 Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 17 Sep 2024 15:37:52 +0000 Subject: [PATCH] feat: parse `meta` attributes --- .changeset/spotty-files-own.md | 5 +++++ includes/Data/BlockAttributeResolver.php | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .changeset/spotty-files-own.md diff --git a/.changeset/spotty-files-own.md b/.changeset/spotty-files-own.md new file mode 100644 index 00000000..1b6aca83 --- /dev/null +++ b/.changeset/spotty-files-own.md @@ -0,0 +1,5 @@ +--- +"@wpengine/wp-graphql-content-blocks": minor +--- + +feat: add support for parsing (deprecated) `meta` attributes. diff --git a/includes/Data/BlockAttributeResolver.php b/includes/Data/BlockAttributeResolver.php index 241c78d9..b363b48e 100644 --- a/includes/Data/BlockAttributeResolver.php +++ b/includes/Data/BlockAttributeResolver.php @@ -47,6 +47,9 @@ public static function resolve_block_attribute( $attribute, string $html, $attri case 'query': $value = self::parse_query_source( $html, $attribute, $attribute_value ); break; + case 'meta': + $value = self::parse_meta_source( $attribute ); + break; } // Sanitize the value type. @@ -181,4 +184,23 @@ private static function parse_query_source( string $html, array $config, array $ return $results; } + + /** + * Parses a meta source block type. + * + * Note: Meta sources are considered deprecated but may still be used by legacy and third-party blocks. + * + * @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-attributes.md#meta-source-deprecated + * + * @param array $config The attribute configuration. + */ + private static function parse_meta_source( array $config ): ?string { + global $post_id; + + if ( empty( $post_id ) || empty( $config['meta'] ) ) { + return null; + } + + return get_post_meta( $post_id, $config, true ); + } }