-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathmeta.php
More file actions
33 lines (31 loc) · 876 Bytes
/
meta.php
File metadata and controls
33 lines (31 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
* Meta Custom Source
*
* @package gutenberg
*/
return array(
'name' => 'meta',
'apply_source' => function ( $block_content, $block_instance, $meta_field, $attribute_config ) {
$meta_value = get_post_meta( $block_instance->context['postId'], $meta_field, true );
$p = new WP_HTML_Tag_Processor( $block_content );
$found = $p->next_tag(
array(
// TODO: build the query from CSS selector.
'tag_name' => $attribute_config['selector'],
)
);
if ( ! $found ) {
return $block_content;
}
$tag_name = $p->get_tag();
$markup = "<$tag_name>$meta_value</$tag_name>";
$p2 = new WP_HTML_Tag_Processor( $markup );
$p2->next_tag();
$names = $p->get_attribute_names_with_prefix( '' );
foreach ( $names as $name ) {
$p2->set_attribute( $name, $p->get_attribute( $name ) );
}
return $p2 . '';
},
);