Changeset 39239 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 11/15/2016 05:38:21 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r39238 r39239 1000 1000 } 1001 1001 if ( ! wp_is_numeric_array( $value ) ) { 1002 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: type name */ __( '%1$s is not of type %2$s.' ), $param, 'array' ) ); 1002 /* translators: 1: parameter, 2: type name */ 1003 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ) ); 1003 1004 } 1004 1005 foreach ( $value as $index => $v ) { … … 1011 1012 if ( ! empty( $args['enum'] ) ) { 1012 1013 if ( ! in_array( $value, $args['enum'], true ) ) { 1013 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: list of valid values */ __( '%1$s is not one of %2$s.' ), $param, implode( ', ', $args['enum'] ) ) ); 1014 /* translators: 1: parameter, 2: list of valid values */ 1015 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not one of %2$s.' ), $param, implode( ', ', $args['enum'] ) ) ); 1014 1016 } 1015 1017 } 1016 1018 1017 1019 if ( in_array( $args['type'], array( 'integer', 'number' ) ) && ! is_numeric( $value ) ) { 1018 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: type name */ __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) ); 1020 /* translators: 1: parameter, 2: type name */ 1021 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, $args['type'] ) ); 1019 1022 } 1020 1023 1021 1024 if ( 'integer' === $args['type'] && round( floatval( $value ) ) !== floatval( $value ) ) { 1022 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: type name */ __( '%1$s is not of type %2$s.' ), $param, 'integer' ) ); 1025 /* translators: 1: parameter, 2: type name */ 1026 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'integer' ) ); 1023 1027 } 1024 1028 1025 1029 if ( 'boolean' === $args['type'] && ! rest_is_boolean( $value ) ) { 1026 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: type name */ __( '%1$s is not of type %2$s.' ), $value, 'boolean' ) ); 1030 /* translators: 1: parameter, 2: type name */ 1031 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $value, 'boolean' ) ); 1027 1032 } 1028 1033 1029 1034 if ( 'string' === $args['type'] && ! is_string( $value ) ) { 1030 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: type name */ __( '%1$s is not of type %2$s.' ), $param, 'string' ) ); 1035 /* translators: 1: parameter, 2: type name */ 1036 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'string' ) ); 1031 1037 } 1032 1038 … … 1050 1056 case 'ipv4' : 1051 1057 if ( ! rest_is_ip_address( $value ) ) { 1052 return new WP_Error( 'rest_invalid_param', sprintf( __( /* translators: %s: IP address */ '%s is not a valid IP address.' ), $value ) ); 1058 /* translators: %s: IP address */ 1059 return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) ); 1053 1060 } 1054 1061 break; … … 1059 1066 if ( isset( $args['minimum'] ) && ! isset( $args['maximum'] ) ) { 1060 1067 if ( ! empty( $args['exclusiveMinimum'] ) && $value <= $args['minimum'] ) { 1061 return new WP_Error( 'rest_invalid_param', sprintf( __( /* translators: 1: parameter, 2: minimum number */ '%1$s must be greater than %2$d (exclusive)' ), $param, $args['minimum'] ) ); 1068 /* translators: 1: parameter, 2: minimum number */ 1069 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d (exclusive)' ), $param, $args['minimum'] ) ); 1062 1070 } elseif ( empty( $args['exclusiveMinimum'] ) && $value < $args['minimum'] ) { 1063 return new WP_Error( 'rest_invalid_param', sprintf( __( /* translators: 1: parameter, 2: minimum number */ '%1$s must be greater than %2$d (inclusive)' ), $param, $args['minimum'] ) ); 1071 /* translators: 1: parameter, 2: minimum number */ 1072 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d (inclusive)' ), $param, $args['minimum'] ) ); 1064 1073 } 1065 1074 } elseif ( isset( $args['maximum'] ) && ! isset( $args['minimum'] ) ) { 1066 1075 if ( ! empty( $args['exclusiveMaximum'] ) && $value >= $args['maximum'] ) { 1067 return new WP_Error( 'rest_invalid_param', sprintf( __( /* translators: 1: parameter, 2: maximum number */ '%1$s must be less than %2$d (exclusive)' ), $param, $args['maximum'] ) ); 1076 /* translators: 1: parameter, 2: maximum number */ 1077 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d (exclusive)' ), $param, $args['maximum'] ) ); 1068 1078 } elseif ( empty( $args['exclusiveMaximum'] ) && $value > $args['maximum'] ) { 1069 return new WP_Error( 'rest_invalid_param', sprintf( __( /* translators: 1: parameter, 2: maximum number */ '%1$s must be less than %2$d (inclusive)' ), $param, $args['maximum'] ) ); 1079 /* translators: 1: parameter, 2: maximum number */ 1080 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d (inclusive)' ), $param, $args['maximum'] ) ); 1070 1081 } 1071 1082 } elseif ( isset( $args['maximum'] ) && isset( $args['minimum'] ) ) { 1072 1083 if ( ! empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) { 1073 1084 if ( $value >= $args['maximum'] || $value <= $args['minimum'] ) { 1074 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: minimum number, 3: maximum number */ __( '%1$s must be between %2$d (exclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); 1085 /* translators: 1: parameter, 2: minimum number, 3: maximum number */ 1086 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$d (exclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); 1075 1087 } 1076 1088 } elseif ( empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) { 1077 1089 if ( $value >= $args['maximum'] || $value < $args['minimum'] ) { 1078 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: minimum number, 3: maximum number */ __( '%1$s must be between %2$d (inclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); 1090 /* translators: 1: parameter, 2: minimum number, 3: maximum number */ 1091 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$d (inclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); 1079 1092 } 1080 1093 } elseif ( ! empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) { 1081 1094 if ( $value > $args['maximum'] || $value <= $args['minimum'] ) { 1082 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: minimum number, 3: maximum number */ __( '%1$s must be between %2$d (exclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); 1095 /* translators: 1: parameter, 2: minimum number, 3: maximum number */ 1096 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$d (exclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); 1083 1097 } 1084 1098 } elseif ( empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) { 1085 1099 if ( $value > $args['maximum'] || $value < $args['minimum'] ) { 1086 return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: minimum number, 3: maximum number */ __( '%1$s must be between %2$d (inclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); 1100 /* translators: 1: parameter, 2: minimum number, 3: maximum number */ 1101 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$d (inclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) ); 1087 1102 } 1088 1103 }
Note: See TracChangeset
for help on using the changeset viewer.