Make WordPress Core


Ignore:
Timestamp:
05/16/2020 07:01:49 PM (5 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Support the JSON Schema pattern keyword.

Props jason_the_adams, birgire, sorenbronsted.
Fixes #44949.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r47809 r47810  
    13821382                )
    13831383            );
     1384        }
     1385
     1386        if ( isset( $args['pattern'] ) ) {
     1387            $pattern = str_replace( '#', '\\#', $args['pattern'] );
     1388            if ( ! preg_match( '#' . $pattern . '#u', $value ) ) {
     1389                /* translators: 1: Parameter, 2: Pattern. */
     1390                return new WP_Error( 'rest_invalid_pattern', sprintf( __( '%1$s does not match pattern %2$s.' ), $param, $args['pattern'] ) );
     1391            }
    13841392        }
    13851393    }
Note: See TracChangeset for help on using the changeset viewer.