# Andrew Harper Travel WordPress Plugin

A comprehensive WordPress plugin for managing the Andrew Harper Travel website, including membership management, payment processing, API integration, and content delivery.

## Description

The Andrew Harper Travel plugin provides a complete solution for managing a premium travel membership website. It integrates with external APIs, handles member authentication via SAML, processes payments through Stripe, and manages content across multiple publication types.

## Features

- **Member Account Management** - User registration, login, profile management
- **Payment Processing** - Stripe integration for subscriptions and payments
- **API Integration** - Connects to Andrew Harper Travel API for member data
- **SAML Authentication** - Single sign-on capability
- **Search Integration** - Algolia-powered search functionality
- **Shopping Cart** - Custom cart implementation for memberships and products
- **Multiple Publication Types** - Hideaway Report, Harper Collection, Directory, Traveler, Cruises
- **Content Management** - Hotels, brands, exclusive experiences, editor's choice

## Installation

1. Upload the `andrew-harper-plugin` folder to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Navigate to **AH Settings** in the WordPress admin menu to configure the plugin

## Configuration

After activating the plugin, you need to configure the settings through the WordPress admin interface:

### Accessing Settings

Go to **WordPress Admin → AH Settings** to access the configuration page.

### Settings Sections

#### 1. API Configuration

Configure the Andrew Harper Travel API connection:

- **API Endpoint** - The base URL for the Andrew Harper API
  - Default: `https://preprod-api.andrewharper.com`
  - Production: Update to your production API URL
  
- **API Service Token** - Authentication token for API requests
  - Required for all API communications
  
- **Site URL** - The main website URL
  - Default: `https://preprod.andrewharper.com`
  - Update for production environment

- **Cache Directory** - Full server path to the cache directory
  - Default: `/var/www/html/cache/`
  - Must be writable by the web server
  - Used for caching API responses

#### 2. Algolia Configuration

Configure the Algolia search integration:

- **Algolia Application ID** - Your Algolia application identifier
  - Format: Alphanumeric string (e.g., `JNDHLV9SL9`)
  
- **Algolia Write API Key** - API key with write permissions
  - Required for indexing content
  - Keep this key secure

#### 3. SAML Configuration

Configure SAML authentication for single sign-on:

- **SimpleSAML URL** - The SAML identity provider endpoint
  - Default: `https://preprod-h360.andrewharper.com/simplesaml/saml2/idp/SSOService.php?spentityid=AHTRevelexAuth`
  - Update for your SAML provider

#### 4. Stripe Configuration

Configure payment processing:

- **Stripe Publishable Key** - Your Stripe public API key
  - Live keys start with: `pk_live_`
  - Test keys start with: `pk_test_`
  - Default: Uses live key
  - Used in frontend JavaScript
  - Switch to test key for development/testing

- **Stripe Secret Key** - Your Stripe secret API key
  - Live keys start with: `sk_live_`
  - Test keys start with: `sk_test_`
  - Used for server-side payment processing
  - **Keep this secure** - Never expose in frontend code

#### 5. Page IDs Configuration

Map WordPress page IDs to plugin functionality. These pages must exist in your WordPress installation:

| Setting | Description | Default ID |
|---------|-------------|------------|
| **Checkout Page ID** | Main checkout page | 1963 |
| **Checkout Success Page ID** | Post-purchase confirmation | 17830 |
| **Hideaway Report Details Page ID** | Hideaway Report content page | 14983 |
| **Harper Collection Details Page ID** | Harper Collection content page | 14985 |
| **Directory Details Page ID** | Directory listing page | 22735 |
| **Traveler Details Page ID** | Traveler magazine page | 22737 |
| **Cruise Details Page ID** | Cruise offerings page | 19067 |
| **Editors Choice Page ID** | Editor's choice content | 27617 |
| **Hotel Details Page ID** | Hotel information page | 562 |
| **Brands Details Page ID** | Brand showcase page | 27974 |
| **Exclusive Experiences Page ID** | Special experiences page | 30905 |

### Updating Page IDs

To find page IDs in WordPress:
1. Go to **Pages → All Pages**
2. Hover over a page title
3. Look at the browser's status bar or the URL preview
4. The ID appears as `post=###` in the URL

## Environment Setup

### Development vs. Production

The plugin supports multiple environments. When moving from development to production:

1. **Update API Endpoint** - Change to production API URL
2. **Update Site URL** - Change to production website URL
3. **Update SAML URL** - Change to production SAML provider
4. **Update Stripe Keys** - Switch from test keys (`pk_test_`, `sk_test_`) to live keys (`pk_live_`, `sk_live_`)
5. **Verify Page IDs** - Ensure page IDs match your production WordPress installation
6. **Update Cache Directory** - Verify the cache directory path exists and is writable

