-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
55 lines (45 loc) · 1.89 KB
/
index.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
<?php
/*
Plugin Name: Fledged Code Editor
Version: 1.0
Author: Alex Tirim
*/
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class FledgedCodeEditor {
function __construct() {
add_action('init', array($this, 'onInit'));
}
function onInit() {
wp_register_script('code-editor-js', plugin_dir_url(__FILE__) . 'build/index.js', array('wp-blocks', 'wp-element', 'wp-editor'));
wp_register_style('code-editor-css', plugin_dir_url(__FILE__) . 'build/index.css');
wp_register_style('code-editor-custom-css', plugin_dir_url(__FILE__) . 'code-editor.css');
register_block_type('makeupnamespace/make-up-block-name', array(
'render_callback' => array($this, 'renderCallback'),
'editor_script' => 'code-editor-js',
'editor_style' => ['code-editor-css', 'code-editor-custom-css'],
));
}
function renderCallback($attributes) {
if (!is_admin()) {
wp_enqueue_script('code-editor-frontend-js', plugin_dir_url(__FILE__) . 'build/frontend.js', array('wp-element'));
wp_enqueue_style('code-editor-frontend-css', plugin_dir_url(__FILE__) . 'build/index.css');
wp_enqueue_style('code-editor-custom-css', plugin_dir_url(__FILE__) . 'code-editor.css');
}
// map through the attributes[files] and htmlspecialchars the value
$attributes['files'] = array_map(function($file) {
// convert double quotes to single quotes
$file['code'] = str_replace('"', "'", $file['code']);
$file['code'] = htmlspecialchars($file['code']);
return $file;
}, $attributes['files']);
ob_start(); ?>
<div class="code-editor-attributes fully-fledged-code-editor"><pre style="display: none;"><?php echo json_encode($attributes) ?></pre></div>
<?php
$var = ob_get_clean();
return $var;
}
function renderCallbackBasic($attributes) {
return '<div>HGelloo</div>';
}
}
$code_editor = new FledgedCodeEditor();