Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
4.35% |
1 / 23 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Checkbox_Setting_Element_Abstract | |
4.35% |
1 / 23 |
|
33.33% |
1 / 3 |
37.51 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_is_checked_value | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| get_is_not_checked_value | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| print_field_callback | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
6 | |||
| sanitize_callback | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BrianHenryIE\WP_Autologin_URLs\Admin\Settings_Fields; |
| 4 | |
| 5 | abstract class Checkbox_Setting_Element_Abstract extends Settings_Section_Element_Abstract { |
| 6 | |
| 7 | public function __construct( $settings_page_slugname_slug_name, $section = 'default' ) { |
| 8 | parent::__construct( $settings_page_slugname_slug_name, $section ); |
| 9 | } |
| 10 | |
| 11 | abstract protected function get_is_checked_value(): string; |
| 12 | |
| 13 | abstract protected function get_is_not_checked_value(): string; |
| 14 | |
| 15 | /** |
| 16 | * Prints the checkbox as displayed in the right-hand column of the settings table. |
| 17 | * |
| 18 | * @param array{placeholder:string, helper:string, supplemental:string, default:string} $arguments The field data as registered with add_settings_field(). |
| 19 | */ |
| 20 | public function print_field_callback( $arguments ): void { |
| 21 | |
| 22 | $is_checked = $this->get_is_checked_value() === $this->value ? 'checked ' : ''; |
| 23 | $label = $arguments['helper']; |
| 24 | |
| 25 | printf( |
| 26 | '<fieldset><label for="%1$s"><input id="%1$s" name="%1$s" type="checkbox" value="%2$s" %3$s />%4$s</label></fieldset>', |
| 27 | esc_attr( $this->id ), |
| 28 | esc_attr( $this->get_is_checked_value() ), |
| 29 | esc_attr( $is_checked ), |
| 30 | wp_kses( $label, array( 'i' => array() ) ) |
| 31 | ); |
| 32 | |
| 33 | $allowed_html = array( |
| 34 | 'br' => array(), |
| 35 | 'a' => array( |
| 36 | 'href' => array(), |
| 37 | 'target' => array(), |
| 38 | ), |
| 39 | ); |
| 40 | |
| 41 | printf( '<p class="description">%s</p>', wp_kses( $arguments['supplemental'], $allowed_html ) ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * If an unexpected value is POSTed, don't make any change to what's in the database. |
| 46 | * |
| 47 | * @param ?string $value The data posted from the HTML form. |
| 48 | * |
| 49 | * @return string The value to save in the database. |
| 50 | */ |
| 51 | public function sanitize_callback( $value ) { |
| 52 | |
| 53 | if ( $this->get_is_checked_value() === $value ) { |
| 54 | return $value; |
| 55 | } elseif ( null === $value ) { |
| 56 | return $this->get_is_not_checked_value(); |
| 57 | } else { |
| 58 | return $this->value; |
| 59 | } |
| 60 | } |
| 61 | } |