=== SeoCms Post Archival System ===
Contributors: SeoPageHost
Tags: archive, posts, database, cleanup, maintenance
Requires at least: 6.2
Tested up to: 6.9
Stable tag: 1.0.2
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Archive old posts and custom post types to a separate database based on configurable age rules.

== Description ==

SeoCms Post Archival System lets you move old posts and custom post types to a separate archive database, keeping your main WordPress database lean and fast.

**Key Features:**

* **Age-based archival rules** — Configure per-post-type rules (e.g., archive posts older than 180 days)
* **Custom post type support** — Works with any registered post type
* **Full data preservation** — Archives posts, post meta, and taxonomy relationships
* **One-click restore** — Restore archived posts back to the main database with all metadata intact
* **Scheduled archival** — Automate archival via WP-Cron (hourly, daily, weekly, or monthly)
* **Manual batch runs** — Run archival on-demand from the dashboard
* **Archive browser** — Search, filter, and browse archived posts from the admin panel
* **Front-end search** — Use the `[seocpoar_search]` shortcode to let visitors search archived content
* **Activity logging** — Full audit trail of all archive and restore actions

**How It Works:**

1. Configure a second MySQL database in Settings
2. Set up archival rules per post type with age thresholds
3. Run archival manually or on a schedule
4. Archived posts are moved to the separate database with all their metadata
5. Browse and restore archived posts at any time

**Shortcode Usage:**

Display a searchable archive browser on any page:

`[seocpoar_search]`
`[seocpoar_search per_page="20"]`
`[seocpoar_search per_page="10" post_type="post"]`

== Installation ==

1. Upload the `seocms-post-archival-system` folder to `/wp-content/plugins/`
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Create a separate MySQL database for the archive (e.g., `wp_archive`)
4. Go to **Archival > Settings** and enter the archive database credentials
5. Click **Test Connection** to verify, then **Initialize Tables** to create the archive schema
6. Go to **Archival > Rules** and add archival rules for your post types
7. Go to **Archival > Dashboard** and click **Run Archival Now**, or enable scheduled archival

= Requirements =

* WordPress 5.3 or higher
* PHP 7.4 or higher (compatible with PHP 8.0, 8.1, 8.2, and 8.3)
* A separate MySQL/MariaDB database for the archive
* The WordPress database user must have access to the archive database

== Frequently Asked Questions ==

= Does this delete my posts? =

By default, yes — posts are removed from the main database after being archived. You can disable this in Settings by unchecking "Delete after archiving", which keeps posts in both databases.

= Can I restore archived posts? =

Yes. Use the Archive Browser in the admin panel or the front-end shortcode to find archived posts, then click "Restore" to bring them back to the main database with all metadata intact.

= Does it archive comments? =

Not in the current version. Only posts, post meta, and taxonomy relationships are archived. Comment archival is planned for a future release.

= Does it work with custom post types? =

Yes. Any registered public post type can have its own archival rule with a custom age threshold.

= Can I use it on a multisite network? =

The plugin works on individual sites within a multisite network. Full multisite support with shared archive databases is planned for a future release.

= What happens if the archive database is unavailable? =

The plugin will return an error message and no posts will be archived or deleted. Your main database is never modified unless the archive operation succeeds first.

= Is the archive database connection secure? =

Database credentials are stored in the WordPress options table (same as wp-config.php credentials). Passwords are masked in the admin UI.

== Screenshots ==

1. Dashboard — Overview with statistics, quick actions, and recent activity
2. Settings — Archive database configuration and scheduling options
3. Archival Rules — Per-post-type age thresholds and status filters
4. Archive Browser — Search and restore archived posts
5. Activity Log — Full audit trail of archive and restore actions
6. Front-end Search — Shortcode-powered archive search for visitors

== Changelog ==

= 1.0.2 =
* Renamed all internal identifiers to use unique `seocpoar_` / `Seocpoar` / `SEOCPOAR_` prefix per WordPress.org reviewer feedback (replaces reserved `wp_`-prefixed names)
* Namespace changed from `WP_Archival` to `Seocpoar`
* Plugin constants renamed `WP_ARCHIVAL_*` → `SEOCPOAR_*`
* Option keys renamed `wp_archival_*` → `seocpoar_*`
* Cron hook renamed `wp_archival_scheduled_run` → `seocpoar_scheduled_run`
* AJAX action suffixes renamed `wp_archival_*` → `seocpoar_*`
* Shortcode renamed `[wp_archival_search]` → `[seocpoar_search]`
* Custom action hooks renamed `wp_archival_post_archived/restored` → `seocpoar_post_archived/restored`
* Log table renamed `{prefix}archival_log` → `{prefix}seocpoar_log`
* Front-end CSS classes renamed `.wpa-*` → `.seocpoar-*`
* URL query params renamed `wpa_view/search/page` → `seocpoar_view/search/page`
* Default archive table prefix changed from `wpa_` to `seocpoar_`

= 1.0.1 =
* Hardened output escaping for all `number_format_i18n()` calls
* Refactored database queries to use `%i` placeholder for table/column identifiers (requires WP 6.2+)
* Refactored Logger ORDER BY to use literal ASC/DESC branches (no variable concat in SQL)
* Prefixed template-scope variables with `seocpoar_` for WordPress coding standards compliance
* Added direct file access protection to bundled CLI test scripts
* Bumped minimum WordPress requirement from 5.3 to 6.2
* Tested up to WordPress 6.9

= 1.0.0 =
* Initial release
* Age-based archival rules per post type
* Archive posts, post meta, and taxonomies to separate database
* One-click restore from archive
* Scheduled archival via WP-Cron
* Admin dashboard with statistics
* Archive browser with search and filtering
* Activity logging
* Front-end shortcode for archive search
* Single archived post view within theme

== Upgrade Notice ==

= 1.0.2 =
Major internal rename to comply with WordPress.org guidelines on unique prefixes. Includes a one-time data migration on activation that moves existing options and the log table to the new prefix.

= 1.0.1 =
Security hardening, code-standards compliance, and WP 6.2+ compatibility improvements. Recommended for all users.

= 1.0.0 =
Initial release.
