=== Hafenstudios Ads – Ad Manager, AdSense & Banner Ads ===
Contributors: hafenstudios
Tags: ads, adsense, ad manager, banner ads, advertising
Requires at least: 6.2
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.9.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Ad manager for banner ads and AdSense: auto-placement, ad rotation, targeting, consent gating, lazy loading and local stats. No external calls.

== Description ==
Hafenstudios Ads is an ad manager for WordPress: place banner ads, AdSense units and any ad code exactly where you want them, rotate them, target who sees them, and keep an eye on impressions, clicks and CTR — without sending any analytics to an external server.

Create multiple ad blocks, insert them automatically before or after the content, after paragraph N or by shortcode, widget and Gutenberg block. Weighted ad rotation, device and post-type targeting, campaign scheduling and consent gating are built in. Part of the hafenstudios plugin family.

= Highlights =
* Clean, focused admin interface with brand bar, weekly summary and clear navigation tabs.
* Automatic placements before content, after content, after paragraph N or after the first image.
* Manual placement via shortcode `[adjet_ad id="1"]`, widget or Gutenberg block.
* Weighted ad rotation via `[adjet_ad_group name="header"]`.
* Device targeting for desktop, tablet and mobile.
* Post type targeting plus exclusions for posts, categories, tags and custom terms.
* Optional "Advertisement" label with editable text.
* Lazy loading via IntersectionObserver.
* Consent-cookie gating for common consent tools.
* Optional anonymous local impression and click statistics.
* Campaign scheduling with optional start and end time.
* One-click duplicate and pause/activate actions for faster workflow.
* Code editor and admin-side live preview that does not execute scripts.
* AdSense Wizard: Publisher-ID + Slot-ID are enough for responsive AdSense units.
* Optional AdSense Auto Ads script loader with clear settings.
* 30-day statistics chart (impressions and clicks) rendered inline, no external libraries.
* Weekly summary above the ad block list: impressions, clicks and CTR since Monday, compared with the same weekday span of the previous week.
* Least-privilege capability `manage_adjet` with an optional editor-access toggle.
* Template gallery with ready-to-use banners, notification bars and popups; premium templates unlock with Pro.
* REST API (`adjet/v1`) for ad blocks, stats and settings via Application Passwords.
* Guided assistant with optional AI copy suggestions (bring your own Anthropic Claude key).
* Built-in cookie-consent banner template with Google Consent Mode v2 support.
* Native newsletter opt-in for SendFox, MailerLite, Brevo and Mailchimp (bring your own token) with double opt-in.
* First-run onboarding that routes you to AdSense, a template or your own HTML.
* JSON import and export with file-size/type checks.
* Uninstall routine that keeps your data unless you explicitly ask for it to be deleted.

= Privacy =
The plugin does not contact hafenstudios servers from the WordPress admin area or frontend. Optional statistics are stored locally in your own WordPress database. Third-party ad code pasted into an ad block may contact external services; configure your consent solution accordingly.

= External services =
The plugin works fully without any external service. Every integration below is optional and only ever runs when you explicitly enable it:

* Google AdSense (frontend): if you configure an AdSense ad unit or enable Auto Ads, the frontend loads Google's `adsbygoogle.js` from `pagead2.googlesyndication.com` to display ads. Terms: https://www.google.com/adsense/localized-terms — Privacy: https://policies.google.com/privacy
* Anthropic Claude (admin only, bring-your-own-key): the optional "AI suggestions" button in the ad assistant sends the template's field labels, your site name/description and any brief you type to the Anthropic API (`api.anthropic.com`) to generate draft ad copy. This happens only after you enter your own Anthropic API key in the settings and click the button; no key, no request. The key is stored encrypted and used server-side only. Terms: https://www.anthropic.com/legal/commercial-terms — Privacy: https://www.anthropic.com/legal/privacy
* SendFox (bring-your-own-token): if you connect SendFox in the settings and use the "Newsletter (SendFox)" template, visitor email addresses submitted through that form are sent to the SendFox API (`api.sendfox.com`) to be added to your list. This happens only when you have connected a SendFox access token. The token is stored encrypted and used server-side only. Terms: https://sendfox.com/tos — Privacy: https://sendfox.com/privacy
* MailerLite (bring-your-own-token): if you connect MailerLite in the settings and use the "Newsletter (MailerLite)" template, visitor email addresses submitted through that form are sent to the MailerLite API (`connect.mailerlite.com`) to be added to your group. This happens only when you have connected a MailerLite API token. The token is stored encrypted and used server-side only. Terms: https://www.mailerlite.com/legal/terms-of-service — Privacy: https://www.mailerlite.com/legal/privacy-policy
* Brevo (bring-your-own-token): if you connect Brevo in the settings and use the "Newsletter (Brevo)" template, visitor email addresses submitted through that form are sent to the Brevo API (`api.brevo.com`) to be added to your list. This happens only when you have connected a Brevo API key. The key is stored encrypted and used server-side only. Terms: https://www.brevo.com/legal/termsofuse/ — Privacy: https://www.brevo.com/legal/privacypolicy/
* Mailchimp (bring-your-own-token): if you connect Mailchimp in the settings and use the "Newsletter (Mailchimp)" template, visitor email addresses submitted through that form are sent to the Mailchimp API (`<dc>.api.mailchimp.com`, the data center encoded in your API key) to be added to your audience with status "pending", which triggers Mailchimp's double opt-in. This happens only when you have connected a Mailchimp API key. The key is stored encrypted and used server-side only. Terms: https://mailchimp.com/legal/terms/ — Privacy: https://www.intuit.com/privacy/statement/

