PluginProbe
Code Snippets / 2.14.6
Code Snippets v2.14.6
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.6, at php/settings/editor-preview.php

101 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' ),
28 $plugin->version
29 );
30 }
31 }
32
33 // Enqueue the menu scripts
34 wp_enqueue_script(
35 'code-snippets-settings-menu',
36 plugins_url( 'js/min/settings.js', $plugin->file ),
37 array( 'code-snippets-editor' ),
38 $plugin->version,
39 true
40 );
41
42 // Extract the CodeMirror-specific editor settings
43 $setting_fields = code_snippets_get_settings_fields();
44 $editor_fields = array();
45
46 foreach ( $setting_fields['editor'] as $name => $field ) {
47 if ( empty( $field['codemirror'] ) ) {
48 continue;
49 }
50
51 $editor_fields[] = array(
52 'name' => $name,
53 'type' => $field['type'],
54 'codemirror' => addslashes( $field['codemirror'] ),
55 );
56 }
57
58 // Pass the saved options to the external JavaScript file
59 $inline_script = 'var code_snippets_editor_atts = ' . code_snippets_get_editor_atts( array(), true ) . ';';
60 $inline_script .= "\n" . 'var code_snippets_editor_settings = ' . wp_json_encode( $editor_fields ) . ';';
61
62 wp_add_inline_script( 'code-snippets-settings-menu', $inline_script, 'before' );
63 }
64
65 /**
66 * Render a theme select field
67 *
68 * @param array $atts
69 */
70 function code_snippets_codemirror_theme_select_field( $atts ) {
71
72 $saved_value = code_snippets_get_setting( $atts['section'], $atts['id'] );
73
74 echo '<select name="code_snippets_settings[editor][theme]">';
75
76 // print a dropdown entry for each theme
77 foreach ( code_snippets_get_available_themes() as $theme ) {
78
79 // skip mobile themes
80 if ( 'ambiance-mobile' === $theme ) {
81 continue;
82 }
83
84 printf(
85 '<option value="%s"%s>%s</option>',
86 esc_attr( $theme ),
87 selected( $theme, $saved_value, false ),
88 esc_html( ucwords( str_replace( '-', ' ', $theme ) ) )
89 );
90 }
91
92 echo '</select>';
93 }
94
95 /**
96 * Render the editor preview setting
97 */
98 function code_snippets_settings_editor_preview() {
99 echo '<div id="code_snippets_editor_preview"></div>';
100 }
101