Add notification email
This commit is contained in:
-25
@@ -1,25 +0,0 @@
|
||||
WordPress plugin for managing Go (Baduk/Weiqi) tournament registrations. Collects player data via frontend forms and exports entries to tournament management systems (Pairgoth, OpenGotha, McMahon, CSV).
|
||||
|
||||
**Relevant files:**
|
||||
- `main.php` - Plugin entry point with WordPress hooks
|
||||
- `go-form-plugin/go-form-plugin.php` - Core plugin logic (forms, entries, EGD integration, exports)
|
||||
- `go-form-plugin/database-schema.sql` - MySQL schema for 4 tables (forms, entries, custom_fields, entry_custom_values)
|
||||
- `go-form-plugin/export/csv.php` - CSV export handler
|
||||
- `go-form-plugin/export/pairgoth.php` - Pairgoth JSON export handler
|
||||
- `go-form-plugin/export/opengotha.php` - OpenGotha XML export handler
|
||||
- `go-form-plugin/export/mcmahon.php` - McMahon XML export handler
|
||||
- `go-form-plugin/export/mcmahon-help.php` - McMahon documentation/reference
|
||||
- `go-form-plugin/templates/form-shortcode.php` - Frontend form template
|
||||
- `go-form-plugin/templates/settings-page.php` - Admin dashboard template
|
||||
- `go-form-plugin/templates/table.php` - Entries table display
|
||||
- `README.md` - Full documentation
|
||||
|
||||
**Nuances:**
|
||||
- Ranks stored as integers (0-47): 0-29=30k-1k, 30-38=1d-9d, 39-47=1p-9p
|
||||
- Rating auto-calculated: `rating = (rank * 100) - 900`
|
||||
- EGD integration: searches `https://europeangodatabase.eu/EGD/GetPlayerDataByData.php` and `GetPlayerDataByPIN.php`
|
||||
- Uses WordPress nonces, `manage_options` capability, `$wpdb->prepare()` for security
|
||||
- Foreign keys with CASCADE delete
|
||||
|
||||
## To LLM
|
||||
Update this file if the changes you have done are worth updating here. The intent of this file is to give you a rough idea of the project, from where you can explore further, if needed.
|
||||
@@ -2,193 +2,11 @@
|
||||
|
||||
A WordPress plugin for managing Go (Baduk/Weiqi) tournament registrations. Collect player information through frontend forms and export entries to popular tournament management systems.
|
||||
|
||||
**Version:** 0.05
|
||||
|
||||
## Features
|
||||
|
||||
- **Frontend Registration Form** with shortcode support
|
||||
- **EGD Database Integration** - Search and auto-fill player data from the European Go Database
|
||||
- **Rank Selection** - Dropdown with ranks from 30k to 9p
|
||||
- **Automatic Rating Calculation** - Auto-computes rating from rank when needed
|
||||
- **Multiple Export Formats** - CSV, Pairgoth (JSON), OpenGotha (XML), McMahon (XML)
|
||||
- **Multi-Form Support** - Create and manage multiple registration forms
|
||||
- **Admin Dashboard** - View, delete, export entries, and manage forms
|
||||
- **Custom Fields** - Add unlimited custom fields (text, email, textarea, select, checkbox) to forms
|
||||
- **Entry Editing** - Edit existing registrations from admin panel
|
||||
- **EGD Data Sync** - Batch update rank and rating from EGD for all entries with EGD numbers
|
||||
- **Responsive Design** - Frontend form with grid layout
|
||||
|
||||
## Installation
|
||||
|
||||
1. Upload the `go-form-plugin` folder to your `/wp-content/plugins/` directory
|
||||
2. Activate the plugin through the 'Plugins' menu in WordPress
|
||||
3. A default form is automatically created on activation
|
||||
|
||||
## Usage
|
||||
|
||||
### Displaying a Form
|
||||
|
||||
Use the shortcode to display a registration form on any page or post:
|
||||
|
||||
```
|
||||
[go_form id=1]
|
||||
```
|
||||
|
||||
Replace `1` with your form ID. Find form IDs in the admin settings page.
|
||||
|
||||
### Admin Settings
|
||||
|
||||
Navigate to **Go Form** in the WordPress admin menu to:
|
||||
|
||||
- **Create Forms** - Add new registration forms with names
|
||||
- **Manage Forms** - View all forms with their shortcodes and IDs
|
||||
- **View Entries** - See all submissions for a form in a sortable table
|
||||
- **Edit Entries** - Modify existing player registrations
|
||||
- **Delete Entries** - Remove individual registrations
|
||||
- **Delete Forms** - Remove a form and all its entries (cascading delete)
|
||||
- **Export Data** - Download entries in various tournament formats
|
||||
- **Manage Custom Fields** - Add, edit, and delete custom fields per form
|
||||
- **EGD Data Sync** - Update rank and rating from EGD for all entries with EGD numbers
|
||||
|
||||
### EGD Search
|
||||
|
||||
Players can click the "Search EGD" button on the frontend form to look up their information in the European Go Database. This auto-fills:
|
||||
- First Name
|
||||
- Last Name
|
||||
- Country
|
||||
- Club
|
||||
- Rank
|
||||
- EGD Number
|
||||
- Rating
|
||||
|
||||
## Export Formats
|
||||
|
||||
| Format | File Extension | Description |
|
||||
|--------|---------------|-------------|
|
||||
| CSV | `.csv` | Standard spreadsheet format |
|
||||
| Pairgoth | `.tour` | JSON format for Pairgoth pairing system |
|
||||
| OpenGotha | `.xml` | XML format for OpenGotha tournament manager |
|
||||
| McMahon | `.xml` | XML format for McMahon tournament system |
|
||||
|
||||
## Database
|
||||
|
||||
The plugin creates four tables:
|
||||
|
||||
- `wp_go_form_forms` - Stores form definitions (id, name, created_at)
|
||||
- `wp_go_form_entries` - Stores all player registrations with Go-specific fields
|
||||
- `wp_go_form_custom_fields` - Stores custom field definitions per form
|
||||
- `wp_go_form_entry_custom_values` - Stores custom field values for each entry
|
||||
|
||||
All tables use foreign keys with CASCADE delete and are automatically removed when the plugin is uninstalled.
|
||||
|
||||
### Rank System
|
||||
|
||||
Ranks are stored as integers (0-47) mapping to:
|
||||
- 0-29: 30k to 1k
|
||||
- 30-38: 1d to 9d
|
||||
- 39-47: 1p to 9p
|
||||
|
||||
Rating auto-calculation: `rating = (rank * 100) - 900`
|
||||
|
||||
## Requirements
|
||||
|
||||
- WordPress 5.0 or higher
|
||||
- PHP 7.4 or higher
|
||||
- MySQL 5.6 or higher
|
||||
|
||||
## Fields Collected
|
||||
|
||||
| Field | Required | Description |
|
||||
|-------|----------|-------------|
|
||||
| First Name | Yes | Player's first name |
|
||||
| Last Name | Yes | Player's last name |
|
||||
| Country | Yes | Country code (2-3 letters) |
|
||||
| Club | Yes | Club name |
|
||||
| Rank | Yes | Go rank (30k to 9p) |
|
||||
| Rating | No | EGD rating (auto-calculated from rank if missing) |
|
||||
| EGD Number | No | European Go Database PIN |
|
||||
|
||||
## Hooks
|
||||
|
||||
### Actions
|
||||
|
||||
**Form Handling:**
|
||||
- `admin_post_go_form_handle_submission` - Frontend form submission handler
|
||||
- `admin_post_go_form_update_entry` - Update entry from admin panel
|
||||
|
||||
**Form Management:**
|
||||
- `admin_post_go_form_create_form` - Create new form
|
||||
- `admin_post_go_form_delete_form` - Delete form and all its entries
|
||||
|
||||
**Entry Management:**
|
||||
- `admin_post_go_form_delete_entry` - Delete single entry
|
||||
|
||||
**Custom Fields:**
|
||||
- `admin_post_go_form_create_custom_field` - Create custom field
|
||||
- `admin_post_go_form_update_custom_field` - Update custom field
|
||||
- `admin_post_go_form_delete_custom_field` - Delete custom field
|
||||
|
||||
**EGD Integration:**
|
||||
- `admin_post_go_form_update_egd_data` - Batch update entries from EGD database
|
||||
|
||||
**Export:**
|
||||
- `admin_post_go_form_export_csv` - CSV export handler
|
||||
- `admin_post_go_form_export_pairgoth` - Pairgoth JSON export handler
|
||||
- `admin_post_go_form_export_opengotha` - OpenGotha XML export handler
|
||||
- `admin_post_go_form_export_mcmahon` - McMahon XML export handler
|
||||
|
||||
### Filters
|
||||
|
||||
None currently available.
|
||||
|
||||
## Custom Fields
|
||||
|
||||
Each form can have unlimited custom fields with the following types:
|
||||
|
||||
| Type | Description | Options |
|
||||
|------|-------------|---------|
|
||||
| `text` | Single line text input | - |
|
||||
| `email` | Email address input with validation | - |
|
||||
| `textarea` | Multi-line text input | - |
|
||||
| `select` | Dropdown selection | Comma-separated options |
|
||||
| `checkbox` | Checkbox (yes/no) | - |
|
||||
|
||||
### Custom Field Settings
|
||||
|
||||
- **Public** - Display on frontend form
|
||||
- **Required** - Mandatory field
|
||||
- **Full Width** - Display outside the grid layout
|
||||
|
||||
## Security
|
||||
|
||||
- All forms use WordPress nonces for CSRF protection
|
||||
- Admin actions require `manage_options` capability
|
||||
- All input is sanitized using WordPress sanitization functions (`sanitize_text_field`, `sanitize_textarea_field`, `intval`)
|
||||
- Direct file access is blocked with `ABSPATH` check
|
||||
- Database operations use `$wpdb->prepare()` for SQL injection prevention
|
||||
|
||||
## API Integration
|
||||
|
||||
### European Go Database (EGD)
|
||||
|
||||
The plugin integrates with the European Go Database for player data:
|
||||
|
||||
- **Search API**: `https://europeangodatabase.eu/EGD/GetPlayerDataByData.php?lastname=X&name=Y`
|
||||
- **Player Data API**: `https://europeangodatabase.eu/EGD/GetPlayerDataByPIN.php?pin=XXXX`
|
||||
|
||||
Fields retrieved from EGD:
|
||||
- Name, Last Name
|
||||
- Country Code
|
||||
- Club
|
||||
- Grade (rank text)
|
||||
- Grade_n (rank numeric)
|
||||
- Gor (rating)
|
||||
- Pin_Player (EGD PIN)
|
||||
|
||||
## Author
|
||||
|
||||
Nikola Petrov - nikola@petrovv.com
|
||||
|
||||
## License
|
||||
|
||||
MIT License - See LICENSE file for details.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
CREATE TABLE wp_go_form_forms (
|
||||
id int NOT NULL AUTO_INCREMENT,
|
||||
name varchar(255) NOT NULL,
|
||||
email varchar(255) DEFAULT NULL,
|
||||
created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
@@ -17,6 +17,7 @@ function go_form_activate()
|
||||
dbDelta("CREATE TABLE $forms (
|
||||
id int NOT NULL AUTO_INCREMENT,
|
||||
name varchar(255) NOT NULL,
|
||||
email varchar(255) DEFAULT NULL,
|
||||
created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
) $charset;");
|
||||
@@ -172,6 +173,7 @@ function go_form_handle_submission()
|
||||
wp_die('Security check failed');
|
||||
|
||||
global $wpdb;
|
||||
global $ranks;
|
||||
if (isset($_POST['form_id'])) {
|
||||
$form_id = intval($_POST['form_id']);
|
||||
} else {
|
||||
@@ -230,16 +232,25 @@ function go_form_handle_submission()
|
||||
}
|
||||
}
|
||||
|
||||
// Send notification email
|
||||
// $to = 'nikola@petrovv.com';
|
||||
// $subject = 'New Go Tournament Registration';
|
||||
// Send notification email if form has an email configured
|
||||
$form = go_form_get_form_by_id($form_id);
|
||||
if (!empty($form->email)) {
|
||||
$to = $form->email;
|
||||
$subject = 'New Go Tournament Registration';
|
||||
|
||||
$message = "A new player has signed up:\n\n";
|
||||
$message .= "Form: {$form->name}\n";
|
||||
$message .= "Form ID: {$form_id}\n";
|
||||
$message .= "Name: {$data['first_name']} {$data['last_name']}\n";
|
||||
$message .= "Country: {$data['country']}\n";
|
||||
$message .= "Club: {$data['club']}\n";
|
||||
$message .= "Rank: {$ranks[$data['rank']]}\n";
|
||||
$message .= "Rating: {$data['rating']}\n";
|
||||
$message .= "EGD Number: {$data['egd_number']}\n";
|
||||
$message .= "Date: " . date('Y-m-d H:i:s') . "\n";
|
||||
|
||||
// $message = "A new player has signed up:\n\n";
|
||||
// $message .= "Form ID: {$form_id}\n";
|
||||
// $message .= "Name: {$data['first_name']} {$data['last_name']}\n";
|
||||
|
||||
|
||||
// wp_mail($to, $subject, $message);
|
||||
wp_mail($to, $subject, $message);
|
||||
}
|
||||
|
||||
wp_redirect($_SERVER['HTTP_REFERER']);
|
||||
exit;
|
||||
@@ -299,7 +310,11 @@ function go_form_create_form()
|
||||
go_form_admin_action('create_form');
|
||||
if (isset($_POST['form_name']) && !empty($_POST['form_name'])) {
|
||||
global $wpdb;
|
||||
$wpdb->insert("{$wpdb->prefix}go_form_forms", ['name' => sanitize_text_field($_POST['form_name'])]);
|
||||
$form_data = [
|
||||
'name' => sanitize_text_field($_POST['form_name']),
|
||||
'email' => isset($_POST['form_email']) ? sanitize_text_field($_POST['form_email']) : ''
|
||||
];
|
||||
$wpdb->insert("{$wpdb->prefix}go_form_forms", $form_data);
|
||||
$new_form_id = $wpdb->insert_id;
|
||||
$redirect_url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $new_form_id, 'created' => 1), admin_url('admin.php'));
|
||||
wp_redirect($redirect_url);
|
||||
@@ -311,6 +326,27 @@ function go_form_create_form()
|
||||
}
|
||||
add_action('admin_post_go_form_create_form', 'go_form_create_form');
|
||||
|
||||
function go_form_update_form()
|
||||
{
|
||||
go_form_admin_action('update_form');
|
||||
if (isset($_POST['form_id']) && isset($_POST['form_name']) && !empty($_POST['form_name'])) {
|
||||
global $wpdb;
|
||||
$form_id = intval($_POST['form_id']);
|
||||
$form_data = [
|
||||
'name' => sanitize_text_field($_POST['form_name']),
|
||||
'email' => isset($_POST['form_email']) ? sanitize_text_field($_POST['form_email']) : ''
|
||||
];
|
||||
$wpdb->update("{$wpdb->prefix}go_form_forms", $form_data, ['id' => $form_id]);
|
||||
$redirect_url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $form_id, 'updated_form' => 1), admin_url('admin.php'));
|
||||
wp_redirect($redirect_url);
|
||||
exit;
|
||||
}
|
||||
$redirect_url = add_query_arg(array('page' => 'go-form-settings'), admin_url('admin.php'));
|
||||
wp_redirect($redirect_url);
|
||||
exit;
|
||||
}
|
||||
add_action('admin_post_go_form_update_form', 'go_form_update_form');
|
||||
|
||||
function go_form_delete_form()
|
||||
{
|
||||
go_form_admin_action('delete_form');
|
||||
|
||||
@@ -7,6 +7,8 @@ if (isset($_GET['deleted']))
|
||||
echo '<div class="notice notice-success"><p>Deleted!</p></div>';
|
||||
if (isset($_GET['created']))
|
||||
echo '<div class="notice notice-success"><p>Form created!</p></div>';
|
||||
if (isset($_GET['updated_form']))
|
||||
echo '<div class="notice notice-success"><p>Form updated!</p></div>';
|
||||
if (isset($_GET['created_field']))
|
||||
echo '<div class="notice notice-success"><p>Custom field created!</p></div>';
|
||||
if (isset($_GET['updated_field']))
|
||||
@@ -37,9 +39,24 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||
|
||||
$form = go_form_get_form_by_id($selected_form_id);
|
||||
$form_name = $form ? $form->name : 'Unknown Form';
|
||||
echo "<h3> $form_name</h3>";
|
||||
|
||||
// Form info and edit UI
|
||||
if ($form) {
|
||||
echo '<div style="margin-bottom:20px; padding:15px; background:#fff; border:1px solid #ddd; border-radius:4px;">';
|
||||
echo '<form method="post" action="' . admin_url('admin-post.php') . '">';
|
||||
echo wp_nonce_field('go_form_update_form_action', 'go_form_update_form_nonce', true, false);
|
||||
echo '<input type="hidden" name="action" value="go_form_update_form">';
|
||||
echo '<input type="hidden" name="form_id" value="' . esc_attr($selected_form_id) . '">';
|
||||
echo '<table class="form-table">';
|
||||
echo '<tr><th><label for="form_name">Form Name:</label></th><td><input type="text" name="form_name" id="form_name" value="' . esc_attr($form->name) . '" required></td></tr>';
|
||||
echo '<tr><th><label for="form_email">Notification Email:</label></th><td><input type="email" name="form_email" id="form_email" value="' . esc_attr($form->email ?? '') . '" placeholder="Optional email for signup notifications"></td></tr>';
|
||||
echo '</table>';
|
||||
echo '<p class="submit"><input type="submit" class="button button-primary" value="Update Form"></p>';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<div style="margin-bottom:15px; display: flex; flex-wrap: wrap; gap: 10px;">';
|
||||
|
||||
action_button('go_form_delete_form', 'Delete Form', 'Delete this form and ALL entries?', $selected_form_id);
|
||||
action_button('go_form_export_csv', 'Export to CSV', 'Confirm Export', $selected_form_id);
|
||||
action_button('go_form_export_pairgoth', 'Export to Pairgoth', 'Confirm Export', $selected_form_id);
|
||||
@@ -225,6 +242,7 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||
echo '<input type="hidden" name="action" value="go_form_create_form">';
|
||||
echo '<table class="form-table">';
|
||||
echo '<tr><th><label for="form_name">Form Name:</label></th><td><input type="text" name="form_name" id="form_name" required></td></tr>';
|
||||
echo '<tr><th><label for="form_email">Notification Email:</label></th><td><input type="email" name="form_email" id="form_email" placeholder="Optional email for signup notifications"></td></tr>';
|
||||
echo '</table>';
|
||||
echo '<p class="submit"><input type="submit" class="button button-primary" value="Create Form"></p>';
|
||||
echo '</form>';
|
||||
@@ -234,7 +252,11 @@ if (isset($_GET['error']) && $_GET['error'] == 'egd_update_failed')
|
||||
foreach ($forms as $f) {
|
||||
|
||||
$url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $f->id), admin_url('admin.php'));
|
||||
echo '<li><a href="' . esc_url($url) . '">' . esc_html($f->name) . '</a> <span style="color:#888">(ID: ' . esc_html($f->id) . ')</span> - <small>Shortcode: <code>[go_form id=' . esc_html($f->id) . ']</code></small></li>';
|
||||
echo '<li><a href="' . esc_url($url) . '">' . esc_html($f->name) . '</a> <span style="color:#888">(ID: ' . esc_html($f->id) . ')</span> - <small>Shortcode: <code>[go_form id=' . esc_html($f->id) . ']</code></small>';
|
||||
if (!empty($f->email)) {
|
||||
echo ' - <span style="color:#2271b1;">Email: ' . esc_html($f->email) . '</span>';
|
||||
}
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user