| @@ 3041-3043 (lines=3) @@ | ||
| 3038 | ||
| 3039 | // If it's an associative array, use the keys to check that the value is among those admitted. |
|
| 3040 | $enum = ( count( array_filter( array_keys( $args['enum'] ), 'is_string' ) ) > 0 ) ? array_keys( $args['enum'] ) : $args['enum']; |
|
| 3041 | if ( ! in_array( $value, $enum ) ) { |
|
| 3042 | return new WP_Error( |
|
| 3043 | 'invalid_param_value', |
|
| 3044 | sprintf( |
|
| 3045 | /* Translators: first variable is the parameter passed to endpoint that holds the list item, the second is a list of admitted values. */ |
|
| 3046 | esc_html__( '%1$s must be one of %2$s', 'jetpack' ), |
|
| @@ 3074-3076 (lines=3) @@ | ||
| 3071 | ||
| 3072 | $modules = Jetpack::get_available_modules(); |
|
| 3073 | ||
| 3074 | if ( count( array_intersect( $value, $modules ) ) != count( $value ) ) { |
|
| 3075 | return new WP_Error( 'invalid_param_value', sprintf( esc_html__( '%s must be a list of valid modules', 'jetpack' ), $param ) ); |
|
| 3076 | } |
|
| 3077 | ||
| 3078 | return true; |
|
| 3079 | } |
|
| @@ 3277-3279 (lines=3) @@ | ||
| 3274 | $sharer = new Sharing_Service(); |
|
| 3275 | $services = array_keys( $sharer->get_all_services() ); |
|
| 3276 | ||
| 3277 | if ( ! empty( $value ) && ! in_array( $value, $services ) ) { |
|
| 3278 | return new WP_Error( 'invalid_param', sprintf( esc_html__( '%s is not a registered custom sharing service.', 'jetpack' ), $param ) ); |
|
| 3279 | } |
|
| 3280 | ||
| 3281 | return true; |
|
| 3282 | } |
|
| @@ 87-97 (lines=11) @@ | ||
| 84 | ||
| 85 | $allowed_object_types = array_keys( self::get_allowed_object_types() ); |
|
| 86 | ||
| 87 | if ( ! in_array( $value, $allowed_object_types, true ) ) { |
|
| 88 | return new WP_Error( |
|
| 89 | 'rest_invalid_param', |
|
| 90 | sprintf( |
|
| 91 | /* translators: %s: comma-separated list of allowed object types */ |
|
| 92 | __( 'The object_type argument should be one of %s', 'jetpack' ), |
|
| 93 | implode( ', ', $allowed_object_types ) |
|
| 94 | ), |
|
| 95 | array( 'status' => 400 ) |
|
| 96 | ); |
|
| 97 | } |
|
| 98 | ||
| 99 | return true; |
|
| 100 | }, |
|