Skip to content

Commit 66755ba

Browse files
authored
Fix: Ajax on save doesn't work in theme plugin editor (#129)
* Fix: Ajax on save doesn't work in theme plugin editor * Try to fix e2e test
1 parent cd22fc4 commit 66755ba

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

classes/class-theme-plugin-editor.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,37 @@ public function __construct() {
1919
return;
2020
}
2121

22+
// Disable Syntax Highlighting (CodeMirror)
23+
add_filter( 'wp_code_editor_settings', array( $this, 'wp_code_editor_settings' ), 10, 2 );
24+
2225
// Enqueue theme and plugin editor scripts
2326
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
2427
}
2528

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+
2648
/**
2749
* Enqueue theme and plugin editor scripts
2850
*/
2951
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.
3153
if ( 'theme-editor.php' !== $hook_suffix && 'plugin-editor.php' !== $hook_suffix ) {
3254
return;
3355
}
@@ -73,11 +95,6 @@ public function admin_enqueue_scripts( $hook_suffix ) {
7395
$language = 'php';
7496
}
7597

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-
8198
wp_enqueue_style(
8299
CHBE_NAMESPACE,
83100
CHBE_URL . '/build/style-theme-plugin-editor.css',

test/e2e/test.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ test.describe( 'Custom HTML Block Extension', () => {
3737
pageUtils,
3838
} ) => {
3939
await admin.visitAdminPage( 'theme-editor.php' );
40+
// Hide file editor warning modal.
41+
const dismissButton = page.locator( '.file-editor-warning-dismiss' );
42+
const isVisible = await dismissButton.isVisible();
43+
if ( isVisible ) {
44+
await dismissButton.click();
45+
}
46+
4047
await page.click( '#monaco-editor .monaco-editor' );
4148
await pageUtils.pressKeys( 'primary+a' );
4249
await page.keyboard.press( 'Delete' );

0 commit comments

Comments
 (0)