### Security Best Practices

- **API Tokens** - Keep service tokens secure and rotate regularly
- **Stripe Keys** - Never expose secret keys; only publishable keys are used in frontend
- **Algolia Keys** - Use write keys only where necessary; use search-only keys for frontend
- **HTTPS** - Always use HTTPS in production for all API endpoints
- **File Permissions** - Ensure cache directory has appropriate permissions (typically 755 or 775)

## Usage

### For Site Administrators

The plugin automatically integrates with your WordPress site once configured. Key features are accessible through:

- **Admin Menu** - Settings and configuration at **AH Settings**
- **Custom Pages** - Content pages defined in Page IDs configuration
- **User Accounts** - Member management through custom templates

### For Developers

#### Main Plugin File
Located at: `andrewharper.php`

#### Settings File
PHP constants defined in: `settings/settings.php`
- All constants now read from WordPress options
- Fallback to default values if options not set

#### Class Structure
- **Andrewharper** - Core plugin class (`includes/class-andrewharper.php`)
- **Andrewharper_Admin** - Admin functionality (`admin/class-andrewharper-admin.php`)
- **Andrewharper_Public** - Frontend functionality (`public/class-andrewharper-public.php`)
- **UserAccount** - Member account management (`includes/class.useraccount.php`)
- **AHTAPI** - API wrapper (`includes/class.ahtapi.php`)
- **ShoppingCart** - Cart functionality (`includes/class.shoppingcart.php`)

#### JavaScript Settings
File: `settings/settings.js`
- Stripe key loaded via `wp_localize_script`
- Accessible globally as `window.stripeKey`
- Configuration values available in `ahPluginSettings` object

## Templates

Custom page templates are located in the `templates/` directory:

- `homepage.php` - Main homepage
- `checkout.php` - Checkout process
- `my-account.php` - Member account dashboard
- Various publication templates (hideaway-report, traveler, etc.)

## Hooks and Filters

The plugin uses WordPress hooks extensively. Key hooks are defined in:
- `includes/class-andrewharper-loader.php` - Hook loader
- Admin hooks registered in `define_admin_hooks()`
- Public hooks registered in `define_public_hooks()`

## Support

For issues or questions:
- **Developer**: O2 Digital Creative Agency
- **Website**: [o2dca.com](https://o2dca.com)

## Version

**Current Version**: 2.2.14

## License

GPL-2.0+
License URI: [http://www.gnu.org/licenses/gpl-2.0.txt](http://www.gnu.org/licenses/gpl-2.0.txt)

## Changelog

### Version 2.2.14
- Fix: Missing HTML code for spinner in refer a friend form

### Version 2.2.12
- Better UX for refer a friend form

### Version 2.2.1
- **Code Portability Improvements**: Standardized all file path constants throughout the plugin
- **Constant Standardization**: Replaced all occurrences of `plugin_dir_path()` with `AHT_PLUGIN_FOLDER` constant
- **Template Path Unification**: Consolidated template path constants by replacing `AHT_THEME_TEMPLATE_FOLDER` with `AHT_PLUGIN_TEMPLATE_FOLDER`
- **Updated Core Plugin File**: Modified `includes/class-andrewharper.php` to use consistent path constants
- **Updated Template Files**: Updated 17+ template files to use unified `AHT_PLUGIN_TEMPLATE_FOLDER` constant
- **Improved Maintainability**: Centralized path management makes future updates and migrations easier
- **Enhanced Code Consistency**: All file includes now follow the same pattern using defined constants
- Constant AH_PLUGIN_TEMPLATE_ROUTE moved from wp-config.php file to plugin main file.

### Version 2.1.0
- Added comprehensive settings management interface accessible via WordPress admin
- Integrated WordPress options for all configuration values
- Added Stripe publishable and secret key configuration
- Added cache directory configuration for API response caching
- Updated all PHP constants to read from database with fallback to default values
- Replaced all hardcoded plugin paths in JavaScript files with dynamic URLs
- Added `pluginUrl` to localized JavaScript settings for proper path resolution
- Improved security with proper settings sanitization and password field types for sensitive keys
- All hardcoded values now configurable via admin interface
- Enhanced portability across different WordPress installations
- Updated 19+ JavaScript files to use dynamic plugin URLs instead of hardcoded paths

### Version 1.0.3
- Initial stable release
- Core functionality implementation

---

**Note**: Always backup your database before updating plugin settings or migrating between environments.
