aristath /
kirki
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Override field methods |
||
| 4 | * |
||
| 5 | * @package Kirki |
||
| 6 | * @subpackage Controls |
||
| 7 | * @copyright Copyright (c) 2017, Aristeides Stathopoulos |
||
| 8 | * @license https://opensource.org/licenses/MIT |
||
| 9 | * @since 2.3.2 |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Field overrides. |
||
| 14 | */ |
||
| 15 | class Kirki_Field_Sortable extends Kirki_Field { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Sets the control type. |
||
| 19 | * |
||
| 20 | * @access protected |
||
| 21 | */ |
||
| 22 | protected function set_type() { |
||
| 23 | $this->type = 'kirki-sortable'; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Sets the $sanitize_callback. |
||
| 28 | * |
||
| 29 | * @access protected |
||
| 30 | */ |
||
| 31 | protected function set_sanitize_callback() { |
||
| 32 | $this->sanitize_callback = array( $this, 'sanitize' ); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Sanitizes sortable values. |
||
| 37 | * |
||
| 38 | * @access public |
||
| 39 | * @param array $value The checkbox value. |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | public function sanitize( $value = array() ) { |
||
| 43 | if ( is_string( $value ) || is_numeric( $value ) ) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 44 | return array( |
||
| 45 | sanitize_text_field( $value ), |
||
| 46 | ); |
||
| 47 | } |
||
| 48 | $sanitized_value = array(); |
||
| 49 | foreach ( $value as $sub_value ) { |
||
| 50 | if ( isset( $this->choices[ $sub_value ] ) ) { |
||
| 51 | $sanitized_value[] = sanitize_text_field( $sub_value ); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | return $sanitized_value; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |