Changeset 47450 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 03/12/2020 02:40:29 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r47362 r47450 972 972 973 973 /** 974 * Parses a 3 or 6 digit hex color (with #). 975 * 976 * @since 5.4.0 977 * 978 * @param string $color 3 or 6 digit hex color (with #). 979 * @return string|false 980 */ 981 function rest_parse_hex_color( $color ) { 982 $regex = '|^#([A-Fa-f0-9]{3}){1,2}$|'; 983 if ( ! preg_match( $regex, $color, $matches ) ) { 984 return false; 985 } 986 987 return $color; 988 } 989 990 /** 974 991 * Parses a date into both its local and UTC equivalent, in MySQL datetime format. 975 992 * … … 1328 1345 if ( isset( $args['format'] ) ) { 1329 1346 switch ( $args['format'] ) { 1347 case 'hex-color': 1348 if ( ! rest_parse_hex_color( $value ) ) { 1349 return new WP_Error( 'rest_invalid_hex_color', __( 'Invalid hex color.' ) ); 1350 } 1351 break; 1352 1330 1353 case 'date-time': 1331 1354 if ( ! rest_parse_date( $value ) ) { … … 1486 1509 if ( isset( $args['format'] ) ) { 1487 1510 switch ( $args['format'] ) { 1511 case 'hex-color': 1512 return (string) sanitize_hex_color( $value ); 1513 1488 1514 case 'date-time': 1489 1515 return sanitize_text_field( $value );
Note: See TracChangeset
for help on using the changeset viewer.