Skip to content

Commit

Permalink
feat: parse meta attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine committed Sep 17, 2024
1 parent 518af63 commit 38243f5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-files-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": minor
---

feat: add support for parsing (deprecated) `meta` attributes.
22 changes: 22 additions & 0 deletions includes/Data/BlockAttributeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<string,mixed> $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 );

Check failure on line 204 in includes/Data/BlockAttributeResolver.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #2 $key of function get_post_meta expects string, array<string, mixed> given.
}
}

0 comments on commit 38243f5

Please sign in to comment.