This repository has been archived by the owner on Nov 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathsettings.php
86 lines (76 loc) · 2.56 KB
/
settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Code Syntax Block plugin settings page
*/
add_action( 'admin_menu', function() {
add_options_page(
'Code Syntax Block Settings', // Title
'Code Syntax Block', // Menu Link
'manage_options', // capability
'mkaz_code_syntax_block_settings', // slug
'mkaz_code_syntax_block_settings_page' // callback
);
} );
add_action( 'admin_init', function() {
register_setting( 'mkaz_code_syntax_block_settings', 'mkaz-code-syntax-color-scheme' );
register_setting( 'mkaz_code_syntax_block_settings', 'mkaz-code-syntax-default-lang' );
add_settings_section(
'mkaz_code_syntax_block_color_scheme',
'',
'',
'mkaz_code_syntax_block_settings'
);
add_settings_field(
'mkaz-code-syntax-color-scheme',
__( 'Color Scheme', 'mkaz_code_syntax_block' ),
'mkaz_code_syntax_block_color_scheme_field_callback',
'mkaz_code_syntax_block_settings', // Section
'mkaz_code_syntax_block_color_scheme' // Setting
);
add_settings_field(
'mkaz-code-syntax-default-lang',
__( 'Default Language', 'mkaz_code_syntax_block' ),
'mkaz_code_syntax_block_default_lang_field_callback',
'mkaz_code_syntax_block_settings', // Section
'mkaz_code_syntax_block_color_scheme' // Setting
);
});
function mkaz_code_syntax_block_color_scheme_field_callback() {
$current_option = get_option( 'mkaz-code-syntax-color-scheme', 'prism-a11y-dark' );
?>
<select name="mkaz-code-syntax-color-scheme">
<?php foreach ( MKAZ_CODE_SYNTAX_COLOR_SCHEMES as $k => $v ) : ?>
<option
<?php if ( $current_option === $k ) { echo "selected"; } ?>
value="<?php echo esc_attr( $k ); ?>"
>
<?php echo esc_html( $v); ?>
</option>
<?php endforeach; ?>
</select>
<p><b>Note:</b> This will change the color scheme for all existing code syntax blocks.</p>
<?php
}
function mkaz_code_syntax_block_default_lang_field_callback() {
$current_option = get_option( 'mkaz-code-syntax-default-lang', '' );
?>
<input
type="text"
name="mkaz-code-syntax-default-lang"
value="<?php echo esc_attr( $current_option ); ?>"
/> (optional)
<p> Automatically set this language when a code block is inserted, use language alias from <a href="https://prismjs.com/#supported-languages">supported languages list</a>.</p>
<?php
}
function mkaz_code_syntax_block_settings_page() {
?>
<h2>Code Syntax Block Settings</h2>
<form action="options.php" method="post">
<table class="form-table">
<?php settings_fields( 'mkaz_code_syntax_block_settings' ); ?>
<?php do_settings_sections( 'mkaz_code_syntax_block_settings' ); ?>
<?php submit_button(); ?>
</table>
</form>
<?php
}