PluginProbe
Code Snippets / 3.10.1
Code Snippets v3.10.1
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 3.10.1, at php/Settings/Editor_Preview.php

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This file handles the editor preview setting
4 *
5 * @since 2.0.0
6 * @package Code_Snippets
7 */
8
9 namespace Code_Snippets\Settings;
10
11 use function Code_Snippets\Utils\get_editor_themes;
12
13 /**
14 * Class for handling the editor preview setting.
15 *
16 * @package Code_Snippets\Settings
17 */
18 class Editor_Preview {
19
20 /**
21 * Retrieve the list of code editor themes.
22 *
23 * @return array<string, string> List of editor themes.
24 */
25 public static function get_editor_theme_list(): array {
26 $themes = [
27 'default' => __( 'Default', 'code-snippets' ),
28 ];
29
30 foreach ( get_editor_themes() as $theme ) {
31 if ( '-mobile' === substr( $theme, -7 ) ) {
32 continue;
33 }
34
35 $themes[ $theme ] = ucwords( str_replace( '-', ' ', $theme ) );
36 }
37
38 return $themes;
39 }
40
41 /**
42 * Render the editor preview setting.
43 */
44 public function render() {
45 $settings = get_settings_values();
46 $settings = $settings['editor'];
47
48 $indent_unit = absint( $settings['indent_unit'] );
49 $tab_size = absint( $settings['tab_size'] );
50
51 $n_tabs = $settings['indent_with_tabs'] ? floor( $indent_unit / $tab_size ) : 0;
52 $n_spaces = $settings['indent_with_tabs'] ? $indent_unit % $tab_size : $indent_unit;
53
54 $indent = str_repeat( "\t", $n_tabs ) . str_repeat( ' ', $n_spaces );
55
56 $code = "add_filter( 'admin_footer_text', function ( \$text ) {\n\n" .
57 $indent . "\$site_name = get_bloginfo( 'name' );\n\n" .
58 $indent . '$text = "Thank you for visiting $site_name.";' . "\n" .
59 $indent . 'return $text;' . "\n" .
60 "} );\n";
61
62 echo '<textarea id="code_snippets_editor_preview">', esc_textarea( $code ), '</textarea>';
63 }
64 }
65