| @@ -43,9 +43,9 @@ | ||
| 43 | 43 | 'Alt-Up' => 'swapLineUp', |
| 44 | 44 | 'Alt-Down' => 'swapLineDown', |
| 45 | 45 | ], |
| 46 | 46 | 'gutters' => [ 'CodeMirror-lint-markers', 'CodeMirror-foldgutter' ], |
| 47 | - 'lint' => 'css' === $type || 'php' === $type, | |
| 47 | + 'lint' => 'php' === $type, | |
| 48 | 48 | 'direction' => 'ltr', |
| 49 | 49 | 'colorpicker' => [ 'mode' => 'edit' ], |
| 50 | 50 | 'foldOptions' => [ 'widget' => '...' ], |
| 51 | 51 | ]; |
| @@ -93,9 +93,45 @@ | ||
| 93 | 93 | PLUGIN_VERSION, |
| 94 | 94 | [ 'in_footer' => true ] |
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | - // CodeMirror Theme. | |
| 97 | + enqueue_code_editor_theme(); | |
| 98 | +} | |
| 99 | + | |
| 100 | +/** | |
| 101 | + * Load the CodeMirror assets required for read-only code previews. | |
| 102 | + * | |
| 103 | + * @param string $type Type of code editor – either 'php', 'css', 'js', or 'html'. | |
| 104 | + * | |
| 105 | + * @return void | |
| 106 | + */ | |
| 107 | +function enqueue_code_preview_editor( string $type ): void { | |
| 108 | + $modes = [ | |
| 109 | + 'css' => 'text/css', | |
| 110 | + 'php' => 'text/x-php', | |
| 111 | + 'js' => 'javascript', | |
| 112 | + 'html' => 'application/x-httpd-php', | |
| 113 | + ]; | |
| 114 | + | |
| 115 | + wp_enqueue_code_editor( | |
| 116 | + [ | |
| 117 | + 'type' => $modes[ $type ] ?? $modes['php'], | |
| 118 | + 'codemirror' => [ | |
| 119 | + 'lint' => false, | |
| 120 | + 'readOnly' => true, | |
| 121 | + ], | |
| 122 | + ] | |
| 123 | + ); | |
| 124 | + | |
| 125 | + enqueue_code_editor_theme(); | |
| 126 | +} | |
| 127 | + | |
| 128 | +/** | |
| 129 | + * Load the configured CodeMirror theme. | |
| 130 | + * | |
| 131 | + * @return void | |
| 132 | + */ | |
| 133 | +function enqueue_code_editor_theme(): void { | |
| 98 | 134 | $theme = get_setting( 'editor', 'theme' ); |
| 99 | 135 | |
| 100 | 136 | if ( 'default' !== $theme ) { |
| 101 | 137 | wp_enqueue_style( |