From 992a9d6ca186bb4399143dd5ee72a27a3b4909aa Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 26 Oct 2020 18:03:48 +0100 Subject: Initial commit --- src/ThemeEditor.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/ThemeEditor.php (limited to 'src/ThemeEditor.php') diff --git a/src/ThemeEditor.php b/src/ThemeEditor.php new file mode 100644 index 0000000..0b62264 --- /dev/null +++ b/src/ThemeEditor.php @@ -0,0 +1,73 @@ + 'twig', 'base' => 'text/html']; + } + + $settings['codemirror']['theme'] = Settings::getCodeMirrorTheme(); + + return $settings; + } + + /** + * wp_enqueue_code_editor action callback + * Adds twig and custom mode support + * Adds selected theme css + * + * @param $settings + */ + public function enqueueCodeEditor($settings) { + if (isset($settings['codemirror']['mode']['name']) && $settings['codemirror']['mode']['name'] == 'twig') { + wp_add_inline_script( # fix as described here: https://make.wordpress.org/core/2017/10/22/code-editing-improvements-in-wordpress-4-9/ + 'wp-codemirror', + 'window.CodeMirror = wp.CodeMirror;' + ); + wp_enqueue_script('mode-twig', 'https://unpkg.com/codemirror@5/mode/twig/twig.js', ['wp-codemirror']); + } + + $theme = $settings['codemirror']['theme']; + if ($theme != 'default') { + wp_enqueue_style('codemirror-theme', "https://unpkg.com/codemirror@5/theme/$theme.css", ['wp-codemirror']); + } + } +} -- cgit v1.2.3