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 / render-fields.php

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

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