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

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

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