WPForms to Mailjet Automation Plugin
Complete Directory Structure
=====================================

wpforms-mailjet-automation/
│
├── wpforms-mailjet-automation.php          [Main plugin file with headers and initialization]
├── uninstall.php                           [Cleanup script for plugin removal]
├── index.php                               [Silence is golden - security file]
├── wpfmj-config-sample.php                 [Sample configuration file - NEW in 1.0.2]
├── .gitignore                              [Git exclusions - NEW in 1.0.2]
├── package.json                            [Node.js dependencies - CREATE THIS]
├── BUILD-INSTRUCTIONS.md                   [Build and deployment instructions]
├── DIRECTORY-STRUCTURE.txt                 [This file]
├── CONFIGURATION-GUIDE.md                  [Configuration documentation - NEW in 1.0.2]
├── PLUGIN-SUMMARY.md                       [Plugin overview and features]
├── QUICK-REFERENCE.md                      [Quick file reference]
├── SECURITY-AUDIT-REPORT.md                [Complete security audit]
├── SECURITY-FIXES-SUMMARY.md               [Security fix details]
└── FINAL-SECURITY-SUMMARY.md               [Final security status - NEW in 1.0.2]
│
├── includes/                               [Core plugin classes]
│   ├── index.php                          [Silence is golden]
│   ├── class-wpfmj-activator.php          [Plugin activation handler]
│   ├── class-wpfmj-deactivator.php        [Plugin deactivation handler]
│   ├── class-wpfmj-loader.php             [Hook registration system]
│   ├── class-wpfmj-core.php               [Main plugin orchestrator]
│   ├── class-wpfmj-cpt.php                [Custom post type registration]
│   ├── class-wpfmj-encryption.php         [AES-256 encryption for API keys]
│   ├── class-wpfmj-mailjet-api.php        [Mailjet API wrapper]
│   ├── class-wpfmj-form-handler.php       [WPForms submission processor]
│   └── class-wpfmj-error-logger.php       [Error logging and management]
│
├── admin/                                  [Admin interface components]
│   ├── index.php                          [Silence is golden]
│   ├── class-wpfmj-admin.php              [Admin functionality and AJAX handlers]
│   ├── class-wpfmj-dashboard.php          [Dashboard page renderer]
│   │
│   ├── css/                               [Admin stylesheets]
│   │   ├── index.php                      [Silence is golden]
│   │   └── wpfmj-admin.css                [Dashboard and wizard styles]
│   │
│   └── js/                                [Admin JavaScript]
│       ├── index.php                      [Silence is golden]
│       ├── wpfmj-wizard.js                [React bundle - GENERATED BY BUILD]
│       └── wpfmj-wizard.asset.php         [Dependency manifest for React bundle]
│
└── assets/                                 [Source assets for building]
    ├── index.php                          [Silence is golden]
    └── src/                               [React source code]
        ├── index.php                      [Silence is golden]
        └── wizard/                        [Wizard React application]
            ├── index.php                  [Silence is golden]
            ├── App.jsx                    [Main wizard component with step routing]
            │
            ├── components/                [Wizard step components]
            │   ├── index.php              [Silence is golden]
            │   ├── StepOne.jsx            [Step 1: Choose form and title]
            │   ├── StepTwo.jsx            [Step 2: Map email, firstname, lastname]
            │   ├── StepThree.jsx          [Step 3: Select trigger field]
            │   ├── StepFour.jsx           [Step 4: Connect Mailjet API]
            │   ├── StepFive.jsx           [Step 5: Map answers to lists]
            │   └── StepSix.jsx            [Step 6: Review and save]
            │
            └── utils/                     [Utility functions]
                ├── index.php              [Silence is golden]
                └── api.js                 [AJAX API wrapper functions]


FILE COUNTS:
============
Total PHP Files: 16 (includes wpfmj-config-sample.php)
Total React Components: 8 (.jsx files)
Total JavaScript Files: 2 (.js files)
Total CSS Files: 1
Total "Silence is golden" index.php files: 9
Total Markdown Documentation: 8 (was 1)
Total Config Files: 2 (.gitignore, wpfmj-config-sample.php)

TOTAL FILES: 46 (44 source + 2 optional/generated)


BUILD ARTIFACTS (Generated by npm run build):
==============================================
These files are CREATED by the build process and should NOT be manually created:

admin/js/wpfmj-wizard.js                   [Compiled React bundle]
admin/js/wpfmj-wizard.asset.php            [Auto-generated dependency file]


INSTALLATION ORDER:
===================
1. Create all directories
2. Place all PHP files in their respective directories
3. Place React .jsx files in assets/src/wizard/ structure
4. Place api.js in assets/src/wizard/utils/
5. Place wpfmj-admin.css in admin/css/
6. Place all "index.php" security files (copy the same one to each directory)
7. Create package.json in root from BUILD-INSTRUCTIONS.md template
8. Run 'npm install' in root directory
9. Run 'npm run build' to generate the React bundle
10. Upload entire folder to wp-content/plugins/
11. Activate in WordPress admin


SECURITY FILES (index.php - "Silence is golden"):
==================================================
Place identical index.php file in these 9 locations:
- Root: wpforms-mailjet-automation/index.php
- includes/index.php
- admin/index.php
- admin/css/index.php
- admin/js/index.php
- assets/index.php
- assets/src/index.php
- assets/src/wizard/index.php
- assets/src/wizard/components/index.php
- assets/src/wizard/utils/index.php

Content of each:
<?php
// Silence is golden.


DATABASE TABLES CREATED:
========================
wp_wpfmj_error_log          [Error logging with automatic 90-day cleanup]

Fields:
- id (bigint, primary key, auto increment)
- automation_id (bigint, indexed)
- form_entry_id (bigint)
- error_type (varchar 50)
- error_message (text)
- retry_count (int, default 0)
- resolved (tinyint, default 0, indexed)
- created_at (datetime, indexed)
- updated_at (datetime)


CUSTOM POST TYPES:
==================
wpfmj_automation            [Stores automation configurations]

Post Meta Keys:
- _wpfmj_config             [JSON configuration object]
- _wpfmj_form_id            [WPForm ID for quick lookups]


WORDPRESS OPTIONS:
==================
- wpfmj_version             [Plugin version number]
- wpfmj_encryption_key      [Base64 encoded AES-256 key, not autoloaded]


CRON JOBS:
==========
- wpfmj_cleanup_error_logs  [Weekly cleanup of resolved errors older than 90 days]


WORDPRESS HOOKS USED:
=====================
Actions:
- plugins_loaded            [Initialize plugin after dependency check]
- before_woocommerce_init  [Declare HPOS compatibility]
- init                      [Register custom post type]
- admin_menu                [Add admin menu pages]
- admin_enqueue_scripts     [Load admin assets]
- wpforms_process_complete  [Handle form submissions]
- All wp_ajax_* actions     [AJAX endpoints]

Filters:
- None currently used


CAPABILITIES REQUIRED:
======================
- manage_options            [Required for all admin operations]


MAILJET API ENDPOINTS USED:
============================
- GET  /contact             [Test connection]
- GET  /contactslist        [Fetch all lists]
- GET  /contact/{email}     [Check if contact exists]
- POST /contact             [Create new contact]
- PUT  /contactdata/{email} [Update contact properties]
- POST /contactslist/{id}/managecontact [Add contact to list]


AJAX ACTIONS:
=============
- wpfmj_get_forms           [Fetch all WPForms]
- wpfmj_get_form_fields     [Fetch fields for specific form]
- wpfmj_test_mailjet        [Test API credentials]
- wpfmj_get_mailjet_lists   [Fetch Mailjet lists]
- wpfmj_save_automation     [Save/update automation]
- wpfmj_get_automation      [Load automation for editing]
- wpfmj_toggle_automation   [Activate/pause automation]
- wpfmj_delete_automation   [Delete automation]
- wpfmj_get_dashboard_data  [Load dashboard table data]


SUPPORTED FIELD TYPES:
======================
For Contact Mapping:
- All WPForms field types (email, firstname, lastname)

For Trigger Fields:
- checkbox
- radio
- select (dropdown)
- payment-checkbox
- payment-multiple
- payment-select
- Any field type with a 'choices' array


NOTES:
======
- All API credentials are encrypted using AES-256-CBC
- Retry logic: 3 attempts with exponential backoff (1s, 2s, 4s)
- Email notification sent to admin after all retries fail
- Dashboard uses vanilla JavaScript (jQuery) for simplicity
- Wizard uses React with @wordpress/components for consistency
- No localStorage/sessionStorage used (not supported in WordPress admin)
- All data stored server-side in custom post type
- Plugin is fully uninstall-safe (removes all data on deletion)
