repository->get(); } public function save( array $input ): array { if ( array_diff( array_keys( $input ), [ 'latitude', 'longitude', 'address' ] ) ) { CatalogValidator::invalid( 'location', __( 'The request contains an unsupported field.', 'abece-booking' ) ); } $data = array_replace( $this->get(), $input ); foreach ( [ 'latitude' => 90, 'longitude' => 180 ] as $field => $limit ) { $value = $data[ $field ]; if ( null !== $value && ( ( ! is_int( $value ) && ! is_float( $value ) ) || ! is_finite( (float) $value ) || abs( $value ) > $limit ) ) { CatalogValidator::invalid( $field, __( 'A coordinate within the allowed range is required.', 'abece-booking' ) ); } } if ( ( null === $data['latitude'] ) !== ( null === $data['longitude'] ) ) { CatalogValidator::invalid( 'location', __( 'Set both latitude and longitude, or clear both.', 'abece-booking' ) ); } if ( array_key_exists( 'address', $data ) ) { if ( ! is_string( $data['address'] ) || mb_strlen( $data['address'] ) > 255 ) { CatalogValidator::invalid( 'address', __( 'Enter the venue street, town and country.', 'abece-booking' ) ); } $data['address'] = trim( sanitize_text_field( $data['address'] ) ); } return $this->repository->save( $data ); } }