class-strong-testimonials-extensions-base.php
1 month ago
class-strong-testimonials-rest-api-base.php
1 week ago
class-strong-testimonials-settings-sanitizer.php
2 months ago
class-strong-testimonials-settings-sanitizer.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | class Strong_Testimonials_Settings_Sanitizer { |
| 4 | /** |
| 5 | * Holds the class object. |
| 6 | * |
| 7 | * @since 2.5.0 |
| 8 | * |
| 9 | * @var object |
| 10 | */ |
| 11 | public static $instance; |
| 12 | |
| 13 | /** |
| 14 | * Get the instance of the class. |
| 15 | */ |
| 16 | public static function get_instance() { |
| 17 | if ( ! isset( self::$instance ) || ! ( self::$instance instanceof Strong_Testimonials_Settings_Sanitizer ) ) { |
| 18 | self::$instance = new Strong_Testimonials_Settings_Sanitizer(); |
| 19 | } |
| 20 | |
| 21 | return self::$instance; |
| 22 | } |
| 23 | |
| 24 | public function text( $value ) { |
| 25 | return sanitize_text_field( $value ); |
| 26 | } |
| 27 | |
| 28 | public function url( $value ) { |
| 29 | return esc_url_raw( $value ); |
| 30 | } |
| 31 | |
| 32 | public function number( $value ) { |
| 33 | return absint( $value ); |
| 34 | } |
| 35 | |
| 36 | public function bool( $value ) { |
| 37 | return rest_sanitize_boolean( $value ); |
| 38 | } |
| 39 | |
| 40 | public function text_array( $value ) { |
| 41 | return array_map( 'sanitize_text_field', $value ); |
| 42 | } |
| 43 | |
| 44 | public function number_array( $value ) { |
| 45 | return array_map( 'absint', $value ); |
| 46 | } |
| 47 | |
| 48 | public function bool_array( $value ) { |
| 49 | return array_map( 'rest_sanitize_boolean', $value ); |
| 50 | } |
| 51 | |
| 52 | public function url_array( $value ) { |
| 53 | return array_map( 'esc_url_raw', $value ); |
| 54 | } |
| 55 | |
| 56 | public function kses( $value ) { |
| 57 | return wp_kses_post( $value ); |
| 58 | } |
| 59 | |
| 60 | public function float( $value ) { |
| 61 | return floatval( $value ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Convert a newline-separated string of IP addresses to an array. |
| 66 | * Keeps backward compatibility with code that expects restrict_ip as array. |
| 67 | */ |
| 68 | public function ip_list( $value ) { |
| 69 | if ( empty( $value ) ) { |
| 70 | return array(); |
| 71 | } |
| 72 | $lines = preg_split( '/\r\n|\r|\n/', (string) $value ); |
| 73 | return array_values( array_filter( array_map( 'sanitize_text_field', $lines ) ) ); |
| 74 | } |
| 75 | } |
| 76 |