-
Notifications
You must be signed in to change notification settings - Fork 331
Open
Open
Copy link
Labels
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()andcheck_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:
- Approach 02: Codeheat Template #373
- Menu Bar Mismatch on Sub-Pages #363
- duplicate-menu: https://github.com/jchristopher/duplicate-menu
🛠️ Recommended Next Steps
- Create a new plugin directory, e.g.,
/wp-content/plugins/plugin-name/ - Move the logic from
functions.phpinto the plugin’s main file, e.g.,plugin-name.php - Maintain the same functions (
add_event_creator_menu,create_event_page, etc.) but register hooks from within the plugin. - Add a proper plugin header (name, description, author, version).
- 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()).
- Convert to class-based architecture (
- 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.
- Improve security and reliability:
- Use
wp_safe_redirect()instead ofwp_redirect(). - Check user capability (
current_user_can()). - Sanitize and validate all inputs.
- Use
- Add contest logging:
- Store
_created_byand_created_onas post meta. - Add an admin “Contest Log” table for history tracking.
- Store
- 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.
- Add shortcode