Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve connection messages #23

Merged
merged 5 commits into from
Feb 12, 2024
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
8 changes: 4 additions & 4 deletions omnisend/class-omnisend-core-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';

Expand Down Expand Up @@ -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',
);
}
}
Expand Down
48 changes: 34 additions & 14 deletions omnisend/includes/Internal/class-connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="notice notice-error"><p>The connection didn’t go through. Check if the API key is correct.</p></div>';
require_once __DIR__ . '/../../view/connection-form.html';
return;
}

if ( $response['verified'] === true && $response['platform'] !== wordpress_platform ) {
echo '<div class="notice notice-error"><p>This Omnisend account is already connected to non-WordPress site. Log in to access it.
<a target="_blank" href="https://www.omnisend.com/customer-support/">Contact our support</a> if you have other issues.</p></div>';
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 '<div class="notice notice-error"><p>API key is not valid.</p></div>';
echo '<div class="notice notice-error"><p>The connection didn’t go through. Check if the API key is correct.</p></div>';
}
}

Expand All @@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
}
}
8 changes: 6 additions & 2 deletions omnisend/readme.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading