PluginProbe
Code Snippets / 2.12.1
Code Snippets v2.12.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 / render-fields.php

render-fields.php in Code Snippets 2.12.1, at php/settings/render-fields.php

75 lines 1.7 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 rendering the settings fields
5 *
6 * @since 2.0.0
7 * @package Code_Snippets
8 */
9
10 /**
11 * Render a checkbox field for a setting
12 *
13 * @since 2.0.0
14 *
15 * @param array $atts The setting field's attributes
16 */
17 function code_snippets_checkbox_field( $atts ) {
18 $saved_value = code_snippets_get_setting( $atts['section'], $atts['id'] );
19 $input_name = sprintf( 'code_snippets_settings[%s][%s]', $atts['section'], $atts['id'] );
20
21 $output = sprintf(
22 '<input type="checkbox" name="%s"%s>',
23 esc_attr( $input_name ),
24 checked( $saved_value, true, false )
25 );
26
27 // Output the checkbox field, optionally with label
28 if ( isset( $atts['label'] ) ) {
29 printf( '<label for="%s">%s %s</label>', esc_attr( $input_name ), $output, $atts['label'] );
30 } else {
31 echo $output;
32 }
33
34 // Add field description if it is set
35 if ( ! empty( $atts['desc'] ) ) {
36 echo '<p class="description">' . $atts['desc'] . '</p>';
37 }
38 }
39
40 /**
41 * Render a number select field for an editor setting
42 *
43 * @since 2.0.0
44 *
45 * @param array $atts The setting field's attributes
46 */
47 function code_snippets_number_field( $atts ) {
48
49 printf(
50 '<input type="number" name="code_snippets_settings[%s][%s]" value="%s"',
51 esc_attr( $atts['section'] ),
52 esc_attr( $atts['id'] ),
53 esc_attr( code_snippets_get_setting( $atts['section'], $atts['id'] ) )
54 );
55
56 if ( isset( $atts['min'] ) ) {
57 printf( ' min="%d"', $atts['min'] );
58 }
59
60 if ( isset( $atts['max'] ) ) {
61 printf( ' max="%d"', $atts['max'] );
62 }
63
64 echo '>';
65
66 if ( ! empty( $atts['label'] ) ) {
67 echo ' ' . $atts['label'];
68 }
69
70 // Add field description if it is set
71 if ( ! empty( $atts['desc'] ) ) {
72 echo '<p class="description">' . $atts['desc'] . '</p>';
73 }
74 }
75