= Security =
The plugin uses capability checks, nonces for form actions, sanitization on save and escaping on output. Raw ad code is only stored unchanged for users with the `unfiltered_html` capability.

= Localization =
* Source language: English.
* Included translations: German, Spanish, French and Dutch — complete and shipped with the plugin.

= Support =
This plugin is developed and maintained by hafenstudios. For direct support you can reach us by e-mail at moin@hafenstudios.com or by phone at +49 174 3935796. You are also welcome to use the plugin support forum on WordPress.org.

== Installation ==
1. Upload the ZIP via Plugins > Add New > Upload Plugin.
2. Activate the plugin.
3. Open the new "Hafenstudios Ads" menu and create your first ad block.
4. Optional: configure the ad label, consent-cookie settings and local statistics.

Upgrading from "AdEngine – Free Ad Inserter & Manager"? Just install this plugin — your ad blocks, settings and statistics are migrated automatically on first load.

== Screenshots ==
1. The ad blocks overview with impressions, clicks and CTR per block.
2. The template gallery: pick a purpose, fill in the fields, no HTML needed.
3. The guided editor with live preview while you type.
4. The AdSense assistant: Publisher-ID, slot and format, nothing else.
5. Placement options, device targeting and consent gating for a single block.
6. Local statistics with the 30-day chart, rendered server-side without any external service.

== Frequently Asked Questions ==
= Does this plugin work with AdSense? =
Yes. You can either paste original AdSense code as custom code or use the AdSense Wizard with your Publisher-ID and Slot-ID. The plugin then generates a responsive ad unit and loads the AdSense script on the frontend when needed.

= Can I use it manually? =
Yes. Use the shortcode `[adjet_ad id="1"]`, the shortcode `[adjet_ad_group name="header"]`, the included widget or the Gutenberg block.

= Does it replace a consent tool? =
No. The plugin can wait for a configured consent cookie, but it does not provide legal advice or a cookie banner.

= Does this plugin track users externally? =
No. The optional statistics feature stores anonymous aggregated counts locally in your WordPress database.

= Can editors manage ads without being administrators? =
Yes. Enable "Editor access" in Settings to grant the `manage_adjet` capability to the editor role. Administrators always have access.

= What happens to my data when I uninstall the plugin? =
Nothing is deleted unless you ask for it. The setting "Delete all data on uninstall" is off by default, so removing the plugin leaves your ad blocks, settings and the statistics table in place and a later reinstall picks them up again. Switch the setting on before uninstalling if you want the options, the statistics table and the `manage_adjet` capability removed for good.

= Is there a REST API? =
Yes. The `adjet/v1` namespace exposes ad blocks (`/blocks`, CRUD), statistics (`/stats`) and settings (`/settings`). Authenticate with an Application Password; access requires the `manage_adjet` capability.

== Changelog ==

= 1.9.0 =
* Added three more newsletter providers next to SendFox: MailerLite, Brevo and Mailchimp. Each one has its own template and its own connection, so you can run several at once and pick a different list per ad block.
* Every provider token is stored encrypted on its own, so connecting a new provider never touches an existing one. An already connected SendFox account keeps working unchanged after the update.
* Mailchimp signups are handed over with status "pending", which triggers Mailchimp's own confirmation mail.
* Uninstalling now also removes the tokens and cached lists of the new providers.
* Translated all new texts into German, Spanish, French, Dutch, Italian and Portuguese.
* Fixed: the click-through rate now follows the site language. On a German site it read "1.58" right next to "31.847" impressions, where the dot is a thousands separator - two different meanings for the same character.

