| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Validation traits. |
| 5 |
* |
| 6 |
* @package \Optml\Inc\Traits |
| 7 |
* @author Optimole <friends@optimole.com> |
| 8 |
*/ |
| 9 |
trait Optml_Validator { |
| 10 |
|
| 11 |
/** |
| 12 |
* Check if the value is a valid numeric. |
| 13 |
* |
| 14 |
* @param mixed $value The value to check. |
| 15 |
* |
| 16 |
* @return bool |
| 17 |
*/ |
| 18 |
public function is_valid_numeric( $value ) { |
| 19 |
if ( isset( $value ) && ! empty( $value ) && is_numeric( $value ) ) { |
| 20 |
return true; |
| 21 |
} |
| 22 |
|
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Check if the URl is a GIF url. |
| 28 |
* |
| 29 |
* @param string $url URL to check. |
| 30 |
* |
| 31 |
* @return bool Is Gif? |
| 32 |
*/ |
| 33 |
public function is_valid_gif( $url ) { |
| 34 |
$type = wp_check_filetype( $url, [ 'gif' => 'image/gif' ] ); |
| 35 |
|
| 36 |
if ( ! isset( $type['ext'] ) || empty( $type['ext'] ) ) { |
| 37 |
return false; |
| 38 |
} |
| 39 |
|
| 40 |
return true; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Check if the url has an accepted mime type extension. |
| 45 |
* |
| 46 |
* @param mixed $url The url to check. |
| 47 |
* |
| 48 |
* @return bool |
| 49 |
*/ |
| 50 |
public function is_valid_mimetype_from_url( $url, $filters = [] ) { |
| 51 |
$type = wp_check_filetype( $url, Optml_Config::$all_extensions ); |
| 52 |
|
| 53 |
if ( ! isset( $type['ext'] ) || empty( $type['ext'] ) ) { |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
return Optml_Filters::should_do_extension( $filters, $type['ext'] ); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
} |
| 62 |
|