Skip to content

Commit

Permalink
Load snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
nerijuszaniauskas committed Jan 3, 2024
1 parent 0d2b955 commit 37ca81b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions omnisend/class-omnisend-core-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

require_once 'module/class-omnisend-core-connection.php';
require_once 'module/class-omnisend-core-options.php';
require_once 'module/class-omnisend-core-snippet.php';

add_action( 'plugins_loaded', 'Omnisend_Core_Bootstrap::load' );
add_action( 'admin_notices', 'Omnisend_Core_Bootstrap::admin_notices' );
Expand All @@ -39,6 +40,7 @@ public static function load() {
}

add_action( 'admin_menu', 'Omnisend_Core_Bootstrap::add_admin_menu' );
add_action( 'wp_footer', 'Omnisend_Core_Snippet::add' );
}

public static function add_admin_menu() {
Expand Down
11 changes: 11 additions & 0 deletions omnisend/module/class-omnisend-core-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ public static function get_api_key(): string {
return is_string( $api_key ) ? $api_key : '';
}

public static function get_brand_id(): string {
$api_key = get_option( self::OPTION_API_KEY );
if ( ! is_string( $api_key ) ) {
return '';
}

$exploded = explode( '-', $api_key );

return count( $exploded ) == 2 ? $exploded[0] : '';
}

public static function set_api_key( $api_key ): bool {
if ( ! is_string( $api_key ) ) {
return false;
Expand Down
18 changes: 18 additions & 0 deletions omnisend/module/class-omnisend-core-snippet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Omnisend plugin
*
* @package OmnisendPlugin
*/

defined( 'ABSPATH' ) || exit;

class Omnisend_Core_Snippet {

public static function add() {
$brand_id = Omnisend_Core_Options::get_brand_id();
if ( $brand_id ) {
require_once 'view/snippet.html';
}
}
}
10 changes: 10 additions & 0 deletions omnisend/module/view/snippet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script type="text/javascript">
window.omnisend = window.omnisend || [];
omnisend.push(["accountID", "<?php echo $brand_id ?>"]);
omnisend.push(["track", "$pageViewed"]);
!function(){var e=document.createElement("script");
e.type="text/javascript",e.async=!0,
e.src="https://omnisnippet1.com/inshop/launcher-v2.js";
var t=document.getElementsByTagName("script")[0];
t.parentNode.insertBefore(e,t)}();
</script>

0 comments on commit 37ca81b

Please sign in to comment.