@@ -19,15 +19,37 @@ public function __construct() {
19
19
return ;
20
20
}
21
21
22
+ // Disable Syntax Highlighting (CodeMirror)
23
+ add_filter ( 'wp_code_editor_settings ' , array ( $ this , 'wp_code_editor_settings ' ), 10 , 2 );
24
+
22
25
// Enqueue theme and plugin editor scripts
23
26
add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'admin_enqueue_scripts ' ) );
24
27
}
25
28
29
+ /**
30
+ * Disable Syntax Highlighting (CodeMirror)
31
+ */
32
+ public function wp_code_editor_settings ( $ settings , $ args ) {
33
+ // Return the default settings if theme/plugin editor is not displayed.
34
+ if ( ! str_contains ( $ _SERVER ['REQUEST_URI ' ], 'theme-editor.php ' ) && ! str_contains ( $ _SERVER ['REQUEST_URI ' ], 'plugin-editor.php ' ) ) {
35
+ return $ settings ;
36
+ }
37
+
38
+ // Return the default settings if the user role isn't allowed to use this extension.
39
+ if ( ! Settings::is_allowed_user () ) {
40
+ return $ settings ;
41
+ }
42
+
43
+ $ settings ['codemirror ' ] = false ;
44
+
45
+ return $ settings ;
46
+ }
47
+
26
48
/**
27
49
* Enqueue theme and plugin editor scripts
28
50
*/
29
51
public function admin_enqueue_scripts ( $ hook_suffix ) {
30
- // Abort the process if post/page editor is not displayed.
52
+ // Abort the process if theme/plugin editor is not displayed.
31
53
if ( 'theme-editor.php ' !== $ hook_suffix && 'plugin-editor.php ' !== $ hook_suffix ) {
32
54
return ;
33
55
}
@@ -73,11 +95,6 @@ public function admin_enqueue_scripts( $hook_suffix ) {
73
95
$ language = 'php ' ;
74
96
}
75
97
76
- // Disable the default code editor (CodeMirror).
77
- wp_dequeue_script ( 'wp-theme-plugin-editor ' );
78
- wp_deregister_style ( 'wp-codemirror ' );
79
- wp_deregister_script ( 'wp-codemirror ' );
80
-
81
98
wp_enqueue_style (
82
99
CHBE_NAMESPACE ,
83
100
CHBE_URL . '/build/style-theme-plugin-editor.css ' ,
0 commit comments