Skip to content

Commit

Permalink
Merge pull request #28 from omnisend/misc/update-instruction-link
Browse files Browse the repository at this point in the history
Update instruction link & set cookie
  • Loading branch information
arnas authored Feb 28, 2024
2 parents ca92e48 + 4371188 commit 0e18024
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 46 deletions.
Binary file modified .wordpress-org/banner-1544x500.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/banner-772x250.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 18 additions & 8 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.3.1
* Version: 1.3.2
* 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.3.1';
const OMNISEND_CORE_PLUGIN_VERSION = '1.3.2';
const OMNISEND_CORE_SETTINGS_PAGE = 'omnisend';
const OMNISEND_CORE_PLUGIN_NAME = 'Email Marketing by Omnisend';

Expand All @@ -43,9 +43,10 @@

class Omnisend_Core_Bootstrap {


public static function load(): void {
// phpcs:ignore because linter could not detect internal, but it is fine
add_filter( 'cron_schedules', 'Omnisend_Core_Bootstrap::cron_schedules' ); // phpcs:ignore
add_filter('cron_schedules', 'Omnisend_Core_Bootstrap::cron_schedules'); // phpcs:ignore

add_action( 'admin_notices', 'Omnisend_Core_Bootstrap::admin_notices' );
add_action( 'admin_menu', 'Omnisend_Core_Bootstrap::add_admin_menu' );
Expand All @@ -55,11 +56,20 @@ public static function load(): void {

if ( ! self::is_omnisend_woocommerce_plugin_active() || ! self::is_omnisend_woocommerce_plugin_connected() ) {
add_action( 'wp_footer', 'Omnisend\Internal\Snippet::add' );
}

add_action( OMNISEND_CORE_CRON_SYNC_CONTACT, 'Omnisend\Internal\Sync::sync_contacts' );
add_action( 'user_register', 'Omnisend\Internal\Sync::hook_user_register' );
add_action( 'profile_update', 'Omnisend\Internal\Sync::hook_profile_update' );
add_action( 'user_register', 'Omnisend\Internal\Sync::identify_user_by_id' );
add_action(
'wp_login',
function ( $user_login, $user ) {
Omnisend\Internal\Sync::identify_user_by_id( $user->ID );
},
10,
2
);
add_action( 'profile_update', 'Omnisend\Internal\Sync::identify_user_by_id' );

add_action( OMNISEND_CORE_CRON_SYNC_CONTACT, 'Omnisend\Internal\Sync::sync_contacts' );
}
}

public static function add_admin_menu() {
Expand All @@ -84,7 +94,7 @@ public static function cron_schedules( $schedules ) {
}

public static function load_omnisend_admin_styles(): void {
// phpcs:disable WordPress.Security.NonceVerification
// phpcs:disable WordPress.Security.NonceVerification
if ( isset( $_GET['page'] ) ) {
if ( in_array( $_GET['page'], array( 'omnisend' ), true ) ) {
wp_enqueue_style(
Expand Down
7 changes: 7 additions & 0 deletions omnisend/includes/Internal/class-snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@

class Snippet {


public static function add() {
$brand_id = Options::get_brand_id();
if ( $brand_id ) {
require_once __DIR__ . '/../../view/snippet.html';
}
}

public static function set_contact_cookie_id( $contact_id ) {
$host = wp_parse_url( home_url(), PHP_URL_HOST );
$expiry = strtotime( '+1 year' );
setcookie( 'omnisendContactID', $contact_id, $expiry, '/', $host );
}
}
38 changes: 11 additions & 27 deletions omnisend/includes/Internal/class-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,18 @@
class Sync {

/**
* Listens for 'user_register' hook https://developer.wordpress.org/reference/hooks/user_register/
* Sync and sets omnisend contact id for user
*
* @param $user_id
* @return void
*/
public static function hook_user_register( $user_id ): void {
if ( \Omnisend_Core_Bootstrap::is_omnisend_woocommerce_plugin_connected() ) {
return; // do not sync if omni woo plugin is active.
}

$user = get_userdata( $user_id );
if ( $user ) {
self::sync_contact( $user );
}
}

/**
* Listens for 'profile_update' hook https://developer.wordpress.org/reference/hooks/profile_update/
*
* @param $user_id
* @return void
*/
public static function hook_profile_update( $user_id ): void {
if ( \Omnisend_Core_Bootstrap::is_omnisend_woocommerce_plugin_connected() ) {
return; // do not sync if omni woo plugin is active.
}

public static function identify_user_by_id( $user_id ): void {
$user = get_userdata( $user_id );
if ( $user ) {
self::sync_contact( $user );
$omnisend_contact_id = self::sync_contact( $user );
if ( $omnisend_contact_id ) {
Snippet::set_contact_cookie_id( $omnisend_contact_id );
}
}
}

Expand Down Expand Up @@ -79,15 +61,15 @@ public static function sync_contacts( int $limit = 100 ): void {

/**
* @param \WP_User $user
* @return void
* @return string
*/
private static function sync_contact( $user ): void {
private static function sync_contact( $user ): string {
$contact = new Contact();
$contact->add_tag( 'WordPress' );

if ( ! filter_var( $user->user_email, FILTER_VALIDATE_EMAIL ) ) {
UserMetaData::mark_sync_skipped( $user->ID );
return;
return '';
}

$contact->set_email( $user->user_email );
Expand Down Expand Up @@ -122,5 +104,7 @@ private static function sync_contact( $user ): void {
} else {
UserMetaData::mark_sync_error( $user->ID );
}

return $response->get_contact_id();
}
}
6 changes: 5 additions & 1 deletion omnisend/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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.3.1
Stable tag: 1.3.2
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.3.2 =

* Update link to Omnisend WP store connection flow, update banner

= 1.3.1 =

* Add message for WooCommerce plugin
Expand Down
8 changes: 4 additions & 4 deletions omnisend/view/connection-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ <h3 class="omnisend-h3">Steps to connect to Omnisend:</h3>
<div class="omnisend-grid-column">
<div class="omnisend-spacing-mv-1">
<p class="omnisend-paragraph-16">
Go to API keys section and create API key
Copy the API key from the platform connection instructions
</p>
</div>
<div class="omnisend-spacing-mt-4">
<a
class="omnisend-link-button"
target="_blank"
href="https://app.omnisend.com/integrations/api-keys/create"
href="https://app.omnisend.com/apps/connect-store/wordpress?source=wordpress%20plugin"
>
Go to API Keys</a
Go to connection instructions</a
>
</div>
</div>
Expand All @@ -125,7 +125,7 @@ <h3 class="omnisend-h3">Steps to connect to Omnisend:</h3>
<div class="omnisend-spacing-mr-4"></div>
<div class="omnisend-grid-column">
<div class="omnisend-spacing-mv-1">
<p class="omnisend-paragraph-16">Paste created API key here:</p>
<p class="omnisend-paragraph-16">Paste copied API key here:</p>
</div>
<div class="omnisend-spacing-mt-4">
<div class="omnisend-flex-row">
Expand Down

0 comments on commit 0e18024

Please sign in to comment.