-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlxrichtext.php
58 lines (54 loc) · 1.43 KB
/
dlxrichtext.php
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
57
58
<?php
/**
* Plugin Name: DLX RichText
* Plugin URI: https://dlxplugins.com/plugins/
* Description: Demonstrates how to convert RichText to InnerBlocks
* Version: 1.0.0
* Requires at least: 5.9
* Requires PHP: 7.2
* Author: DLX Plugins
* Author URI: https://dlxplugins.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: dlxrichtext
*
* @package DLXRichText
*/
namespace DLXPlugins\DLXRichText;
/**
* Register the block and set server-side remder.
*/
function register_block() {
register_block_type(
plugin_dir_path( __FILE__ ) . 'build/blocks/dlxrichtext/block.json',
array(
'render_callback' => __NAMESPACE__ . '\frontend_block_output',
)
);
}
add_action( 'init', __NAMESPACE__ . '\register_block' );
/**
* Output block to frontend.
*
* @param array $attributes Block attributes.
*/
function frontend_block_output( $attributes ) {
$richtext_content = $attributes['textContent'] ?? '';
return sprintf(
'<div class="dlxrichtext-frontend">%s</div>',
wp_kses_post( $richtext_content )
);
}
/**
* Enqueue block editor assets.
*/
function enqueue_block_editor_assets() {
wp_register_script(
'dlx-richtext-editor-script',
plugins_url( 'build/index.js', __FILE__ ),
array(),
'1.0.0',
true
);
}
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_block_editor_assets' );