= 1.8.7 =
* Added a small card above the content of the plugin's own pages that shows one thing at a time: a statistics milestone, a one-off review request, or a feature you may not have found yet. Never more than one card, never on other pages of the admin area, and every card can be dismissed for good.
* Replaced the four 30-day tiles above the ad block list with a weekly summary: impressions, clicks and CTR since Monday, compared with the same weekday span of the previous week, plus a 7-day chart and the strongest ad block of the week. Same local data as before, nothing new is collected.
* Added the setting "Delete all data on uninstall", switched off by default. Until you switch it on, removing the plugin leaves your ad blocks, settings and statistics untouched.
* The assistant now states plainly what your own Claude API key unlocks, and the settings explain that requests go from your site straight to Anthropic with your own account.
* Added complete Spanish, French and Dutch translations and completed the German one.
* Added a link to the manual on the plugin pages.

= 1.8.6 =
* Fixed: the Pro page named the wrong payment provider. Purchases are handled by Freemius, not Digistore24; the 30-day money-back guarantee is unchanged.

= 1.8.5 =
* The plugin now speaks English by default: all source strings were translated from German to English, and German ships as a complete translation that loads automatically on German sites. Before this release, every site saw the German interface regardless of its language.
* Removed the broken placeholder translation files (en/es/fr/nl) that did not actually translate anything; Spanish, French and Dutch will return via wordpress.org language packs.
* Added the six directory screenshots.

= 1.8.4 =
* Renamed the plugin to "Hafenstudios Ads – Ad Placement Manager" and changed the text domain to `hafenstudios-ads`, following the WordPress.org plugin review. No functional changes.
* Internal prefixes, option names, shortcodes and the REST namespace are deliberately unchanged, so existing ad blocks, settings and statistics keep working.

= 1.8.2 =
* Removed the legacy `[sai_ad]` and `[sai_ad_group]` shortcode aliases, so every public name this plugin registers now carries the `adjet` prefix. Use `[adjet_ad]` and `[adjet_ad_group]` instead.
* The Google AdSense loader is now enqueued with `wp_enqueue_script()` only; the custom script-tag filter that added the optional `crossorigin` attribute has been dropped.
* Documented the output escaping contract of the ad render pipeline directly at the shortcode, block and `the_content` callbacks.

= 1.8.1 =
* Fixed the Plugin URI and the SendFox terms link so all declared URLs resolve.
* Moved all frontend and admin JavaScript and CSS out of inline `<script>`/`<style>` tags into properly enqueued files: base styles now load as `public/frontend.css`, the AdSense unit call, the popup/exit-intent/cookie-consent behaviour and the admin live preview run from enqueued scripts. No behaviour change.
* Hardened and documented output escaping around the ad render pipeline (generated markup is escaped; raw custom code stays gated behind the `unfiltered_html` capability, like the core Custom HTML block).
* Switched all direct database access to prepared statements using the `%i` table-identifier placeholder, which raises the minimum WordPress version to 6.2.

= 1.8.0 =
* Added a built-in Cookie-Consent banner template: visitors accept or decline, it sets the consent signal your consent-gated ads wait for, and it emits Google Consent Mode v2 updates. No separate consent plugin needed.
* Added a native SendFox newsletter integration (bring your own SendFox access token): the new "Newsletter (SendFox)" template subscribes visitors straight into your chosen list. SendFox handles the double opt-in.
* Added a public opt-in endpoint protected by nonce, honeypot and rate limiting; the token is stored encrypted and used server-side only.
* Generalised the assistant with a third mapper type (provider) so more email providers can hook in later.

