fossasia / fossasia/codeheat.org
Convert "Add Contest" Functionality from `functions.php` to a Dedicated Plugin
- Dominant language
- Less
- Stars
- 1.6k
- Forks
- 331
- PR merge metrics
- No merged PRs in 30d
Description
### Summary
Currently, the “**Add Contest”** functionality in the WordPress admin dashboard is implemented inside the `functions.php` file of the **Astra child theme**. While it works, this approach mixes theme and functionality logic — which is not recommended for scalability or maintainability.
This issue proposes **migrating this functionality into a standalone WordPress plugin**, making it reusable, portable, user-friendly, and easier for contributors to maintain or enhance.
---
### Objective
Create a plugin that allows admins to:
- Add new **Codeheat event/contest** pages directly from the WP admin dashboard.
- Choose from multiple predefined **template pages**.
- Set **start and end dates** dynamically (auto-inserted in placeholders `[START_DATE]` and `[END_DATE]` in templates).
- Automatically **redirect** to the page editor after creation.
- Automate menu creation and duplication when new contest pages are published.
- Ensure **security** with proper nonce checks (CSRF protection).
---
### Current Implementation
Implemented in `functions.php` of the Astra child theme.
Key features already working:
- **Multiple Templates**: Admin can choose between templates such as *“Template: Codeheat with Summit”* and *“Template: Bi-monthly Contest.”*
- **Start & End Date Fields**: Admin can select contest start and end dates in “Month Day, Year” format (e.g., *September 30th, 2025*). It requires adding placeholders `[START_DATE]` and `[END_DATE]` in template pages.
- **Improved Workflow**: On click of 'Create Contest' button, automatically redirects to the WordPress editor.
- **Security Enhancements**: Added `wp_nonce_field()` and `check_admin_referer()` for form submission protection.
---
### Current Limitation
- The homepage uses a **globally defined menu**, but each contest year (e.g., “Codeheat 2021”) has its own dedicated menu.
- Currently, menus must be **manually created** or duplicated using a third-party plugin.
- Contest creation is **manual**, **non-modular**, and **lacks automatic linking** under the "About" menu.
---
### Proposed Solution
#### 1. Automatic Menu Duplication & Linking
When a new Codeheat contest page (e.g., “Codeheat 2025”) is created:
- Duplicate the **“Template Menu”** automatically.
- Rename it to match the contest year (e.g., `2025`). For this purpose, the slug of the webpage can be used.
- Place the new contest page as a **submenu under “About”** in the existing menu as well as other menus.
- Ensure all menus remain **editable** under **Appearance → Menus**, allowing users to add, remove, or reorganize items.
---
**Implementation Reference:**
1. https://github.com/fossasia/codeheat.org/issues/373
2. https://github.com/fossasia/codeheat.org/issues/363
3. duplicate-menu: https://github.com/jchristopher/duplicate-menu
---
### 🛠️ Recommended Next Steps
1. **Create a new plugin directory**, e.g., `/wp-content/plugins/plugin-name/`
2. **Move the logic** from `functions.php` into the plugin’s main file, e.g., `plugin-name.php`
3. Maintain the same functions (`add_event_creator_menu`, `create_event_page`, etc.) but register hooks from within the plugin.
4. Add a proper **plugin header** (name, description, author, version).
5. **Improve structure and maintainability:**
- Convert to **class-based architecture** (`WPFA-plugin-name`).
- Add **namespaces** (e.g., `WPFA-plugin-name`) to prevent conflicts.
- Use **hooks and filters** to make templates and parent pages customizable.
- Add **i18n support** for translations (`__()` / `_e()`).
6. **Enhance user experience:**
- Add inline form validation and dynamic field defaults.
- Display success notices with smooth redirection messages.
- Pre-fill next contest’s year based on existing ones.
7. **Improve security and reliability:**
- Use `wp_safe_redirect()` instead of `wp_redirect()`.
- Check user capability (`current_user_can()`).
- Sanitize and validate all inputs.
8. **Add contest logging:**
- Store `_created_by` and `_created_on` as post meta.
- Add an admin “Contest Log” table for history tracking.
9. **Future enhancements:**
- Add shortcode `[codeheat_events]` or REST API endpoint for front-end display.
- Add Template Management UI for registering templates visually.
- Implement auto-archiving for past contests.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.