A comprehensive starter template for WordPress plugins with best practices for AI-assisted development.
The WordPress Plugin Starter Template provides a solid foundation for developing WordPress plugins. It incorporates best practices, modern coding standards, and a comprehensive structure that makes it easy to get started with plugin development.
This template is based on the experience gained from developing the "Fix 'Plugin file does not exist' Notices" plugin and other successful WordPress plugins.
- Object-Oriented Architecture: Well-structured, maintainable code using OOP principles
- Namespace Support: Modern PHP namespacing for better organization and avoiding conflicts
- Comprehensive Documentation: Detailed documentation for both users and developers
- Testing Framework: PHPUnit setup for unit testing and Cypress for e2e testing
- Internationalization Ready: Full support for translation and localization
- Update Source Selection: Choose between WordPress.org, GitHub, or Gitea for plugin updates
- AI Workflow Documentation: Detailed guides for AI-assisted development
- Wiki Documentation: Ready-to-use wiki structure for comprehensive documentation
- Multisite Compatible: Fully tested and compatible with WordPress multisite installations
- Clone or download this repository
- Important: Begin by reading the Starter Prompt file for detailed instructions
- Add the .ai-assistant.md file and .ai-workflows/ directory to your AI IDE chat context (pin them if possible)
- Use the prompt in the Starter Prompt file to guide the AI in customizing the template for your plugin
- Rename files and update namespaces to match your plugin
- Customize the functionality for your specific needs
- Update documentation to reflect your plugin's features
- Build and test your plugin
This template includes comprehensive documentation for AI-assisted development:
- .ai-assistant.md: Guide for AI assistants to understand the project structure
- .ai-workflows/: Detailed workflow documentation for common development tasks
- Starter Prompt: Comprehensive prompt for AI tools to help customize the template (available in the wiki)
Important: For the best AI assistance, add the .ai-assistant.md file and .ai-workflows/ directory to your AI IDE chat context. In most AI IDEs, you can pin these files to ensure they're considered in each message.
- Clone or download this repository
- Read the Starter Prompt file for detailed instructions
- Add the .ai-assistant.md file and .ai-workflows/ directory to your AI IDE chat context
- Use the prompt in the Starter Prompt file to guide the AI in customizing the template
- Rename files and update namespaces to match your plugin
- Customize the functionality for your specific needs
- Update documentation to reflect your plugin's features
- Build and test your plugin
To get started with this template, follow these steps:
-
In your terminal, navigate to the folder you keep you Git repositories (eg:
~/Git/
), then clone this repository to your local machine:git clone https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding.git
-
Open the Starter Prompt file and follow the instructions to customize the template for your plugin.
-
Add the .ai-assistant.md file and .ai-workflows/ directory to your AI IDE chat context.
-
Use an AI assistant like GitHub Copilot, Claude, or ChatGPT to help you customize the template by providing the prompt from the Starter Prompt file.
This template includes configuration for WordPress Environment (wp-env) to make local development easier:
-
Install Node.js dependencies:
npm install
-
Start the WordPress environment:
npm run start
-
For multisite testing:
npm run multisite
-
Access your local WordPress site at http://localhost:8888 (admin credentials: admin/password)
The template includes both PHP unit tests and end-to-end tests:
-
Install Composer dependencies:
composer install
-
Run PHP unit tests:
npm run test:php
-
Check PHP coding standards:
npm run lint:php
-
Fix PHP coding standards issues:
npm run fix:php
-
Start the WordPress environment:
npm run start
-
Run Cypress tests in interactive mode:
npm run test:e2e
-
Run Cypress tests in headless mode:
npm run test:e2e:headless
Use the included build script to create a deployable version of your plugin:
npm run build
Or directly:
./build.sh {VERSION}
This will create a ZIP file that you can install in WordPress.
If you've installed this plugin from GitHub or Gitea, you'll need Git Updater to receive updates:
- Install the Git Updater plugin from git-updater.com/git-updater/
- Go to Settings > Git Updater > Remote Management
- Click the "Refresh Cache" button to ensure Git Updater recognizes the latest version
- Updates will now appear in your WordPress dashboard when available
This template includes functionality that allows users to choose where they want to receive updates from:
- In the Plugins list, find your plugin
- Click the "Update Source" link next to the plugin
- Select your preferred update source:
- WordPress.org: Updates from the official WordPress.org repository
- GitHub: Updates directly from the GitHub repo
- Gitea: Updates directly from the Gitea repo
- Click "Save" to apply your preference
See the Starter Prompt file for detailed instructions on customizing this template for your specific plugin needs. Make sure to add the .ai-assistant.md file and .ai-workflows/ directory to your AI IDE chat context for the best results.
The main files you need to update include:
- Main plugin file (rename and update header)
- README.md
- readme.txt
- CHANGELOG.md
- composer.json
- package.json
- languages/pot file
- .github/workflows/
- .wiki/
- .ai-assistant.md
- includes/plugin.php
- includes/core.php
- admin/lib/admin.php
Use the included build.sh script to create a deployable version of your plugin:
./build.sh {VERSION}
This will create a ZIP file that you can install in WordPress.
Customize the includes/core.php file to implement your core functionality and the admin/lib/admin.php file for admin-specific functionality.
Yes, this template is fully compatible with WordPress multisite installations. You can test multisite compatibility by running:
npm run multisite
If you need help with this template, there are several ways to get support:
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository on GitHub or Gitea
- Create your feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add some amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Submit a pull request
For more detailed information, see the Contributing Guide.
This project uses several automated code quality tools to ensure high standards. These tools are free for public repositories and should be integrated into any new repositories based on this template:
-
CodeRabbit: AI-powered code review tool
- Website
- Provides automated feedback on pull requests
-
CodeFactor: Continuous code quality monitoring
- Website
- Provides a grade for your codebase
-
Codacy: Code quality and static analysis
- Website
- Identifies issues related to code style, security, and performance
- Requires a
CODACY_PROJECT_TOKEN
secret in your GitHub repository settings - To set up Codacy:
- Go to Codacy and sign in with your GitHub account
- Add your repository to Codacy
- Go to your project settings > Integrations > Project API
- Generate a project API token
- Add the token as a secret named
CODACY_PROJECT_TOKEN
in your GitHub repository settings - Note: Codacy tokens are project-specific, so they need to be added at the repository level. However, you can use GitHub Actions to securely pass these tokens between repositories if needed.
-
SonarCloud: Code quality and security analysis
- Website
- Provides detailed analysis of code quality and security
- Requires a
SONAR_TOKEN
secret in your GitHub repository settings - To set up SonarCloud:
- Go to SonarCloud and sign in with your GitHub account
- Create a new organization or use an existing one
- Add your repository to SonarCloud
- Generate a token in SonarCloud (Account > Security > Tokens)
- Add the token as a secret named
SONAR_TOKEN
in your GitHub repository or organization settings (see "GitHub Secrets Management" section below)
-
PHP_CodeSniffer (PHPCS): PHP code style checker
- Enforces WordPress Coding Standards
- Automatically runs in GitHub Actions workflow
- Run locally with
composer phpcs
-
PHP Code Beautifier and Fixer (PHPCBF): Automatically fixes coding standard violations
- Run locally with
composer phpcbf
- Run locally with
-
PHPStan: PHP static analysis tool
- Detects bugs and errors without running the code
- Run locally with
composer phpstan
-
PHP Mess Detector (PHPMD): Analyzes code for potential problems
- Identifies complex code, unused parameters, etc.
- Run locally with
composer phpmd
For detailed setup instructions, see the Code Quality Setup Guide.
When you receive feedback from these code quality tools, you can use AI assistants to help address the issues:
- Copy the output from the code quality tool
- Paste it into your AI assistant chat
- Ask the AI to help you understand and resolve the issues
- Apply the suggested fixes
- Commit the changes and verify that the issues are resolved
For more information on coding standards and how to pass code quality checks, see the Coding Standards Guide.
GitHub offers three levels of secrets management, each with different scopes and use cases:
-
Organization Secrets (recommended for teams and organizations):
- Available at: GitHub Organization > Settings > Secrets and variables > Actions
- Scope: Can be shared across multiple repositories within the organization
- Benefits: Centralized management, reduced duplication, easier rotation
- Recommended for:
SONAR_TOKEN
and other tokens that apply to multiple repositories - Note: You can restrict which repositories can access organization secrets
- Note: Codacy tokens (
CODACY_PROJECT_TOKEN
) are project-specific and should be set at the repository level
-
Repository Secrets:
- Available at: Repository > Settings > Secrets and variables > Actions
- Scope: Limited to a single repository
- Benefits: Repository-specific, higher isolation
- Recommended for:
CODACY_PROJECT_TOKEN
and other repository-specific credentials or tokens that shouldn't be shared
-
Environment Secrets:
- Available at: Repository > Settings > Environments > (select environment) > Environment secrets
- Scope: Limited to specific deployment environments (e.g., production, staging)
- Benefits: Environment-specific, can have approval requirements
- Recommended for: Deployment credentials that vary between environments
For code quality tools like SonarCloud, organization secrets are recommended if you have multiple repositories that use these tools. This approach reduces management overhead and ensures consistent configuration across projects. For Codacy, since tokens are project-specific, they should be set at the repository level.
To run code quality tools locally before committing to GitHub:
-
Install dependencies:
composer install
-
Run PHP CodeSniffer:
composer phpcs
-
Fix coding standards automatically:
composer phpcbf
-
Run PHPStan static analysis:
composer phpstan
-
Run PHP Mess Detector:
composer phpmd
-
Run all linters at once:
composer lint
-
Set up environment variables for SonarCloud and Codacy:
-
For macOS/Linux:
export SONAR_TOKEN=your_sonar_token export CODACY_PROJECT_TOKEN=your_codacy_token
-
For Windows (Command Prompt):
set SONAR_TOKEN=your_sonar_token set CODACY_PROJECT_TOKEN=your_codacy_token
-
For Windows (PowerShell):
$env:SONAR_TOKEN="your_sonar_token" $env:CODACY_PROJECT_TOKEN="your_codacy_token"
-
-
Create a .env file (alternative approach):
# .env (already included in .gitignore to prevent committing secrets) SONAR_TOKEN=your_sonar_token CODACY_PROJECT_TOKEN=your_codacy_token
Then load these variables:
# Using a tool like dotenv source .env
-
Run SonarCloud locally:
# Install SonarScanner npm install -g sonarqube-scanner # Run analysis sonar-scanner \ -Dsonar.projectKey=your_project_key \ -Dsonar.organization=your_organization \ -Dsonar.sources=. \ -Dsonar.host.url=https://sonarcloud.io \ -Dsonar.login=$SONAR_TOKEN
-
Run Codacy locally:
# Install Codacy CLI npm install -g codacy-coverage # Run analysis codacy-analysis-cli analyze --directory . --project-token $CODACY_PROJECT_TOKEN
For more detailed instructions, see the Code Quality Setup Guide.
By running these tools locally, you can identify and fix issues before pushing your code to GitHub, ensuring smoother CI/CD workflows.
This repository is configured to work with various AI-powered development tools. You can use any of the following AI IDEs to contribute to this project:
- Augment Code - AI-powered coding assistant
- Bolt - AI-powered code editor
- Cline - AI terminal assistant
- Cody - Sourcegraph's AI coding assistant
- Continue - Open-source AI coding assistant
- Cursor - AI-first code editor
- Loveable - AI development environment
- Roo Code - AI pair programmer
- v0 - AI-powered design and development tool
- Windsurf - AI coding assistant
The repository includes configuration files for all these tools to ensure a consistent development experience.
This template is designed to work seamlessly with the Git Updater plugin for updates from GitHub and Gitea. To ensure proper integration:
-
Required Headers: The plugin includes specific headers in the main plugin file that Git Updater uses to determine update sources and branches:
* GitHub Plugin URI: wpallstars/wp-plugin-starter-template-for-ai-coding * GitHub Branch: main * Primary Branch: main * Release Branch: main * Release Asset: true * Gitea Plugin URI: https://gitea.wpallstars.com/wpallstars/wp-plugin-starter-template-for-ai-coding * Gitea Branch: main
-
Tagging Releases: When creating a new release, always tag it with the 'v' prefix (e.g.,
v0.1.2
) to ensure GitHub Actions can create the proper release assets. -
GitHub Actions: The repository includes a GitHub Actions workflow that automatically builds the plugin and creates a release with the .zip file when a new tag is pushed.
-
Update Source Selection: The template includes a feature that allows users to choose their preferred update source (WordPress.org, GitHub, or Gitea).
For more information on Git Updater integration, see the Git Updater Required Headers documentation.
- Improved: Code quality with proper type declarations
- Fixed: Inconsistent variable naming (camelCase to snake_case)
- Improved: Path handling in admin class
- Added: Textdomain loading functionality
- Removed: Unused phpcs:ignore comment
- Implemented: Proper return type declarations
- Fixed: WordPress mocking in unit tests
- Added: Proper mocking for WordPress functions in tests
- Improved: Code quality tool configurations
- Added: Detailed code quality checks workflow documentation
- Updated: Documentation for better workflow efficiency
- Improved: Code quality with comprehensive fixes
- Fixed: Indentation issues in PHP files
- Updated: CSS formatting with modern notation
- Fixed: JavaScript issues with proper global variables
- Improved: Security by using filter_input() instead of direct superglobal access
- Standardized: Naming conventions across the codebase
- Fixed: Documentation and comments for better clarity
- Fixed: Formatting issues in markdown files for better code quality
- Fixed: Improved URL formatting with angle brackets
- Fixed: Standardized list formatting across documentation files
- Changed: Alphabetized AI IDE list.
- Added: More informative badges (Build Status, Requirements, WP.org placeholders, Release, Issues, Contributors, Wiki).
- Fixed: GitHub Actions tests workflow with proper file paths and dependencies
- Fixed: GitHub Actions workflows permissions for releases and wiki sync
- Fixed: Release workflow to use correct plugin directory name
- Added: Testing setup with wp-env and Cypress
- Added: Multisite compatibility
- Added: npm scripts for development and testing
- Added: Improved AI IDE context recommendations in documentation
- Enhanced: Starter Prompt with guidance on pinning .ai-assistant.md and .ai-workflows/
- Moved: Starter Prompt to the wiki for better organization
- Updated: README.md and readme.txt with AI IDE context recommendations
- Improved: Documentation for AI-assisted development
- Added: STARTER-PROMPT.md with comprehensive guide for customizing the template
- Updated: Documentation files with improved instructions
- Added: Additional AI workflow files for better development guidance
- Updated: LICENSE file with correct GPL-2.0 text
- Initial release with basic template structure
- Added: Core plugin architecture with OOP approach
- Added: Admin interface components and styling
- Added: Update mechanism with multiple source options
- Added: Documentation templates for users and developers
- Added: AI workflow documentation for AI-assisted development
- Added: GitHub Actions workflows for automated tasks
- Added: Wiki documentation templates
This project is licensed under the GPL-2.0+ License - see the LICENSE file for details.
This template is based on the experience gained from developing the "Fix 'Plugin file does not exist' Notices" plugin by WPALLSTARS.