Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Validate the custom social field value with the BankID API
- * @param bool $isValid
- * @param GeminiLabs\SiteReviews\Request $request
- * @return bool|string
- */
- add_filter('site-reviews/validate/custom', function ($isValid, $request) {
- $apiResponse = wp_remote_post('https://api.banksignering.se/api/auth', [
- 'body' => [
- 'apiUser' => 'xxx',
- 'password' => 'yyy',
- 'companyApiGuid' => 'zzz',
- 'personalNumber' => $request->social,
- 'endUserIp' => $request->ip_address,
- ],
- ]);
- if (is_wp_error($apiResponse)) {
- // WordPress encountered an error when making the API request.
- // You can either return the WordPress error message here,
- // or return a custom validation error message
- return $apiResponse->get_message();
- }
- // Get the response body of the API request
- $apiResponseBody = json_decode($apiResponse['body']);
- if (wp_validate_boolean(glsr_get($apiResponseBody, 'authResponse.Success'))) {
- return true; // validation was successful!
- }
- // The API request returned an error, so return an appropriate
- // validation error message here
- return 'BankID validation failed, please check your social number.';
- }, 10, 2);
- /**
- * Remove the submitted custom social field value before the review is saved
- * @param array $values
- * @return array
- */
- add_filter('site-reviews/create/review-values', function ($values) {
- if (isset($values['custom']['social'])) {
- // Replace the submitted social security value
- $values['custom']['social'] = 'Validated with BankID';
- $values['request']->set('social', 'Validated with BankID');
- }
- return $values;
- });
Add Comment
Please, Sign In to add comment