Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions forms-bridge/addons/brevo/class-brevo-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,42 +138,22 @@ function ( $path ) {
* @return array
*/
public function get_endpoint_schema( $endpoint, $backend, $method = null ) {
$bytes = random_bytes( 16 );
$bytes[6] = chr( ord( $bytes[6] ) & 0x0f | 0x40 );
$bytes[8] = chr( ord( $bytes[8] ) & 0x3f | 0x80 );
$uuid = vsprintf( '%s%s-%s-%s-%s-%s%s%s', str_split( bin2hex( $bytes ), 4 ) );
if ( ! function_exists( 'yaml_parse' ) ) {
return array();
}

$response = wp_remote_get(
self::OAS_URL,
array(
'headers' => array(
'Accept' => 'application/json',
'Host' => 'developers.brevo.com',
'Referer' => 'https://developers.brevo.com/reference/get_companies',
'Alt-Used' => 'developers.brevo.com',
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0',
'X-Requested-With' => 'XMLHttpRequest',
),
'cookies' => array(
'anonymous_id' => $uuid,
'first_referrer' => 'https://app.brevo.com/',
'pscd' => 'get.brevo.com',
'readme_language' => 'shell',
'readme_library' => '{%22shell%22:%22curl%22}',
),
)
);
$response = wp_remote_get( self::OAS_URL );

if ( is_wp_error( $response ) ) {
return array();
}

$data = json_decode( $response['body'], true );
$data = yaml_parse( $response['body'] );
if ( ! $data ) {
return array();
}

$oa_explorer = new OpenAPI( $data['oasDefinition'] );
$oa_explorer = new OpenAPI( $data );

$method = strtolower( $method ?? 'post' );
$path = preg_replace( '/^\/v\d+/', '', $endpoint );
Expand Down
7 changes: 2 additions & 5 deletions forms-bridge/addons/listmonk/class-listmonk-form-bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ public function submit( $payload = array(), $attachments = array() ) {
$error_response = $response->get_error_data()['response'] ?? null;

$code = $error_response['response']['code'] ?? null;
if ( $code !== 409 ) {
if ( 409 !== $code ) {
return $response;
}

if (
! isset( $payload['email'] ) ||
$this->endpoint !== '/api/subscribers'
) {
if ( ! isset( $payload['email'] ) || '/api/subscribers' !== $this->endpoint ) {
return $response;
}

Expand Down
16 changes: 4 additions & 12 deletions forms-bridge/addons/mailchimp/class-mailchimp-form-bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ public function submit( $payload = array(), $attachments = array() ) {
}

if ( 'Member Exists' === $title ) {
if (
! preg_match(
'/(?<=lists\/).+(?=\/members)/',
$this->endpoint,
$matches
)
) {
if ( ! preg_match( '/(?<=lists\/).+(?=\/members)/', $this->endpoint, $matches ) ) {
return $response;
}

Expand All @@ -84,17 +78,15 @@ public function submit( $payload = array(), $attachments = array() ) {
return $response;
}

$member_id =
$search_response['data']['exact_matches']['members'][0]['id'] ?? null;
$member_id = $search_response['data']['exact_matches']['members'][0]['id'] ?? null;

if ( ! $member_id ) {
return $response;
}

$update_endpoint = "/3.0/lists/{$list_id}/members/{$member_id}";
if (
strstr( $this->endpoint, 'skip_merge_validation' ) !== false
) {

if ( false !== strstr( $this->endpoint, 'skip_merge_validation' ) ) {
$update_endpoint .= '?skip_merge_validation=true';
}

Expand Down
3 changes: 2 additions & 1 deletion forms-bridge/addons/zoho/class-zoho-form-bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ function ( $headers, $backend ) {
if ( ! $backend ) {
return new WP_Error(
'invalid_backend',
'The bridge does not have a valid backend'
'The bridge does not have a valid backend',
(array) $this->data,
);
}

Expand Down
6 changes: 5 additions & 1 deletion forms-bridge/includes/class-form-bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ public function submit( $payload = array(), $attachments = array() ) {

$backend = $this->backend();
if ( ! $backend ) {
return new WP_Error( 'invalid_bridge' );
return new WP_Error(
'invalid_backend',
'The bridge does not have a valid backend',
(array) $this->data,
);
}

$method = $this->method;
Expand Down
Loading