diff --git a/omnisend/class-omnisend-core-bootstrap.php b/omnisend/class-omnisend-core-bootstrap.php index 0d9d084..44d50ea 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.3 + * Version: 1.1.4 * 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.0.0'; +const OMNISEND_CORE_PLUGIN_VERSION = '1.1.4'; 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.3', + '1.1.4', ); wp_enqueue_style( 'styles.css', plugin_dir_url( __FILE__ ) . 'styles/styles.css?' . time(), array(), - '1.1.3', + '1.1.4', ); } } diff --git a/omnisend/includes/Internal/class-connection.php b/omnisend/includes/Internal/class-connection.php index b37d792..35641eb 100644 --- a/omnisend/includes/Internal/class-connection.php +++ b/omnisend/includes/Internal/class-connection.php @@ -15,26 +15,46 @@ class Connection { public static function display(): void { $connected = Options::is_store_connected(); + // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText + $wordpress_platform = 'wordpress'; if ( ! $connected && ! empty( $_POST['action'] ) && 'connect' == $_POST['action'] && ! empty( $_POST['api_key'] ) ) { check_admin_referer( 'connect' ); $api_key = sanitize_text_field( wp_unslash( $_POST['api_key'] ) ); - $brand_id = self::get_brand_id( $api_key ); + $response = self::get_account_data( $api_key ); + $brand_id = $response['brandID']; - if ( $brand_id ) { - // Set credentials so snippet can be added for snippet verification. - Options::set_api_key( $api_key ); - Options::set_brand_id( $brand_id ); + if ( ! $brand_id ) { + echo '

The connection didn’t go through. Check if the API key is correct.

'; + require_once __DIR__ . '/../../view/connection-form.html'; + return; + } + 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.

'; + require_once __DIR__ . '/../../view/connection-form.html'; + return; + } + + $connected = false; + if ( $response['platform'] === wordpress_platform ) { + $connected = true; + } + + if ( $response['platform'] === '' ) { $connected = self::connect_store( $api_key ); - if ( $connected ) { - Options::set_store_connected(); - } + } + + if ( $connected ) { + Options::set_api_key( $api_key ); + Options::set_brand_id( $brand_id ); + Options::set_store_connected(); } if ( ! $connected ) { Options::disconnect(); // Store was not connected, clean up. - echo '

API key is not valid.

'; + echo '

The connection didn’t go through. Check if the API key is correct.

'; } } @@ -46,7 +66,7 @@ public static function display(): void { require_once __DIR__ . '/../../view/connection-success.html'; } - private static function get_brand_id( $api_key ): string { + private static function get_account_data( $api_key ): array { $response = wp_remote_get( OMNISEND_CORE_API_V3 . '/accounts', array( @@ -65,7 +85,7 @@ private static function get_brand_id( $api_key ): string { $arr = json_decode( $body, true ); - return is_array( $arr ) && ! empty( $arr['brandID'] ) && is_string( $arr['brandID'] ) ? $arr['brandID'] : ''; + return is_array( $arr ) ? $arr : array(); } private static function connect_store( $api_key ): bool { @@ -122,13 +142,13 @@ public static function connect_with_omnisend_for_woo_plugin(): void { return; } - $brand_id = self::get_brand_id( $api_key ); - if ( ! $brand_id ) { + $response = self::get_account_data( $api_key ); + if ( ! $response['brandID'] ) { return; } Options::set_api_key( $api_key ); - Options::set_brand_id( $brand_id ); + Options::set_brand_id( $response['brandID'] ); Options::set_store_connected(); } } diff --git a/omnisend/readme.txt b/omnisend/readme.txt index bfbb7ea..3f826cb 100644 --- a/omnisend/readme.txt +++ b/omnisend/readme.txt @@ -1,11 +1,11 @@ === Email Marketing by Omnisend === Plugin Name: Email Marketing by Omnisend Contributors: Omnisend -Tags: form, email marketing, web tracking, subscriber collection +Tags: email marketing, marketing, newsletter, sms, form Requires at least: 4.7.0 Tested up to: 6.4 Requires PHP: 7.1 -Stable tag: 1.1.3 +Stable tag: 1.1.4 License: GPLv3 or later URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -54,6 +54,10 @@ Read Omnisend [Terms of Use](https://www.omnisend.com/terms) == Changelog == += 1.1.4 = + +* Improve connection messages + = 1.1.3 = * Update build process