=== MailJinny ===
Contributors: spiggle
Tags: newsletter, email, subscribers, mailjinny, signup
Requires at least: 6.7
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 1.0.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Connect WordPress to MailJinny. Sync people who opted in, and turn posts into newsletter drafts.

== Description ==

MailJinny for WordPress connects a site to [MailJinny](https://mailjinny.com), a newsletter service. Paste an API key on one settings screen. The plugin checks the key, picks the newsletter when there is only one, and syncs users who asked to be emailed.

What you can do:

* Connect with an API key. The key can live in `wp-config.php` as `MAILJINNY_API_KEY` so it is not stored in the database.
* Sync users who check **Email me new posts**. Other users are never uploaded.
* Turn a post into a MailJinny draft from the editor sidebar, and optionally do that when the post is published. Sending the campaign stays in MailJinny.
* Add a signup form with the MailJinny Signup block or `[mailjinny_signup]`.
* Optionally route WordPress email (password resets and the like) through MailJinny when the sender domain is verified. If MailJinny does not accept a message, WordPress sends it the normal way.
* See plan usage, sending-domain status, and a deliverability score on the settings screen.

The plugin does not support Multisite network activation, WooCommerce, popups, or sending a campaign directly from WordPress.

== Installation ==

1. Upload the `mailjinny` folder to `/wp-content/plugins/`, or install the zip from the Plugins screen.
2. Activate MailJinny.
3. Go to **Settings → MailJinny**, paste an API key from [API keys](https://app.mailjinny.com/api-keys), and click **Verify & connect**.
4. If you do not have an account yet, use **Create a free account** or open [plans and pricing](https://mailjinny.com/pricing/).

To keep the key out of the database, add this to `wp-config.php` before connecting:

`define( 'MAILJINNY_API_KEY', 'spm_your_key_here' );`

Self-hosted MailJinny servers can set a different API base URL under **Advanced** on the connect screen. The default is `https://app.mailjinny.com/api/v1`.

== Frequently Asked Questions ==

= Who gets synced? =

Only users who check **Email me new posts**, and only while their role is one of the roles you select (Subscriber by default). Addresses that MailJinny has unsubscribed, bounced, complained, or suppressed are not subscribed again.

= Does the plugin send the newsletter? =

No. It creates a draft and links you to MailJinny, where you review and send it. That stays true even if the API key is allowed to broadcast.

= What happens if MailJinny is down while WordPress is sending email? =

Routing is off until you turn it on, and it can be turned on only when the sender domain is verified. If a send fails or takes longer than a few seconds, WordPress delivers that message with its normal mailer.

= Can I use this on Multisite? =

Not as a network-activated plugin. Activate it on an individual site if you need it there.

== External services ==

This plugin talks to MailJinny only after you open its settings screen or use a feature that needs the connection. It does not call out when it is activated, and it does not call out from the public site until a visitor submits the signup form or you have turned on WordPress email routing.

**Service:** MailJinny (https://app.mailjinny.com). Marketing site: https://mailjinny.com. Terms and privacy policy are on that site.

**API base:** `https://app.mailjinny.com/api/v1` unless you change it for a self-hosted server.

What is sent, and when:

* **Settings screen, before you connect.** The plugin requests the public plan list (`GET /plans`) so the screen can show current prices and limits. No account data is sent. The site URL is included as the `X-Site-Url` header.
* **When you click Verify & connect.** The API key you pasted, your site URL, and a plugin user agent are sent to `GET /me`, `GET /newsletters`, and `POST /webhooks`. The webhook URL is your site's `https://example.com/wp-json/mailjinny/v1/webhook`.
* **Health panel.** While you are connected, opening the settings screen loads account usage, sending domains, and deliverability (`GET /me`, `GET /domains`, `GET /deliverability`, `GET /newsletters`).
* **Subscriber sync.** Email, first name, last name, WordPress user id, and role are sent for users who opted in (`POST /contacts` or `POST /contacts/bulk`). Source is `wordpress`.
* **Signup form.** The email address a visitor submits is sent with `POST /contacts`. No status is sent, so MailJinny can ask them to confirm.
* **Post to draft.** The subject, preview text, and cleaned post HTML are sent with `POST /campaigns` or `PATCH /campaigns/{id}` when an editor creates a draft.
* **WordPress email, only if you enable it.** Recipient, sender, subject, and body of messages WordPress sends with `wp_mail()` are sent with `POST /emails/send`. Attachments and Cc/Bcc are not sent; those messages stay on the normal mailer.
* **Disconnect.** The plugin asks MailJinny to delete the webhook it registered.

MailJinny signs webhooks with HMAC-SHA256. The plugin checks that signature before it changes a subscriber's status.

== Screenshots ==

1. The connect screen, with a place to paste an API key and links to create an account.
2. The health panel after the site is connected.

== Changelog ==

= 1.0.2 =
* Load the admin notice dismiss script with WordPress enqueue functions.
* On uninstall, remove dismissed-notice user meta and clear every scheduled sync event, including per-user jobs.

= 1.0.1 =
* Admin notices now appear only on the Plugins screen and can be dismissed.
* The WordPress.org username is listed as the plugin contributor.

= 1.0.0 =
* First release. Connect with an API key, sync opted-in users, create newsletter drafts from posts, embed a signup form, receive unsubscribe webhooks, and optionally route WordPress email.

== Upgrade Notice ==

= 1.0.2 =
Admin notice script is now loaded with WordPress enqueue functions.

= 1.0.1 =
Admin notices are limited to the Plugins screen and can be dismissed.

= 1.0.0 =
First release.
