| 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 |
|