File: /var/www/bharti-foundation.stgviitor.com/wp-content/themes/lifeline/LICENSE_README.md
# Lifeline Theme Licensing System
A comprehensive theme licensing system for the Lifeline WordPress theme that integrates with Envato's API to validate purchase codes and restrict demo content import to licensed users.
## Features
- **Purchase Code Validation**: Validates Envato purchase codes against the official API
- **Demo Import Restriction**: Prevents demo content import without a valid license
- **Beautiful Admin Interface**: Modern, responsive design that matches WordPress admin
- **Security Features**: Nonce verification, capability checks, and duplicate activation prevention
- **Easy Configuration**: Centralized configuration file for easy customization
- **AJAX Support**: Smooth user experience with real-time validation
## Installation
### 1. Files Structure
The licensing system consists of the following files:
```
wp-content/themes/lifeline/
├── includes/
│ ├── Classes/
│ │ ├── LicenseManager.php # Main license management class
│ │ ├── LicenseConfig.php # Configuration constants
│ │ └── LicenseSetup.php # Setup instructions
│ └── assets/
│ ├── css/
│ │ └── license-admin.css # Admin page styling
│ └── js/
│ └── license-admin.js # Admin page functionality
```
### 2. Integration
The system is automatically integrated into the theme through the `Setup` class. No additional integration code is required.
## Configuration
### 1. Envato API Token
You need to obtain an Envato API token to validate purchase codes:
1. Go to [https://build.envato.com/my-apps/](https://build.envato.com/my-apps/)
2. Sign in with your Envato account
3. Click "Create App"
4. Fill in the app details:
- **App Name**: Lifeline Theme License Manager
- **App Type**: Server to Server
- **Redirect URI**: Leave blank
5. Click "Create App"
6. Copy your Personal Token
### 2. Configure the Token
You have two options to store your API token:
#### Option 1: wp-config.php (Recommended)
Add this line to your `wp-config.php` file:
```php
define('ENVATO_API_TOKEN', 'your_token_here');
```
#### Option 2: Theme Options
Add this code to your `functions.php`:
```php
update_option('lifeline_envato_token', 'your_token_here');
```
### 3. Update Supported Item IDs
In `wp-content/themes/lifeline/includes/Classes/LicenseConfig.php`, update the `SUPPORTED_ITEM_IDS` constant with your actual Envato theme item IDs:
```php
const SUPPORTED_ITEM_IDS = array(
'12345678', // Replace with actual Lifeline theme item ID
'87654321', // Replace with other Lifeline theme variations if any
);
```
To find your item ID:
1. Go to your theme page on Envato
2. Look at the URL - it will contain the item ID
3. Example: `https://themeforest.net/item/lifeline/12345678`
## Usage
### 1. Admin Interface
Once configured, users can access the license management page at:
**Appearance > Theme License**
### 2. License Activation
1. Navigate to Appearance > Theme License
2. Enter the Envato purchase code
3. Click "Activate License"
4. The system will validate the code against Envato's API
5. If successful, the license is activated
### 3. Demo Content Import
After license activation:
1. Users can access **Appearance > Import Lifeline Demo Data**
2. The One Click Demo Import plugin will work normally
3. Without a license, demo import is blocked
### 4. License Deactivation
Users can deactivate their license:
1. Go to Appearance > Theme License
2. Click "Deactivate License"
3. Confirm the action
4. Demo import will be blocked again
## Security Features
- **Nonce Verification**: All forms and AJAX requests use WordPress nonces
- **Capability Checks**: Only users with `manage_options` capability can manage licenses
- **Input Sanitization**: All user inputs are properly sanitized
- **API Validation**: Purchase codes are validated against Envato's official API
- **Duplicate Prevention**: Each license can only be active on one domain
## Customization
### 1. Modify Error Messages
Edit the `ERROR_MESSAGES` constant in `LicenseConfig.php`:
```php
const ERROR_MESSAGES = array(
'missing_code' => 'Please enter a purchase code.',
'invalid_code' => 'Invalid purchase code.',
// Add your custom messages here
);
```
### 2. Change Required Capability
Modify the `REQUIRED_CAPABILITY` constant in `LicenseConfig.php`:
```php
const REQUIRED_CAPABILITY = 'manage_options'; // Change to your preferred capability
```
### 3. Customize Styling
Modify `wp-content/themes/lifeline/assets/css/license-admin.css` to match your theme's design.
### 4. Add Custom Validation
Extend the `LicenseManager` class to add custom validation logic:
```php
class CustomLicenseManager extends LicenseManager {
protected function custom_validation($purchase_code) {
// Add your custom validation logic
return true;
}
}
```
## Troubleshooting
### Common Issues
1. **"Failed to connect to Envato API"**
- Check your API token
- Verify internet connection
- Ensure the token has the correct permissions
2. **"Invalid purchase code"**
- Verify the purchase code is correct
- Check if the code has expired
- Ensure the code is for the correct theme
3. **"Wrong item"**
- Update `SUPPORTED_ITEM_IDS` with correct theme item IDs
- Verify the purchase code belongs to your theme
4. **"Already active elsewhere"**
- This is a security feature to prevent license sharing
- Each license can only be active on one domain
### Debug Mode
Enable WordPress debug mode to see detailed error messages:
```php
// In wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
```
## API Reference
### LicenseManager Class
#### Methods
- `is_license_valid()` - Check if license is currently valid
- `get_current_license()` - Get the current license purchase code
- `check_license_before_import()` - Hook for demo import restriction
#### Hooks
- `ocdi/plugin_page_setup` - Modifies demo import page setup
- `ocdi/before_import` - Checks license before demo import
### LicenseConfig Class
#### Constants
- `ENVATO_API_URL` - Envato API endpoint
- `SUPPORTED_ITEM_IDS` - Array of supported theme item IDs
- `LICENSE_OPTION` - WordPress option name for license storage
- `REQUIRED_CAPABILITY` - User capability required for license management
## Support
For support and questions:
1. Check the troubleshooting section above
2. Review the error logs
3. Verify your configuration
4. Contact theme support
## Changelog
### Version 1.0.0
- Initial release
- Envato API integration
- Demo import restriction
- Beautiful admin interface
- Security features
## License
This licensing system is part of the Lifeline theme and follows the same license terms.
---
**Note**: This system is designed for legitimate theme distribution. Please ensure compliance with Envato's terms of service and WordPress.org guidelines.