-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-monaco-editor.php
executable file
·120 lines (102 loc) · 3.66 KB
/
wp-monaco-editor.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* WP Monaco Editor
*
* @package Cady/Plugins/WP_Monaco_Editor
*
* @since 1.0.0
*
* Plugin Name: WP Monaco Editor
* Plugin URI: https://github.com:CadyIO/wp-monaco-editor
* Description: Monaco Editor integration for WordPress
* Author: Cady
* Author URI: https://cady.io
* Version: 1.0.0
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Tested up to: 4.8
* Text Domain: wp-monaco-editor
* Domain Path: /languages
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Current version of the plugin.
*
* @since 1.0.0
*/
define( 'WP_MONACO_EDITOR_VERSION', '1.0.0' );
/**
* The base name of the plugin.
*
* @since 1.0.0
*/
define( 'WP_MONACO_EDITOR_PLUGIN_BASE_NAME', plugin_basename( __FILE__ ) );
/**
* The base URL of the plugin.
*
* @since 1.0.0
*/
define( 'WP_MONACO_EDITOR_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
/**
* The base directory path of the plugin.
*
* @since 1.0.0
*/
define( 'WP_MONACO_EDITOR_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
/**
* Load the text domain.
*
* @since 1.0.0
*/
add_action( 'plugins_loaded', function() {
load_plugin_textdomain( 'wp-monaco-editor', false, WP_MONACO_EDITOR_PLUGIN_DIR_PATH . '/languages/' );
} );
if ( ! function_exists( 'wp_monaco_editor_enqueue_admin_scripts' ) ) {
/**
* Enqueue scripts for admin.
*
* @since 1.0.0
*
* @param string $hook_suffix The assigned hook for the plugin.
*/
function wp_monaco_editor_enqueue_admin_scripts( $hook_suffix ) {
// Only load scripts on Post Edit page.
if ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) {
// Styles.
wp_enqueue_style( 'wp-monaco-editor-css', WP_MONACO_EDITOR_PLUGIN_DIR_URL . 'assets/css/wp-monaco-editor.css', array(), WP_MONACO_EDITOR_VERSION );
// Scripts.
wp_enqueue_script( 'monaco-editor', WP_MONACO_EDITOR_PLUGIN_DIR_URL . 'assets/vendor/monaco/min/vs/loader.js', array( 'jquery' ), WP_MONACO_EDITOR_VERSION, true );
wp_enqueue_script( 'wp-monaco-post-editor-js', WP_MONACO_EDITOR_PLUGIN_DIR_URL . 'assets/js/wp-monaco-post-editor.js', array( 'monaco-editor' ), WP_MONACO_EDITOR_VERSION, true );
}
// Only load scripts on Plugin editor page.
if ( 'plugin-editor.php' === $hook_suffix || 'theme-editor.php' === $hook_suffix ) {
// Styles.
wp_enqueue_style( 'wp-monaco-editor-css', WP_MONACO_EDITOR_PLUGIN_DIR_URL . 'assets/css/wp-monaco-editor.css', array(), WP_MONACO_EDITOR_VERSION );
// Scripts.
wp_enqueue_script( 'monaco-editor', WP_MONACO_EDITOR_PLUGIN_DIR_URL . 'assets/vendor/monaco/min/vs/loader.js', array( 'jquery' ), WP_MONACO_EDITOR_VERSION, true );
wp_enqueue_script( 'wp-monaco-plugins-themes-editor-js', WP_MONACO_EDITOR_PLUGIN_DIR_URL . 'assets/js/wp-monaco-plugins-themes-editor.js', array( 'monaco-editor' ), WP_MONACO_EDITOR_VERSION, true );
}
}
} // wp_monaco_editor_enqueue_admin_scripts
add_action( 'admin_enqueue_scripts', 'wp_monaco_editor_enqueue_admin_scripts' );
// if ( ! function_exists( 'wp_monaco_editor_tinymce_setup_function' ) ) {
// /**
// * Hook into TinyMCE init.
// *
// * @since 1.0.0
// *
// * @param array $init The functions passed to the TinyMCE init.
// */
// function wp_monaco_editor_tinymce_setup_function( $init ) {
// $init['init_instance_callback'] = 'function(editor) {
// editor.on("Change", function (e) {
// tinyOnChange(editor, e);
// });
// }';
// return $init;
// }
// } // wp_monaco_editor_tinymce_setup_function
// add_filter( 'tiny_mce_before_init', 'wp_monaco_editor_tinymce_setup_function' );