Ensure the API request data are string

In case an array was passed to an endpoint or token, there was a fatal error.
[MAILPOET-6348]
This commit is contained in:
Rostislav Wolny
2024-11-27 12:57:07 +01:00
committed by Aschepikov
parent ea6c705a97
commit d6d71c7cc3
2 changed files with 35 additions and 4 deletions

View File

@ -122,20 +122,20 @@ class API {
}
public function setRequestData($data, $requestType) {
$this->requestApiVersion = !empty($data['api_version']) ? $data['api_version'] : false;
$this->requestApiVersion = (!empty($data['api_version']) && is_string($data['api_version'])) ? $data['api_version'] : false;
$this->requestEndpoint = isset($data['endpoint'])
$this->requestEndpoint = (isset($data['endpoint']) && is_string($data['endpoint']))
? Helpers::underscoreToCamelCase(trim($data['endpoint']))
: null;
// JS part of /wp-admin/customize.php does not like a 'method' field in a form widget
$methodParamName = isset($data['mailpoet_method']) ? 'mailpoet_method' : 'method';
$this->requestMethod = isset($data[$methodParamName])
$this->requestMethod = (isset($data[$methodParamName]) && is_string($data[$methodParamName]))
? Helpers::underscoreToCamelCase(trim($data[$methodParamName]))
: null;
$this->requestType = $requestType;
$this->requestToken = isset($data['token'])
$this->requestToken = (isset($data['token']) && is_string($data['token']))
? trim($data['token'])
: null;