-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextend-embed.php
More file actions
56 lines (43 loc) · 1.48 KB
/
Copy pathextend-embed.php
File metadata and controls
56 lines (43 loc) · 1.48 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Plugin Name: Embed Ext.
* Description: Extending embed block.
* Version: 0.1.0
* Requires at least: 6.5
*/
function enquee_embed_editor_assets () {
$asset_file = include plugin_dir_path(__FILE__) . '/build/index.asset.php';
wp_enqueue_script(
'extend-embed',
plugin_dir_url(__FILE__) . '/build/index.js',
$asset_file['dependencies'],
$asset_file['version']
);
}
add_action('enqueue_block_editor_assets', 'enquee_embed_editor_assets');
function addEmbedHeightAttribute( $args, $block_type ) {
// Only add the attribute to Image blocks.
if ( $block_type === 'core/embed' ) {
if ( ! isset( $args['attributes'] ) ) {
$args['attributes'] = array();
}
$args['attributes']['height'] = array(
'type' => 'number',
'default' => '100px',
);
}
return $args;
}
add_filter( 'register_block_type_args', 'addEmbedHeightAttribute', 10, 2 );
function addHeightToIframe ( $block_content, $block ){
$is_core_embed = $block['attrs']['height'] ?? false;
if($is_core_embed) {
$processor = new WP_HTML_Tag_Processor( $block_content );
if ($processor->next_tag('iframe')) {
$processor->set_attribute('style', 'height:'. $block['attrs']['height']);
}
return $processor->get_updated_html();
}
return $block_content;
}
add_filter( 'render_block_core/embed', 'addHeightToIframe', 10, 2 );