=== DeepClick — Inventor of ReflowLink ===
Contributors: deepclick
Tags: integration, sdk, deepclick
Requires at least: 5.0
Tested up to: 6.9
Stable tag: 1.0.3
Requires PHP: 7.4
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Official DeepClick extension for WordPress integration.

== Description ==

This is the official DeepClick Reflow for Wordpress plugin that connects your Wordpress website to DeepClick Reflow. This plugin allows you to get users to view ads one more time, push messages to churned users, and retain users in your private domain, achieving "1 click, 2 impressions."

DeepClick Reflow has the following core functions and features:

* **Fallback Page:** Gain 10-20% more clicks.
* **Audience Recovery:** Restore and back up Facebook audience.
* **Claim Resolution:** Cut down 80% of ad-related complaints.
* **Green Shield:** No more landing page bans.
* **Push Notifications:** Push messages to users who left ads.
* **PWA Retargeting:** Add website to homescreen like apps.

## Installation

### Method 1: WordPress Admin Panel

1. Upload the plugin folder to `/wp-content/plugins/` directory
2. Go to WordPress Admin → Plugins
3. Activate "DeepClick Reflow" plugin

### Method 2: Upload ZIP

1. Compress the plugin files into a ZIP file
2. Go to WordPress Admin → Plugins → Add New → Upload Plugin
3. Select the ZIP file and install
4. Activate the plugin

## Usage

### Initial Setup

1. After activation, navigate to **DeepClick Reflow** in WordPress admin menu
2. You will see one of two states:

   **Not Installed State:**
   - Shows an "Authorize" button
   - Click to open DeepClick console in a new tab for authorization

   **Installed State:**
   - Displays app information including:
     - App icon
     - App name
     - App description

### Frontend SDK Injection

Once configured with `sdk_code` and `mch_id`, the plugin automatically injects the DeepClick JS SDK on WordPress frontend pages (not in admin area). The script is only loaded when both `sdk_code` and `mch_id` are properly configured. The script is loaded with `defer` attribute for optimal performance.

The injected script URL format:
```
https://storage.deepclick.com/dc-cdn/js-sdk/{environment}/deep-click.js?mch_id={mch_id}&sdk_code={sdk_code}&integration_type=wordpress&from_source=app_stores
```

**Note:** The SDK is only injected on frontend pages when the plugin is properly configured. If `sdk_code` or `mch_id` is missing, the script will not be loaded.

## File Structure

```
deepclick/
├── deepclick.php  # Main plugin file (plugin name:DeepClick Reflow)
└── README.md          # Documentation
```

## System Requirements

- WordPress 5.0 or higher
- PHP 7.4 or higher

## Data Storage

The plugin stores configuration data in WordPress `wp_options` table:

- `deepre_app_installed`: Boolean flag indicating installation status
- `deepre_app_info`: Array containing:
  - `icon`: App icon URL
  - `name`: App name
  - `sdk_code`: SDK code for integration
  - `mch_id`: Merchant ID

All data is automatically removed when the plugin is uninstalled.

## Security

- Direct file access protection
- Input sanitization for all user data
- URL escaping for external links
- REST API endpoint requires `manage_options` capability (admin users only)

## Development Notes

### Key Components

1. **Deepre_Plugin Class**: Main plugin class handling all functionality
2. **Admin Menu**: Standalone menu in WordPress admin panel
3. **REST API Webhook**: Receives external configuration updates
4. **Script Enqueuing**: Proper WordPress way to inject external scripts
5. **Uninstall Hook**: Ensures clean removal of plugin data

### WordPress Best Practices

- Uses `wp_enqueue_script()` for script injection
- Implements `wp_script_add_data()` for defer attribute
- Follows WordPress coding standards
- Uses WordPress sanitization functions
- Implements proper uninstall hook

## Customization

### Authorization URL

To change the authorization URL, modify the `$deepre_auth_url` in the `admin_page()` method:

```php
$deepre_auth_url = 'https://console.deepclick.com/product-library?site_url=' . rawurlencode(get_site_url());
```

### Webhook Security

To add authentication to the webhook endpoint, modify the `permission_callback` in `register_rest_routes()`:

```php
'permission_callback' => function() {
    // Add your authentication logic here
    return current_user_can('manage_options');
}
```

## Uninstallation

When the plugin is uninstalled (not just deactivated), all stored data is automatically removed:

- `deepre_app_info` option
- `deepre_app_installed` option

This ensures no leftover data remains in your WordPress database.

== License ==

This plugin is licensed under GPLv3 or later.

== Upgrade Notice ==

= 1.0.1 =
Initial release of DeepClick Reflow plugin.

## Support

For issues or questions:

1. Verify WordPress and PHP versions meet requirements
2. Check browser console for JavaScript errors
3. Verify REST API endpoint is accessible

## Author

**DeepClick**
- Website: https://deepclick.com
- Plugin URI: https://deepclick.com
