=== MarketLyft - Marketing Automation for WordPress ===
Contributors: marketlyft
Tags: marketlyft, mautic, sync, woocommerce, crm
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 8.0
Stable tag: 1.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Synchronizes WordPress and WooCommerce user data with MarketLyft (Mautic 7.x) via REST API.

== Description ==

**Free up to 300 contacts.** MarketLyft is a one-way synchronization plugin that pushes user and customer data from WordPress to your MarketLyft (Mautic 7.x) instance.

**Supported data sources:**

* WordPress user registration, profile updates, login, deletion, role changes
* WooCommerce customers, orders, order status changes, payments (HPOS + Block Checkout compatible)
* Contact Form 7 submissions
* Gravity Forms submissions
* MailPoet 3 subscriber events
* The Newsletter Plugin subscriber events

**Key features:**

* Configurable field mapping (WP/WC/form fields → MarketLyft contact fields)
* Automatic tag management (add/remove tags based on events)
* Background processing via WP Cron (built-in) with optional Action Scheduler upgrade
* Encrypted credential storage (sodium)
* Retry with exponential backoff on API failures
* HPOS and Block Checkout (WC 8.3+) compatible

= Third-Party Service =

This plugin sends data to your MarketLyft (Mautic) instance — the URL you configure in Settings → MarketLyft Sync. No data is sent to any other external service.

**Data transmitted:**

* User profile information (name, email, website URL)
* WooCommerce billing details (address, phone, company) when WooCommerce module is enabled
* Form submission data (Contact Form 7, Gravity Forms) when Forms module is enabled
* Newsletter subscriber data (MailPoet, Newsletter Plugin) when Newsletter module is enabled

**When data is transmitted:**

* On user registration, profile update, login, deletion, and role change
* On WooCommerce checkout, order status change, and payment completion
* On form submission (Contact Form 7, Gravity Forms)
* On newsletter subscription, update, and unsubscription events

Data is transmitted only to the MarketLyft/Mautic URL you have configured. No data is collected by the plugin author.

MarketLyft is powered by Mautic, an open-source marketing automation platform.

* [MarketLyft Privacy Policy](https://marketlyft.app/privacy)
* [MarketLyft Terms of Service](https://marketlyft.app/terms)
* [Mautic Privacy Policy](https://www.mautic.org/privacy-policy)

== Installation ==

1. Upload the `marketlyft-sync` folder to `/wp-content/plugins/` or install directly from the WordPress plugin directory.
2. Activate the plugin.
3. Go to Settings → MarketLyft Sync.
4. Enter your MarketLyft instance URL.
5. Choose an authentication method (Basic Auth or OAuth2) and enter your API credentials.
6. Enable the sync modules you need (Users, WooCommerce, Forms, Newsletter).
7. Click "Test Connection" to verify the connection.

= OAuth2 Setup =

1. In your MarketLyft/Mautic instance, go to Settings → API Credentials and create a new OAuth2 client.
2. Set the Redirect URI to the value shown on the plugin settings page.
3. Copy the Client ID and Client Secret into the plugin settings.
4. Click "Authorize" and follow the prompts.

= Credential Encryption (Recommended) =

To encrypt stored API credentials, add the following to your `wp-config.php`:

`define( 'MLWPS_ENCRYPTION_KEY', 'your-64-char-hex-string' );`

Generate a key with: `php -r "echo bin2hex(random_bytes(32));"`

= Background Processing =

The plugin processes sync jobs in the background using WordPress's built-in WP Cron. No extra plugin is required. If Action Scheduler is already installed on your site (for example via WooCommerce), the plugin uses it automatically for better performance on large migrations and for the Tools → Scheduled Actions admin UI.

== Frequently Asked Questions ==

= What is MarketLyft? =

MarketLyft is a marketing automation platform powered by Mautic 7.x. This plugin connects your WordPress site to your MarketLyft instance via its REST API.

= Does this plugin work without WooCommerce? =

Yes. WooCommerce is optional. The core Users module works with any WordPress installation. WooCommerce, Forms, and Newsletter modules can be enabled or disabled independently.

= Does this plugin import data from MarketLyft into WordPress? =

No. Synchronization is strictly one-way: WordPress → MarketLyft. No data is ever pulled from MarketLyft into your WordPress database.

= What happens if the MarketLyft API is unreachable? =

API calls are queued via Action Scheduler and retried up to 5 times with exponential backoff (1, 2, 4, 8, 16 minutes). Client errors (4xx) are not retried and are logged immediately.

= Is Action Scheduler required? =

No. The plugin uses WordPress's built-in WP Cron by default — no extra plugin is needed. If Action Scheduler is already installed (e.g. via WooCommerce), the plugin picks it up automatically, which scales better for very large migrations (10k+ contacts) and provides a detailed admin UI at Tools → Scheduled Actions.

= How are my API credentials stored? =

If you define `MLWPS_ENCRYPTION_KEY` in `wp-config.php`, credentials are encrypted with XSalsa20-Poly1305 (libsodium) before being stored in the database. Without the key, credentials are stored in plain text.

= Which WordPress hooks does this plugin use? =

The plugin listens to 17 WordPress/WooCommerce/form/newsletter hooks. See the plugin documentation for the complete list.

== Screenshots ==

1. API connection settings with OAuth2 authorization
2. Sync module selection (Users, WooCommerce, Forms, Newsletter)
3. Field mapping interface
4. Successful connection test

== Changelog ==

= 1.1.0 =
* First Sync — one-click bulk migration of existing WordPress users, WooCommerce customers, and newsletter subscribers (MailPoet / The Newsletter Plugin) to MarketLyft after OAuth2 authorization. Runs once, shows a live progress bar, and can be reset from the settings page if needed.
* No external dependency: background processing now uses WP Cron by default (built into WordPress core). Action Scheduler is still used automatically when present (e.g. on WooCommerce sites) — but it is no longer required.
* Privacy: sync error logs no longer include contact field values — emails are masked and other values are dropped. Prevents PII leakage on shared hosting and centralised log collectors.
* Credential storage warnings: the settings page now accurately reflects whether `MLWPS_ENCRYPTION_KEY` is configured, showing a warning when credentials fall back to plaintext or when a rotated key prevents decryption.

= 1.0.3 =
* WooCommerce OAuth2 integration

= 1.0.1 =
* OAuth2 authorization flow
* Improvements to settings page UI and field mapping
* WooCommerce HPOS and Block Checkout compatibility fixes
* Various bug fixes and stability improvements

= 1.0.0 =
* Initial release
* WordPress user sync (registration, profile update, login, deletion, role change)
* WooCommerce customer and order sync (HPOS + Block Checkout compatible)
* Contact Form 7 and Gravity Forms integration
* MailPoet 3 and Newsletter Plugin integration
* Configurable field mapping UI
* OAuth2 and Basic Auth support
* Encrypted credential storage (libsodium)
* Action Scheduler background processing with retry and exponential backoff

== Upgrade Notices ==

= 1.1.0 =
Adds a First Sync button so you can push existing users, customers, and newsletter subscribers to MarketLyft in one click. Background processing now works out of the box without Action Scheduler.

= 1.0.3 =
Adds OAuth2 support for WooCommerce.

= 1.0.0 =
Initial release.
