=== EvangelOS Sync ===
Contributors: getevangelos
Tags: church, events, sync, church management, prayer requests
Requires at least: 6.0
Tested up to: 7.0
Stable tag: 1.0.1
Requires PHP: 8.0
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Connect your WordPress site to EvangelOS — automatically sync church events, communications, and prayer requests. No manual data entry required.

== Description ==

**EvangelOS Sync** is the official WordPress plugin for [EvangelOS](https://getevangelos.com), the church management system built for modern ministries.

Once connected, your WordPress site stays automatically in sync with your EvangelOS account — events appear on your website the moment they're created in EvangelOS, sent announcements and newsletters are published as posts, and website visitors can submit prayer requests directly into your EvangelOS prayer request queue.

= What it does =

**Events sync** — Public church events created in EvangelOS are automatically imported into a `church_event` custom post type in WordPress. Events are updated when they change in EvangelOS, and optionally trashed when they're deleted. Supports filtering to upcoming-only and public-only events.

**Communications sync** — Sent announcements, newsletters, and other communications from EvangelOS are automatically published as WordPress posts, organized into categories. Great for keeping your website's news section current without copy-pasting.

**Prayer requests** — Add the `[evangelos_prayer_request]` shortcode to any page to display a prayer request form. Submissions go directly into EvangelOS so your pastoral team sees them immediately. A `/prayer-requests/` page is created automatically on activation.

= Features =

* One-click connection test to verify your API key
* Configurable sync schedule: hourly, twice daily, or daily
* Sync history dashboard showing the last 25 runs with created/updated/skipped/error counts
* Manual sync trigger — no need to wait for the scheduled run
* Smart upsert logic — only writes to the database when data has actually changed
* Optional deletion sync — trash WordPress content when it's removed from EvangelOS
* Lightweight — no bloat, no third-party dependencies, uses WordPress core HTTP APIs

= Requirements =

* An active [EvangelOS](https://getevangelos.com) account
* An API key generated in EvangelOS under **Settings → API**
* For prayer requests: a Website Guest member created in EvangelOS and the `MEMBER_PORTAL_ACCESS` permission enabled on your API key

== Installation ==

1. Upload the `evangelos-sync` folder to the `/wp-content/plugins/` directory, or install directly through the WordPress Plugins screen.
2. Activate the plugin through the **Plugins** screen in WordPress.
3. Go to **EvangelOS → Settings** in the WordPress admin sidebar.
4. Enter your **EvangelOS API URL** (default: `https://api.evangelos.app`) and your **API Key** (starts with `ek_`).
5. Click **Save Settings**, then click **Test Connection** to confirm everything is working.
6. Configure your sync schedule and choose which content types to sync.
7. To enable prayer requests: create a member named **"Website Guest"** in EvangelOS, copy their Member ID, and paste it into the **Prayer Requests** section. Then add `[evangelos_prayer_request]` to any page — or use the `/prayer-requests/` page created automatically on activation.

== Frequently Asked Questions ==

= Where do I get an API key? =

Log in to your EvangelOS account, go to **Settings → API**, and generate a new key. Keys start with `ek_`. Keep your key private — it provides access to your organization's data.

= What is the "Website Guest" member? =

When a visitor submits a prayer request through your website, EvangelOS needs a member to file it under. Create a placeholder member in EvangelOS called "Website Guest" (or similar), then copy their Member ID (a UUID) into the plugin's Prayer Requests settings. The visitor's name and email are appended to the request text so your pastoral team knows who sent it.

= How often does the sync run? =

You can choose hourly, twice daily (every 12 hours), or daily. You can also trigger a manual sync at any time from the **Sync Status** tab. Sync runs are powered by WordPress cron (`wp-cron`), so they depend on site traffic. On low-traffic sites, consider using a server-side cron job to call `wp-cron.php` directly.

= Will it overwrite content I've edited in WordPress? =

The plugin uses an update-timestamp check — if EvangelOS reports that a record hasn't changed since the last sync, the WordPress post is left untouched. However, if the record is updated in EvangelOS, the sync will overwrite the WordPress post content with the new data from EvangelOS. Treat EvangelOS as the source of truth for synced content.

= What happens to events deleted in EvangelOS? =

By default, nothing — the WordPress post is left in place. If you enable **Trash WordPress events deleted in EvangelOS** in Settings, deleted events will be moved to the WordPress Trash (not permanently deleted) on the next sync.

= Can I use this without an EvangelOS account? =

No — the plugin requires a live EvangelOS account and API key to function. Visit [getevangelos.com](https://getevangelos.com) to learn more.

= Does this work with any WordPress theme? =

The event sync creates a `church_event` custom post type. Your theme needs to support (or at least not conflict with) custom post types to display events. The communications sync uses standard WordPress posts, which work with any theme. The prayer request form renders with basic styles that you can override in your theme's CSS.

= Is my API key stored securely? =

Your API key is stored in the WordPress options table, the same way WordPress stores all plugin settings. For additional security, we recommend restricting database access on your server and using a dedicated low-permission API key in EvangelOS that is scoped to read-only access (plus `MEMBER_PORTAL_ACCESS` if using prayer requests).

== Screenshots ==

1. The EvangelOS Sync settings page — configure your API key, sync schedule, and content filters.
2. The Sync Status tab — view last/next sync time and a detailed history of the last 25 runs.
3. The prayer request form rendered on the front end using the `[evangelos_prayer_request]` shortcode.

== Changelog ==

= 1.0.1 =
* Fix: "Email" is now a selectable communication type in Settings, matching what the sync engine already supported (previously arbitrarily limited to four of the five supported types).
* Fix: Escape the admin settings link output with `esc_url()` / `esc_html__()` (late escaping).

= 1.0.0 =
* Initial release.
* Events sync: EvangelOS events → `church_event` custom post type with full field mapping.
* Communications sync: Sent EvangelOS communications → WordPress posts organized by category.
* Prayer requests: `[evangelos_prayer_request]` shortcode with AJAX form submission.
* Admin UI: two-tab settings and sync status page with branded header, connection tester, manual sync, and 25-run history.
* Configurable cron schedule (hourly / twice daily / daily) with auto-reschedule on settings change.
* Smart upsert logic with change-detection to minimize unnecessary database writes.

== Upgrade Notice ==

= 1.0.1 =
Fixes a settings escaping issue and unlocks the Email communication type in the sync settings.

= 1.0.0 =
Initial release — no upgrade steps required.