= 1.7.0 =
* Added a template gallery with ready-to-use ads, banners, notification bars and popups (free), plus Pro-badged premium templates and a Free/Pro foundation with an upgrade page. Free stays fully functional.
* Added a guided assistant: pick a template and just fill in fields (title, text, link, colour) with a live preview instead of writing HTML. Field values are stored and stay editable; "HTML selbst bearbeiten" switches to the raw editor.
* Added a guided Google AdSense assistant: enter Publisher-ID, Slot-ID and format, and the plugin builds the responsive unit.
* Added optional AI copy suggestions in the assistant: bring your own Anthropic Claude API key and let the AI draft titles, texts and button labels as fully editable suggestions. One request per click, never automatic; the key is stored encrypted (libsodium) and used server-side only.
* Added a site-wide "overlay" placement so popups, exit-intent and notification bars display and self-trigger.
* Added a first-run onboarding panel that routes you to AdSense, a template or your own HTML.
* Refined the admin: save-in-editor confirmation, compact icon actions, a collapsible "Erweitert" section, and Hans, the hand-drawn hafenstudios captain mascot.

= 1.6.0 =
* Added a least-privilege capability `manage_adjet` (administrators keep access via a manage_options fallback) plus an optional editor-access toggle in Settings.
* Added a REST API under `adjet/v1` for ad blocks, statistics and settings (Application Password auth).
* Added a 30-day impressions/clicks chart to the statistics page, rendered inline as SVG without external libraries.

= 1.5.0 =
* Rebranded the plugin as part of the hafenstudios plugin family.
* Redesigned the admin interface in the clean hafenstudios/Linkjet design language (brand bar, tab navigation, teal accent, KPI and content cards).
* Migrated shortcodes to `[adjet_ad]` and `[adjet_ad_group]`; the legacy `[sai_ad]` / `[sai_ad_group]` shortcodes keep working as aliases.
* Automatic data migration from a previous AdEngine install (ad blocks, settings and statistics).
* Added object-cache-backed statistics totals to reduce database load.
* Fixed AdSense script enqueue to always carry a version and cleaned up Plugin Check notices.

= 1.4.3 =
* Renamed the public plugin title to comply with WordPress.org naming restrictions.

= 1.4.1 =
* Refined admin interface with cleaner hero, glass navigation, stronger cards and better responsive behavior.
* Improved backend usability, visual hierarchy and AdSense onboarding cues.

= 1.4.0 =
* Added AdSense Wizard for easy responsive AdSense ad units using Publisher-ID and Slot-ID.
* Added optional AdSense Auto Ads frontend loader.
* Added dynamic Gutenberg block for manual placements.
* Added weighted ad rotation groups.

= 1.3.1 =
* Added campaign scheduling with optional start/end time.
* Added one-click duplicate and pause/activate actions.
* Added automatic placement after the first image.
* Added WordPress code editor integration and a safer admin-side live preview.

= 1.3.0 =
* Added optional local statistics toggle.
* Hardened import flow with JSON extension and file-size validation.
* Improved security posture around raw ad code.

= 1.2.0 =
* Added backend styling with hero area and KPI cards.
* Added localization starter files.

= 1.1.0 =
* Added label, AMP exclusion, server-side device detection, minimum word count, max-per-post, exclusion lists, lazy loading, consent gating, stats, import/export and uninstall routine.

= 1.0.0 =
* Initial version.

== Upgrade Notice ==

= 1.9.0 =
Adds MailerLite, Brevo and Mailchimp as newsletter providers next to SendFox. An existing SendFox connection keeps working; nothing needs to be re-entered.

= 1.8.7 =
Uninstalling no longer deletes your data unless you switch on "Delete all data on uninstall" in the settings. Adds a weekly summary above the ad block list and complete Spanish, French and Dutch translations.

= 1.8.4 =
Renaming only: the plugin is now called "Hafenstudios Ad Placement Manager". Your ad blocks, settings and statistics stay exactly as they are.

= 1.8.2 =
The legacy `[sai_ad]` and `[sai_ad_group]` shortcodes from AdEngine were removed. If you still have them in your content, switch to `[adjet_ad]` and `[adjet_ad_group]`.

= 1.8.1 =
Maintenance release: valid declared URLs and all JavaScript/CSS moved into properly enqueued files. No action needed.

= 1.8.0 =
Adds a built-in cookie-consent banner (Google Consent Mode v2) and a native SendFox newsletter integration. Both optional; the plugin stays fully functional without them.

= 1.7.0 =
Big update since 1.6.0: template gallery, guided assistant with optional AI copy suggestions (bring your own Anthropic key, stored encrypted), a Google AdSense assistant, site-wide overlays and first-run onboarding. Free stays fully functional.

= 1.6.0 =
Adds the manage_adjet capability, a REST API and a statistics chart. No action required.

= 1.5.0 =
Rebrand with a refreshed admin interface. Existing ad blocks, settings and stats are migrated automatically.
