diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..4034311
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1 @@
+.wordpress
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 0000000..684b5fd
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1 @@
+* @omnisend/integrations
diff --git a/.github/workflows/release-plugin.yml b/.github/workflows/release-plugin.yml
new file mode 100644
index 0000000..d7a32ef
--- /dev/null
+++ b/.github/workflows/release-plugin.yml
@@ -0,0 +1,16 @@
+name: Release plugin
+
+on: [workflow_dispatch]
+jobs:
+ svn:
+ name: Release new tag
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@main
+ - name: WordPress Plugin Deploy
+ uses: omnisend/action-wordpress-plugin-deploy@v1.0.3
+ env:
+ SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
+ SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
+ SLUG: omnisend-for-gravity-forms-add-on
+ BUILD_DIR: omnisend-for-gravity-forms
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..06b0cc5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,24 @@
+ woocommerce-omnisend/.vscode/*
+.vscode/*
+.idea/*
+.svn
+
+# These are needed when repo is checked out at the location of working WordPress site
+.DS_Store
+akismet/
+hello.php
+index.php
+klaviyo
+mailchimp-for-woocommerce
+woocommerce
+wp-crontrol
+code-snippets
+
+# Composer
+composer.phar
+/vendor/
+# Local wordpress setup
+.wordpress
+.env
+
+*.zip
diff --git a/.phpcs.xml b/.phpcs.xml
new file mode 100644
index 0000000..97269a4
--- /dev/null
+++ b/.phpcs.xml
@@ -0,0 +1,16 @@
+
+
+
+ *.js
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.prettierrc.yml b/.prettierrc.yml
new file mode 100644
index 0000000..19a117c
--- /dev/null
+++ b/.prettierrc.yml
@@ -0,0 +1,5 @@
+tabWidth: 4
+printWidth: 140
+singleQuote: true
+trailingComma: none
+bracketSpacing: true
diff --git a/.wordpress-org/banner-1544x500.png b/.wordpress-org/banner-1544x500.png
new file mode 100755
index 0000000..6098f15
Binary files /dev/null and b/.wordpress-org/banner-1544x500.png differ
diff --git a/.wordpress-org/banner-772x250.png b/.wordpress-org/banner-772x250.png
new file mode 100755
index 0000000..0525ef7
Binary files /dev/null and b/.wordpress-org/banner-772x250.png differ
diff --git a/.wordpress-org/icon-256x256.gif b/.wordpress-org/icon-256x256.gif
new file mode 100644
index 0000000..9425f4f
Binary files /dev/null and b/.wordpress-org/icon-256x256.gif differ
diff --git a/.wordpress-org/screenshot-1.gif b/.wordpress-org/screenshot-1.gif
new file mode 100644
index 0000000..2b02c06
Binary files /dev/null and b/.wordpress-org/screenshot-1.gif differ
diff --git a/.wordpress-org/screenshot-2.png b/.wordpress-org/screenshot-2.png
new file mode 100644
index 0000000..d21f49e
Binary files /dev/null and b/.wordpress-org/screenshot-2.png differ
diff --git a/.wordpress-org/screenshot-3.png b/.wordpress-org/screenshot-3.png
new file mode 100644
index 0000000..3726d52
Binary files /dev/null and b/.wordpress-org/screenshot-3.png differ
diff --git a/.wordpress-org/screenshot-4.png b/.wordpress-org/screenshot-4.png
new file mode 100644
index 0000000..ce369a9
Binary files /dev/null and b/.wordpress-org/screenshot-4.png differ
diff --git a/.wordpress-org/screenshot-5.png b/.wordpress-org/screenshot-5.png
new file mode 100644
index 0000000..eb713be
Binary files /dev/null and b/.wordpress-org/screenshot-5.png differ
diff --git a/.wordpress-org/screenshot-6.png b/.wordpress-org/screenshot-6.png
new file mode 100644
index 0000000..60aff8d
Binary files /dev/null and b/.wordpress-org/screenshot-6.png differ
diff --git a/.wordpress-org/screenshot-7.png b/.wordpress-org/screenshot-7.png
new file mode 100644
index 0000000..f6c7b07
Binary files /dev/null and b/.wordpress-org/screenshot-7.png differ
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3bcb868
--- /dev/null
+++ b/README.md
@@ -0,0 +1,7 @@
+# Omnisend Add-on for Gravity Forms WordPress plugin
+
+Plugin (Add-On) for Gravity forms Wordpress plugin.
+
+More information can be found [here](https://docs.gravityforms.com/category/developers/php-api/add-on-framework/).
+
+Link to plugin in Wordpress app store: [link](https://wordpress.org/plugins/omnisend-for-gravity-forms-add-on/).
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..1fc1ebb
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,16 @@
+{
+ "name": "omnisend/gravity-forms-addon",
+ "description": "Omnisend for Gravity Forms Add-on",
+ "license": "proprietary",
+ "config": {
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": true
+ }
+ },
+ "require-dev": {
+ "php": ">=7.1.0",
+ "wp-coding-standards/wpcs": "^3.0",
+ "squizlabs/php_codesniffer": "^3.7.1",
+ "dealerdirect/phpcodesniffer-composer-installer": "^1.0"
+ }
+}
diff --git a/composer.lock b/composer.lock
new file mode 100644
index 0000000..bed8850
--- /dev/null
+++ b/composer.lock
@@ -0,0 +1,411 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "0eb877a42946a4262f219df95629c6fd",
+ "packages": [],
+ "packages-dev": [
+ {
+ "name": "dealerdirect/phpcodesniffer-composer-installer",
+ "version": "v1.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/PHPCSStandards/composer-installer.git",
+ "reference": "4be43904336affa5c2f70744a348312336afd0da"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da",
+ "reference": "4be43904336affa5c2f70744a348312336afd0da",
+ "shasum": ""
+ },
+ "require": {
+ "composer-plugin-api": "^1.0 || ^2.0",
+ "php": ">=5.4",
+ "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0"
+ },
+ "require-dev": {
+ "composer/composer": "*",
+ "ext-json": "*",
+ "ext-zip": "*",
+ "php-parallel-lint/php-parallel-lint": "^1.3.1",
+ "phpcompatibility/php-compatibility": "^9.0",
+ "yoast/phpunit-polyfills": "^1.0"
+ },
+ "type": "composer-plugin",
+ "extra": {
+ "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin"
+ },
+ "autoload": {
+ "psr-4": {
+ "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Franck Nijhof",
+ "email": "franck.nijhof@dealerdirect.com",
+ "homepage": "http://www.frenck.nl",
+ "role": "Developer / IT Manager"
+ },
+ {
+ "name": "Contributors",
+ "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors"
+ }
+ ],
+ "description": "PHP_CodeSniffer Standards Composer Installer Plugin",
+ "homepage": "http://www.dealerdirect.com",
+ "keywords": [
+ "PHPCodeSniffer",
+ "PHP_CodeSniffer",
+ "code quality",
+ "codesniffer",
+ "composer",
+ "installer",
+ "phpcbf",
+ "phpcs",
+ "plugin",
+ "qa",
+ "quality",
+ "standard",
+ "standards",
+ "style guide",
+ "stylecheck",
+ "tests"
+ ],
+ "support": {
+ "issues": "https://github.com/PHPCSStandards/composer-installer/issues",
+ "source": "https://github.com/PHPCSStandards/composer-installer"
+ },
+ "time": "2023-01-05T11:28:13+00:00"
+ },
+ {
+ "name": "phpcsstandards/phpcsextra",
+ "version": "1.2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/PHPCSStandards/PHPCSExtra.git",
+ "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489",
+ "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4",
+ "phpcsstandards/phpcsutils": "^1.0.9",
+ "squizlabs/php_codesniffer": "^3.8.0"
+ },
+ "require-dev": {
+ "php-parallel-lint/php-console-highlighter": "^1.0",
+ "php-parallel-lint/php-parallel-lint": "^1.3.2",
+ "phpcsstandards/phpcsdevcs": "^1.1.6",
+ "phpcsstandards/phpcsdevtools": "^1.2.1",
+ "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
+ },
+ "type": "phpcodesniffer-standard",
+ "extra": {
+ "branch-alias": {
+ "dev-stable": "1.x-dev",
+ "dev-develop": "1.x-dev"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "LGPL-3.0-or-later"
+ ],
+ "authors": [
+ {
+ "name": "Juliette Reinders Folmer",
+ "homepage": "https://github.com/jrfnl",
+ "role": "lead"
+ },
+ {
+ "name": "Contributors",
+ "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors"
+ }
+ ],
+ "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.",
+ "keywords": [
+ "PHP_CodeSniffer",
+ "phpcbf",
+ "phpcodesniffer-standard",
+ "phpcs",
+ "standards",
+ "static analysis"
+ ],
+ "support": {
+ "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues",
+ "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy",
+ "source": "https://github.com/PHPCSStandards/PHPCSExtra"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/PHPCSStandards",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/jrfnl",
+ "type": "github"
+ },
+ {
+ "url": "https://opencollective.com/php_codesniffer",
+ "type": "open_collective"
+ }
+ ],
+ "time": "2023-12-08T16:49:07+00:00"
+ },
+ {
+ "name": "phpcsstandards/phpcsutils",
+ "version": "1.0.9",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/PHPCSStandards/PHPCSUtils.git",
+ "reference": "908247bc65010c7b7541a9551e002db12e9dae70"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/908247bc65010c7b7541a9551e002db12e9dae70",
+ "reference": "908247bc65010c7b7541a9551e002db12e9dae70",
+ "shasum": ""
+ },
+ "require": {
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0",
+ "php": ">=5.4",
+ "squizlabs/php_codesniffer": "^3.8.0 || 4.0.x-dev@dev"
+ },
+ "require-dev": {
+ "ext-filter": "*",
+ "php-parallel-lint/php-console-highlighter": "^1.0",
+ "php-parallel-lint/php-parallel-lint": "^1.3.2",
+ "phpcsstandards/phpcsdevcs": "^1.1.6",
+ "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0"
+ },
+ "type": "phpcodesniffer-standard",
+ "extra": {
+ "branch-alias": {
+ "dev-stable": "1.x-dev",
+ "dev-develop": "1.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "PHPCSUtils/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "LGPL-3.0-or-later"
+ ],
+ "authors": [
+ {
+ "name": "Juliette Reinders Folmer",
+ "homepage": "https://github.com/jrfnl",
+ "role": "lead"
+ },
+ {
+ "name": "Contributors",
+ "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors"
+ }
+ ],
+ "description": "A suite of utility functions for use with PHP_CodeSniffer",
+ "homepage": "https://phpcsutils.com/",
+ "keywords": [
+ "PHP_CodeSniffer",
+ "phpcbf",
+ "phpcodesniffer-standard",
+ "phpcs",
+ "phpcs3",
+ "standards",
+ "static analysis",
+ "tokens",
+ "utility"
+ ],
+ "support": {
+ "docs": "https://phpcsutils.com/",
+ "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues",
+ "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy",
+ "source": "https://github.com/PHPCSStandards/PHPCSUtils"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/PHPCSStandards",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/jrfnl",
+ "type": "github"
+ },
+ {
+ "url": "https://opencollective.com/php_codesniffer",
+ "type": "open_collective"
+ }
+ ],
+ "time": "2023-12-08T14:50:00+00:00"
+ },
+ {
+ "name": "squizlabs/php_codesniffer",
+ "version": "3.8.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git",
+ "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7",
+ "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7",
+ "shasum": ""
+ },
+ "require": {
+ "ext-simplexml": "*",
+ "ext-tokenizer": "*",
+ "ext-xmlwriter": "*",
+ "php": ">=5.4.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
+ },
+ "bin": [
+ "bin/phpcs",
+ "bin/phpcbf"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.x-dev"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Greg Sherwood",
+ "role": "Former lead"
+ },
+ {
+ "name": "Juliette Reinders Folmer",
+ "role": "Current lead"
+ },
+ {
+ "name": "Contributors",
+ "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors"
+ }
+ ],
+ "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
+ "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer",
+ "keywords": [
+ "phpcs",
+ "standards",
+ "static analysis"
+ ],
+ "support": {
+ "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues",
+ "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy",
+ "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer",
+ "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/PHPCSStandards",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/jrfnl",
+ "type": "github"
+ },
+ {
+ "url": "https://opencollective.com/php_codesniffer",
+ "type": "open_collective"
+ }
+ ],
+ "time": "2023-12-08T12:32:31+00:00"
+ },
+ {
+ "name": "wp-coding-standards/wpcs",
+ "version": "3.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/WordPress/WordPress-Coding-Standards.git",
+ "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b4caf9689f1a0e4a4c632679a44e638c1c67aff1",
+ "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1",
+ "shasum": ""
+ },
+ "require": {
+ "ext-filter": "*",
+ "ext-libxml": "*",
+ "ext-tokenizer": "*",
+ "ext-xmlreader": "*",
+ "php": ">=5.4",
+ "phpcsstandards/phpcsextra": "^1.1.0",
+ "phpcsstandards/phpcsutils": "^1.0.8",
+ "squizlabs/php_codesniffer": "^3.7.2"
+ },
+ "require-dev": {
+ "php-parallel-lint/php-console-highlighter": "^1.0.0",
+ "php-parallel-lint/php-parallel-lint": "^1.3.2",
+ "phpcompatibility/php-compatibility": "^9.0",
+ "phpcsstandards/phpcsdevtools": "^1.2.0",
+ "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
+ },
+ "suggest": {
+ "ext-iconv": "For improved results",
+ "ext-mbstring": "For improved results"
+ },
+ "type": "phpcodesniffer-standard",
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Contributors",
+ "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors"
+ }
+ ],
+ "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
+ "keywords": [
+ "phpcs",
+ "standards",
+ "static analysis",
+ "wordpress"
+ ],
+ "support": {
+ "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues",
+ "source": "https://github.com/WordPress/WordPress-Coding-Standards",
+ "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki"
+ },
+ "funding": [
+ {
+ "url": "https://opencollective.com/thewpcc/contribute/wp-php-63406",
+ "type": "custom"
+ }
+ ],
+ "time": "2023-09-14T07:06:09+00:00"
+ }
+ ],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": {
+ "php": ">=7.1.0"
+ },
+ "plugin-api-version": "2.6.0"
+}
diff --git a/lint.sh b/lint.sh
new file mode 100755
index 0000000..673b976
--- /dev/null
+++ b/lint.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+alias composer='docker run --rm -it -v "$(pwd):/app" composer/composer'
+
+action=$1
+
+case $action in
+"check")
+ composer update
+ composer install
+ ./vendor/bin/phpcs -s omnisend-for-gravity-forms
+ ;;
+"fix")
+ composer update
+ composer install
+ ./vendor/bin/phpcbf omnisend-for-gravity-forms
+ ;;
+*)
+ echo "pass one of these argument: check,fix"
+ exit 1
+ ;;
+esac
diff --git a/omnisend-for-gravity-forms/class-omnisend-addon-bootstrap.php b/omnisend-for-gravity-forms/class-omnisend-addon-bootstrap.php
new file mode 100644
index 0000000..dedcb15
--- /dev/null
+++ b/omnisend-for-gravity-forms/class-omnisend-addon-bootstrap.php
@@ -0,0 +1,39 @@
+ array(
+ 'omnisend-connect/omnisend-woocommerce.php',
+ ),
+ array( $this, 'omnisend_api_key_existence' ),
+ );
+ }
+
+ public function omnisend_api_key_existence( $meets_requirements ) {
+ $api_key = get_option( 'omnisend_api_key', null );
+ if ( is_null( $api_key ) ) {
+ $meets_requirements['meets_requirements'] = false;
+ $meets_requirements['errors'][] = 'Your Email Marketing for WooCommerce by Omnisend is not configured properly. Please configure it firstly';
+ }
+ return $meets_requirements;
+ }
+
+ /**
+ * Get an instance of this class.
+ *
+ * @return OmnisendAddOn
+ */
+ public static function get_instance() {
+ if ( self::$_instance == null ) {
+ self::$_instance = new OmnisendAddOn();
+ }
+
+ return self::$_instance;
+ }
+
+ /**
+ * Handles hooks and loading of language files.
+ */
+ public function init() {
+ parent::init();
+ add_action( 'gform_after_submission', array( $this, 'after_submission' ), 10, 2 );
+ }
+
+
+ public function get_form_fields() {
+ $form = $this->get_current_form();
+ $all_fields = array();
+ $consent_fields = array();
+
+ foreach ( $form['fields'] as $field ) {
+ $inputs = $field->get_entry_inputs();
+
+ if ( $inputs ) {
+ $choices = array();
+
+ foreach ( $inputs as $input ) {
+ if ( rgar( $input, 'isHidden' ) ) {
+ continue;
+ }
+ $choices[] = array(
+ 'value' => $input['id'],
+ 'label' => GFCommon::get_label( $field, $input['id'], true ),
+ );
+ }
+
+ if ( ! empty( $choices ) ) {
+ $all_fields[] = array(
+ 'choices' => $choices,
+ 'label' => GFCommon::get_label( $field ),
+ );
+ }
+
+ if ( $field->type === 'consent' ) {
+ $consent_fields[] = array(
+ 'choices' => $choices,
+ 'label' => GFCommon::get_label( $field ),
+ );
+ }
+ } else {
+ $all_fields[] = array(
+ 'value' => $field->id,
+ 'label' => GFCommon::get_label( $field ),
+ );
+
+ if ( $field->type === 'consent' ) {
+ $consent_fields[] = array(
+ 'value' => $field->id,
+ 'label' => GFCommon::get_label( $field ),
+ );
+ }
+ }
+ }
+
+ return array(
+ 'allFields' => $all_fields,
+ 'consentFields' => $consent_fields,
+ );
+ }
+
+ public function form_settings_fields( $form ) {
+ $fields_data = $this->get_form_fields();
+ $all_fields = $fields_data['allFields'];
+ $consent_fields = $fields_data['consentFields'];
+
+ $choices[] = array(
+ 'value' => '-1',
+ 'label' => 'Choose Field',
+ );
+
+ $all_fields_choices = array_merge( $choices, $all_fields );
+ $consent_fields_choices = array_merge( $choices, $consent_fields );
+
+ return array(
+ array(
+ 'title' => esc_html__( 'Welcome Email', 'omnisend-for-gravity-forms-add-on' ),
+ 'fields' => array(
+ array(
+ 'label' => esc_html__( 'Check this to automatically send your custom welcome email, created in Omnisend, to subscribers joining through Gravity Forms.', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'checkbox',
+ 'name' => 'send_welcome_email_checkbox',
+ 'choices' => array(
+ array(
+ 'label' => esc_html__( 'Send a welcome email to new subscribers', 'omnisend-for-gravity-forms-add-on' ),
+ 'name' => 'send_welcome_email',
+ ),
+ ),
+ ),
+ array(
+ 'type' => 'welcome_automation_details',
+ 'name' => 'welcome_automation_details',
+ ),
+ ),
+ ),
+ array(
+ 'title' => esc_html__( 'Omnisend Field Mapping', 'omnisend-for-gravity-forms-add-on' ),
+
+ 'fields' => array(
+ array(
+ 'type' => 'field_mapping_details',
+ 'name' => 'field_mapping_details',
+ ),
+ array(
+ 'label' => esc_html__( 'Email', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'email',
+ 'validation_callback' => function ( $field, $value ) {
+ if ( $value <= 0 ) {
+ $field->set_error( esc_html__( 'Email is required', 'omnisend-for-gravity-forms-add-on' ) );
+ }
+ },
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'Address', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'address',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'City', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'city',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'State', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'state',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'Country', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'country',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'First Name', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'first_name',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'Last Name', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'last_name',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'Phone Number', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'phone_number',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'Birthday', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'birthday',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'Postal Code', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'postal_code',
+ 'choices' => $all_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'Email Consent', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'email_consent',
+ 'choices' => $consent_fields_choices,
+ ),
+ array(
+ 'label' => esc_html__( 'Phone Consent', 'omnisend-for-gravity-forms-add-on' ),
+ 'type' => 'select',
+ 'name' => 'phone_consent',
+ 'choices' => $consent_fields_choices,
+ ),
+
+ ),
+ ),
+ );
+ }
+
+
+
+ /**
+ * Performing a custom action at the end of the form submission process.
+ *
+ * @param array $entry The entry currently being processed.
+ * @param array $form The form currently being processed.
+ */
+ public function after_submission( $entry, $form ) {
+ if ( ! is_plugin_active( 'omnisend-connect/omnisend-woocommerce.php' ) ) {
+ return;
+ }
+
+ try {
+ $settings = $this->get_form_settings( $form );
+ $email_consent = 'nonSubscribed';
+ $phone_consent = 'nonSubscribed';
+
+ $consent_object = array(
+ 'source' => 'gravity-forms',
+ 'createdAt' => gmdate( 'c' ),
+ 'ip' => $entry['ip'],
+ 'userAgent' => $entry['user_agent'],
+ );
+
+ $fields_to_process = array(
+ 'email',
+ 'address',
+ 'country',
+ 'city',
+ 'state',
+ 'first_name',
+ 'last_name',
+ 'birthday',
+ 'phone_number',
+ 'postal_code',
+ 'email_consent',
+ 'phone_consent',
+ );
+
+ $email = '';
+ $phone_number = '';
+ $postal_code = '';
+ $address = '';
+ $country = '';
+ $city = '';
+ $state = '';
+ $first_name = '';
+ $last_name = '';
+ $birthday = '';
+
+ foreach ( $fields_to_process as $field ) {
+
+ if ( isset( $settings[ $field ] ) && $settings[ $field ] != '-1' ) {
+ if ( in_array( $field, array( 'email_consent', 'phone_consent' ) ) ) {
+ if ( $entry[ $settings[ $field ] ] == '1' ) {
+ ${$field} = 'subscribed';
+ }
+ } else {
+ ${$field} = $entry[ $settings[ $field ] ];
+ }
+ }
+ }
+
+ $identifiers = array();
+ if ( $email != '' ) {
+ $email_identifier = array(
+ 'type' => 'email',
+ 'channels' => array(
+ 'email' => array(
+ 'status' => $email_consent,
+ 'statusDate' => gmdate( 'c' ),
+ ),
+ ),
+ 'id' => $email,
+ );
+
+ if ( $email_consent == 'subscribed' ) {
+ $email_identifier['consent'] = $consent_object;
+ }
+ array_push( $identifiers, $email_identifier );
+ } else {
+ error_log( 'Email is not mapped. Skipping Omnisend contact creation.' );
+ return;
+ }
+
+ if ( $phone_number != '' ) {
+ $phone_identifier = array(
+ 'type' => 'phone',
+ 'channels' => array(
+ 'sms' => array(
+ 'status' => $phone_consent,
+ 'statusDate' => gmdate( 'c' ),
+ ),
+ ),
+ 'id' => $phone_number,
+ );
+ if ( $phone_consent == 'subscribed' ) {
+ $phone_identifier['consent'] = $consent_object;
+ }
+
+ array_push( $identifiers, $phone_identifier );
+ }
+
+ $data = array( 'identifiers' => $identifiers );
+ $fields_to_data_keys = array(
+ 'first_name' => 'firstName',
+ 'last_name' => 'lastName',
+ 'birthday' => 'birthdate',
+ 'postal_code' => 'postalCode',
+ 'address' => 'address',
+ 'state' => 'state',
+ 'country' => 'country',
+ 'city' => 'city',
+ 'send_welcome_email' => 'sendWelcomeEmail',
+ );
+
+ foreach ( $fields_to_data_keys as $variable => $data_key ) {
+ if ( ! empty( $$variable ) ) {
+ $data[ $data_key ] = $$variable;
+ }
+ }
+
+ $form_name = preg_replace( '/[^A-Za-z0-9\-]/', '', $form['title'] );
+ $data['tags'] = array( 'gravity_forms', 'gravity_forms ' . $form_name );
+
+ if (
+ isset( $settings['send_welcome_email'] ) &&
+ $settings['send_welcome_email'] == '1'
+ ) {
+ $data['sendWelcomeEmail'] = true;
+ }
+
+ $custom_properties = $this->mapCustomProperties( $form, $entry, $settings, array_keys( $data ) );
+ if ( ! empty( $custom_properties ) ) {
+ $data['customProperties'] = (object) $custom_properties;
+ }
+
+ if ( ! $this->createOmnisendContact( $data ) ) {
+ return;
+ }
+
+ $this->enableWebTracking( $email, $phone_number );
+
+ } catch ( Exception $e ) {
+ error_log( 'Error in after_submission: ' . $e->getMessage() );
+ }
+ }
+
+ private function createOmnisendContact( $body ) {
+ $api_key = get_option( 'omnisend_api_key', null );
+ $endpoint = 'https://api.omnisend.com/v3/contacts';
+
+ $data = array(
+ 'body' => wp_json_encode( $body ),
+ 'headers' => array(
+ 'Content-Type' => 'application/json',
+ 'X-API-Key' => $api_key,
+ ),
+ 'timeout' => 10,
+ );
+
+ $response = wp_remote_post( $endpoint, $data );
+
+ if ( is_wp_error( $response ) ) {
+ error_log( 'wp_remote_post error: ' . $response->get_error_message() );
+ return false;
+ }
+
+ $http_code = wp_remote_retrieve_response_code( $response );
+ if ( $http_code >= 400 ) {
+ $body = wp_remote_retrieve_body( $response );
+ error_log( "HTTP error: {$http_code} - " . wp_remote_retrieve_response_message( $response ) . " - {$body}" );
+ return false;
+ }
+
+ return true;
+ }
+
+
+ private function mapCustomProperties( $form, $entry, $settings, $excluded_fields ) {
+ $custom_properties = array();
+ $prefix = 'gravity_forms_';
+ foreach ( $form['fields'] as $field ) {
+ $field_id = $field['id'];
+ $field_label = $field['label'];
+
+ if ( ! in_array( $field_id, $settings ) || $settings[ array_search( $field_id, $settings ) ] === '-1' ) {
+ // Replace spaces with underscores, remove invalid characters, lowercase.
+ $safe_label = str_replace( ' ', '_', $field_label );
+ $safe_label = preg_replace( '/[^A-Za-z0-9_]/', '', $safe_label );
+ $safe_label = strtolower( $safe_label );
+
+ if ( $field['type'] !== 'checkbox' ) {
+ // Check if the value is set and not empty.
+ if ( ! empty( $entry[ $field_id ] ) ) {
+ $custom_properties[ $prefix . $safe_label ] = $entry[ $field_id ];
+ }
+ } else {
+ $selected_choices = array();
+ if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) {
+ foreach ( $field['inputs'] as $input ) {
+ $choice_id = $input['id'];
+ if ( ! empty( $entry[ $choice_id ] ) ) {
+ $selected_choices[] = $input['label'];
+ }
+ }
+ }
+ // Only add to customProperties if selectedChoices is not empty.
+ if ( ! empty( $selected_choices ) ) {
+ $custom_properties[ $prefix . $safe_label ] = $selected_choices;
+ }
+ }
+ }
+ }
+ return $custom_properties;
+ }
+
+ public function get_menu_icon() {
+ return file_get_contents( $this->get_base_path() . '/images/menu-icon.svg' );
+ }
+
+ private function enableWebTracking( $email, $phone ) {
+ $identifiers = array_filter(
+ array(
+ 'email' => sanitize_email( $email ),
+ 'phone' => sanitize_text_field( $phone ),
+ )
+ );
+
+ $path_to_script = plugins_url( '/js/snippet.js', __FILE__ );
+
+ wp_enqueue_script( 'omnisend-snippet-script', $path_to_script, array(), '1.0.0', true );
+ wp_localize_script( 'omnisend-snippet-script', 'omnisendIdentifiers', $identifiers );
+ }
+
+ public function settings_welcome_automation_details( $field, $echo = true ) {
+ echo '
' . esc_html__( 'After checking this, don’t forget to design your welcome email in Omnisend.', 'omnisend-for-gravity-forms-add-on' ) . '
';
+ echo '' . esc_html__( 'Learn more about Welcome automation', 'omnisend-for-gravity-forms-add-on' ) . ' ';
+ }
+
+
+ public function settings_field_mapping_details() {
+ echo '' . esc_html__( 'Field mapping lets you align your form fields with Omnisend. It\'s important to match them correctly, so the information collected through Gravity Forms goes into the right place in Omnisend.', 'omnisend-for-gravity-forms-add-on' ) . '
';
+
+ echo ' ';
+
+ echo '';
+ }
+}
diff --git a/omnisend-for-gravity-forms/images/menu-icon.svg b/omnisend-for-gravity-forms/images/menu-icon.svg
new file mode 100644
index 0000000..8933619
--- /dev/null
+++ b/omnisend-for-gravity-forms/images/menu-icon.svg
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
diff --git a/omnisend-for-gravity-forms/images/omnisend-field-mapping.png b/omnisend-for-gravity-forms/images/omnisend-field-mapping.png
new file mode 100644
index 0000000..1f245f7
Binary files /dev/null and b/omnisend-for-gravity-forms/images/omnisend-field-mapping.png differ
diff --git a/omnisend-for-gravity-forms/js/snippet.js b/omnisend-for-gravity-forms/js/snippet.js
new file mode 100644
index 0000000..0b0107b
--- /dev/null
+++ b/omnisend-for-gravity-forms/js/snippet.js
@@ -0,0 +1,5 @@
+jQuery(document).ready(function($) {
+ if (omnisendIdentifiers && omnisend && omnisend.identifyContact) {
+ omnisend.identifyContact(omnisendIdentifiers);
+ }
+});
diff --git a/omnisend-for-gravity-forms/readme.txt b/omnisend-for-gravity-forms/readme.txt
new file mode 100644
index 0000000..bdb5a35
--- /dev/null
+++ b/omnisend-for-gravity-forms/readme.txt
@@ -0,0 +1,74 @@
+=== Omnisend for Gravity Forms Add-On ===
+Plugin Name: Omnisend for Gravity Forms Add-On
+Contributors: Omnisend
+Tags: Gravity forms, form, email marketing, web tracking, subscriber collection
+Requires at least: 4.7.0
+Tested up to: 6.4
+Requires PHP: 7.1
+Stable tag: 1.0.4
+License: GPLv3 or later License
+URI: http://www.gnu.org/licenses/gpl-3.0.html
+
+Email Marketing, Newsletter, Email Automation, Forms, Pop Up, SMS by Omnisend
+
+== DESCRIPTION ==
+
+The Omnisend for Gravity Forms Add-On connects Gravity Forms to Omnisend, automatically sending form data and contact information to Omnisend. This makes it simple to segment your contacts and send them personalized emails.
+
+When used with the Omnisend for WooCommerce plugin, you can track what customers do on your site and send automated emails—such as to remind them they left items in their cart, welcome new subscribers, and confirm a new order.
+
+Using Gravity Forms Omnisend Add-On, you'll gain access to the Gravity Forms easy-to-use interface. You can create new forms, edit forms, and change their statuses. You are also able to:
+
+* Check the entries from specific form(s) and export the contact list.
+* Customize your integration settings to your store needs.
+* Import and export your forms.
+* Integrate with additional add-ons.
+
+== REQUIREMENTS ==
+
+Omnisend for Gravity Forms add-on requires you to install:
+- Gravity Forms plugin
+- WooCommerce Wordpress plugin
+- Omnisend for WooCommerce plugin
+
+== FAQ ==
+
+= Installation instructions =
+Read [Installation instructions](https://support.omnisend.com/en/articles/8617559-integration-with-gravity-forms)
+
+= What are the technical requirements for the plugin installation? =
+* PHP 7.1+
+* WordPress 4.0.1+
+* WooCommerce plugin 6.0+
+* Omnisend for WooCommerce plugin 1.10.0 +
+* Omnisend account
+
+= How can I reach Omnisend support? =
+Every Omnisend customer gets our award-winning support, 24/7—even on the free plan. Email support@omnisend.com or use the live chat option within your account. We also have a comprehensive [Knowledge Base](https://support.omnisend.com/).
+
+= Where can I find Omnisend Terms? =
+Read Omnisend [Terms of Use](https://www.omnisend.com/terms)
+
+== Screenshots ==
+
+1. Build beautiful campaigns using our email templates
+2. Drive revenue round the clock and recover sales with pre-built automated workflows
+3. Send emails, newsletters & SMS campaigns
+4. Access all features on the generous free-forever plan
+5. Grow your audience with popups incl exit-intent, signup forms & spin-to-win
+6. Fast support, available 24/77. Actionable insights to help create more personalized messages
+7. Convert more visitors with highly-targeted landing pages
+
+== Changelog ==
+
+= 1.0.4 =
+
+* Minor usability improvements.
+
+= 1.0.3 =
+
+* Added support for welcome emails
+
+= 1.0.0 =
+
+* Initial release.