diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
index 8fbf4b1342..d2cd599f99 100644
|
a
|
b
|
function rest_parse_date( $date, $force_utc = false ) { |
| 966 | 966 | return strtotime( $date ); |
| 967 | 967 | } |
| 968 | 968 | |
| | 969 | /** |
| | 970 | * Parses an 3 or 6 digit hex color (with #). |
| | 971 | * |
| | 972 | * @since 5.4.0 |
| | 973 | * |
| | 974 | * @param string $color 3 or 6 digit hex color (with #). |
| | 975 | * the timestamp's timezone. Default false. |
| | 976 | * @return string|boolean |
| | 977 | */ |
| | 978 | function rest_parse_color( $color ) { |
| | 979 | $regex = '|^#([A-Fa-f0-9]{3}){1,2}$|'; |
| | 980 | |
| | 981 | if ( ! preg_match( $regex, $color, $matches ) ) { |
| | 982 | return false; |
| | 983 | } |
| | 984 | |
| | 985 | return $color; |
| | 986 | } |
| | 987 | |
| 969 | 988 | /** |
| 970 | 989 | * Parses a date into both its local and UTC equivalent, in MySQL datetime format. |
| 971 | 990 | * |
| … |
… |
function rest_validate_value_from_schema( $value, $args, $param = '' ) { |
| 1314 | 1333 | |
| 1315 | 1334 | if ( isset( $args['format'] ) ) { |
| 1316 | 1335 | switch ( $args['format'] ) { |
| | 1336 | case 'color': |
| | 1337 | if ( ! rest_parse_color( $value ) ) { |
| | 1338 | return new WP_Error( 'rest_invalid_color', __( 'Invalid color.' ) ); |
| | 1339 | } |
| | 1340 | break; |
| | 1341 | |
| 1317 | 1342 | case 'date-time': |
| 1318 | 1343 | if ( ! rest_parse_date( $value ) ) { |
| 1319 | 1344 | return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) ); |
| … |
… |
function rest_sanitize_value_from_schema( $value, $args ) { |
| 1470 | 1495 | |
| 1471 | 1496 | if ( isset( $args['format'] ) ) { |
| 1472 | 1497 | switch ( $args['format'] ) { |
| | 1498 | case 'color': |
| | 1499 | return sanitize_hex_color( $value ); |
| | 1500 | |
| 1473 | 1501 | case 'date-time': |
| 1474 | 1502 | return sanitize_text_field( $value ); |
| 1475 | 1503 | |