diff --git a/README.md b/README.md index db29aa9..49e6a76 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ You can find function references in the [client folder](https://github.com/omnis Before using Omnisend Client you need to ensure the following conditions: * Omnisend Plugin is installed `is_plugin_active( 'omnisend/class-omnisend-core-bootstrap.php' )` -* Omnisend Plugin is up to date `class_exists( 'Omnisend\Public\V1\Omnisend' )` -* Omnisend is connected to the WordPress `Omnisend\Public\V1\Omnisend::is_connected()` +* Omnisend Plugin is up to date `class_exists( 'Omnisend\SDK\V1\Omnisend' )` +* Omnisend is connected to account `Omnisend\SDK\V1\Omnisend::is_connected()` If any of these conditions are false you should ask to resolve them. @@ -36,7 +36,7 @@ To send contact to the Omnisend you need to provide your integration name & vers This is done by getting an actual client -` $client = \Omnisend\Public\V1\Omnisend::get_client( 'integration name', 'integration version' );` +` $client = \Omnisend\SDK\V1\Omnisend::get_client( 'integration name', 'integration version' );` 'integration name' - should be your integration name 'integration version' - should be your integration version @@ -64,7 +64,7 @@ Here is how you can create a basic client & submit contact. $contact->set_email_opt_in( 'where user opted to become subscriber' ); } - $client = \Omnisend\Public\V1\Omnisend::get_client( 'integration name', 'integration version' ); + $client = \Omnisend\SDK\V1\Omnisend::get_client( 'integration name', 'integration version' ); $response = $client->create_contact( $contact ); ``` @@ -74,15 +74,15 @@ Here is how you can create a basic client & submit contact. If data provided is invalid or creation fails, then ```php -$client->create_contact($contact) +$response = $client->create_contact($contact) ``` -Will return `errors` in `WP_Error`. Depending on your integration logic you should handle the error i.e +Will return `CreateContactResponse`. Depending on your integration logic you should handle the error i.e ```php - if ( is_wp_error( $response ) ) { - error_log( 'Error in after_submission: ' . $response->get_error_message()); - return; + if ( $response->get_wp_error()->has_errors() ) { + error_log( 'Error in after_submission: ' . $response->get_wp_error()->get_error_message()); + return; } ``` diff --git a/omnisend/class-omnisend-core-bootstrap.php b/omnisend/class-omnisend-core-bootstrap.php index 44d50ea..eb97a4e 100644 --- a/omnisend/class-omnisend-core-bootstrap.php +++ b/omnisend/class-omnisend-core-bootstrap.php @@ -4,7 +4,7 @@ * * Plugin Name: Omnisend * Description: Omnisend main plugin that enables integration with Omnisend. - * Version: 1.1.4 + * Version: 1.2.0 * Author: Omnisend * Author URI: https://www.omnisend.com * Developer: Omnisend @@ -22,7 +22,7 @@ defined( 'ABSPATH' ) || die( 'no direct access' ); -const OMNISEND_CORE_PLUGIN_VERSION = '1.1.4'; +const OMNISEND_CORE_PLUGIN_VERSION = '1.2.0'; const OMNISEND_CORE_SETTINGS_PAGE = 'omnisend'; const OMNISEND_CORE_PLUGIN_NAME = 'Email Marketing by Omnisend'; @@ -71,13 +71,13 @@ public static function load_omnisend_admin_styles(): void { 'roboto.css', plugin_dir_url( __FILE__ ) . 'assets/fonts/roboto/roboto.css?' . time(), array(), - '1.1.4', + OMNISEND_CORE_PLUGIN_VERSION, ); wp_enqueue_style( 'styles.css', plugin_dir_url( __FILE__ ) . 'styles/styles.css?' . time(), array(), - '1.1.4', + OMNISEND_CORE_PLUGIN_VERSION, ); } } diff --git a/omnisend/includes/Internal/V1/class-client.php b/omnisend/includes/Internal/V1/class-client.php index 4f70bbf..a3b9833 100644 --- a/omnisend/includes/Internal/V1/class-client.php +++ b/omnisend/includes/Internal/V1/class-client.php @@ -7,12 +7,13 @@ namespace Omnisend\Internal\V1; -use Omnisend\Public\V1\Contact; +use Omnisend\SDK\V1\Contact; +use Omnisend\SDK\V1\CreateContactResponse; use WP_Error; defined( 'ABSPATH' ) || die( 'no direct access' ); -class Client implements \Omnisend\Public\V1\Client { +class Client implements \Omnisend\SDK\V1\Client { private string $api_key; private string $plugin_name; @@ -30,19 +31,19 @@ public function __construct( string $api_key, string $plugin_name, string $plugi } - public function create_contact( $contact ): mixed { + public function create_contact( $contact ): CreateContactResponse { $error = new WP_Error(); if ( $contact instanceof Contact ) { $error->merge_from( $contact->validate() ); } else { - $error->add( 'contact', 'Contact is not instance of Omnisend\Public\V1\Contact.' ); + $error->add( 'contact', 'Contact is not instance of Omnisend\SDK\V1\Contact.' ); } $error->merge_from( $this->check_setup() ); if ( $error->has_errors() ) { - return $error; + return new CreateContactResponse( '', $error ); } $response = wp_remote_post( @@ -61,7 +62,7 @@ public function create_contact( $contact ): mixed { if ( is_wp_error( $response ) ) { error_log('wp_remote_post error: ' . $response->get_error_message()); // phpcs:ignore - return $response; + return new CreateContactResponse( '', $response ); } $http_code = wp_remote_retrieve_response_code( $response ); @@ -69,23 +70,23 @@ public function create_contact( $contact ): mixed { $body = wp_remote_retrieve_body( $response ); $err_msg = "HTTP error: {$http_code} - " . wp_remote_retrieve_response_message( $response ) . " - {$body}"; $error->add( 'omnisend_api', $err_msg ); - return $error; + return new CreateContactResponse( '', $error ); } $body = wp_remote_retrieve_body( $response ); if ( ! $body ) { $error->add( 'omnisend_api', 'empty response' ); - return $error; + return new CreateContactResponse( '', $error ); } $arr = json_decode( $body, true ); if ( empty( $arr['contactID'] ) ) { $error->add( 'omnisend_api', 'contactID not found in response.' ); - return $error; + return new CreateContactResponse( '', $error ); } - return (string) $arr['contactID']; + return new CreateContactResponse( (string) $arr['contactID'], $error ); } /** diff --git a/omnisend/includes/Internal/class-connection.php b/omnisend/includes/Internal/class-connection.php index 35641eb..0e43b4c 100644 --- a/omnisend/includes/Internal/class-connection.php +++ b/omnisend/includes/Internal/class-connection.php @@ -30,7 +30,7 @@ public static function display(): void { return; } - if ( $response['verified'] === true && $response['platform'] !== wordpress_platform ) { + if ( $response['verified'] === true && $response['platform'] !== $wordpress_platform ) { echo '
This Omnisend account is already connected to non-WordPress site. Log in to access it. Contact our support if you have other issues.