PluginProbe
Code Snippets / 2.14.0
Code Snippets v2.14.0
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / settings / editor-preview.php

editor-preview.php in Code Snippets 2.14.0, at php/settings/editor-preview.php

98 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file handles the editor preview setting
5 *
6 * @since 2.0
7 * @package Code_Snippets
8 */
9
10 /**
11 * Load the CSS and JavaScript for the editor preview field
12 */
13 function code_snippets_editor_settings_preview_assets() {
14 $plugin = code_snippets();
15
16 // Enqueue scripts for the editor preview
17 code_snippets_enqueue_editor();
18
19 // Enqueue all editor themes
20 $themes = code_snippets_get_available_themes();
21
22 foreach ( $themes as $theme ) {
23 if ( 'default' !== $theme ) {
24 wp_enqueue_style(
25 'code-snippets-editor-theme-' . $theme,
26 plugins_url( "css/min/editor-themes/$theme.css", $plugin->file ),
27 array( 'code-snippets-editor' ), $plugin->version
28 );
29 }
30 }
31
32 // Enqueue the menu scripts
33 wp_enqueue_script(
34 'code-snippets-settings-menu',
35 plugins_url( 'js/min/settings.js', $plugin->file ),
36 array( 'code-snippets-editor' ), $plugin->version, true
37 );
38
39 // Extract the CodeMirror-specific editor settings
40 $setting_fields = code_snippets_get_settings_fields();
41 $editor_fields = array();
42
43 foreach ( $setting_fields['editor'] as $name => $field ) {
44 if ( empty( $field['codemirror'] ) ) {
45 continue;
46 }
47
48 $editor_fields[] = array(
49 'name' => $name,
50 'type' => $field['type'],
51 'codemirror' => addslashes( $field['codemirror'] ),
52 );
53 }
54
55 // Pass the saved options to the external JavaScript file
56 $inline_script = 'var code_snippets_editor_atts = ' . code_snippets_get_editor_atts( array(), true ) . ';';
57 $inline_script .= "\n" . 'var code_snippets_editor_settings = ' . wp_json_encode( $editor_fields ) . ';';
58
59 wp_add_inline_script( 'code-snippets-settings-menu', $inline_script, 'before' );
60 }
61
62 /**
63 * Render a theme select field
64 *
65 * @param array $atts
66 */
67 function code_snippets_codemirror_theme_select_field( $atts ) {
68
69 $saved_value = code_snippets_get_setting( $atts['section'], $atts['id'] );
70
71 echo '<select name="code_snippets_settings[editor][theme]">';
72
73 // print a dropdown entry for each theme
74 foreach ( code_snippets_get_available_themes() as $theme ) {
75
76 // skip mobile themes
77 if ( 'ambiance-mobile' === $theme ) {
78 continue;
79 }
80
81 printf(
82 '<option value="%s"%s>%s</option>',
83 $theme,
84 selected( $theme, $saved_value, false ),
85 ucwords( str_replace( '-', ' ', $theme ) )
86 );
87 }
88
89 echo '</select>';
90 }
91
92 /**
93 * Render the editor preview setting
94 */
95 function code_snippets_settings_editor_preview() {
96 echo '<div id="code_snippets_editor_preview"></div>';
97 }
98