Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3e5d0d0c0 | ||
|
|
cdc73bc010 | ||
|
|
67c6c65611 | ||
|
|
ebdb172a14 | ||
|
|
57a4c98f46 | ||
|
|
4c1bee9dbe | ||
|
|
200cc5671d | ||
|
|
398d24ed90 | ||
|
|
ad30d716db | ||
|
|
19ec65326b | ||
|
|
3048e91a78 | ||
|
|
3926927791 | ||
|
|
728c5dcf3d | ||
|
|
109c07cfed | ||
|
|
ea628c521b | ||
|
|
ae7bd5cb89 | ||
|
|
1f4be45862 | ||
|
|
78bd0708d3 | ||
|
|
36840c46c1 | ||
|
|
aa62142e4c | ||
|
|
0ab1a1df4d | ||
|
|
69cd192f49 | ||
|
|
4ebe55b940 | ||
|
|
5b4037bf0d | ||
|
|
fd314fd7c7 | ||
|
|
546ed59a61 | ||
|
|
069dc2e8d7 | ||
|
|
9d36b47f9f | ||
|
|
5cd2a7d374 | ||
|
|
497c44c3c6 | ||
|
|
e3f11ac03f | ||
|
|
04cdd49a3f | ||
|
|
cdd9b050c7 | ||
|
|
6031751015 |
No files matched your search
+88
-52
@@ -6,50 +6,83 @@ This guide helps AI assistants understand the project structure, workflows, and
|
||||
|
||||
This workspace may contain multiple repository folders. Always focus ONLY on the current repository you're working in and avoid hallucinating functionality from other repositories in the workspace.
|
||||
|
||||
- **Current Repository**: wp-plugin-starter-template-for-ai-coding
|
||||
- **Repository Purpose**: A comprehensive starter template for WordPress plugins with best practices for AI-assisted development
|
||||
- **Repository Scope**: All code changes, documentation, and functionality discussions should be limited to THIS repository only
|
||||
* **Current Repository**: wp-plugin-starter-template-for-ai-coding
|
||||
* **Repository Purpose**: A comprehensive starter template for WordPress plugins with best practices for AI-assisted development
|
||||
* **Repository Scope**: All code changes, documentation, and functionality discussions should be limited to THIS repository only
|
||||
|
||||
## Project Overview
|
||||
|
||||
- **Plugin Name**: WordPress Plugin Starter Template
|
||||
- **Plugin Slug**: wp-plugin-starter-template
|
||||
- **Text Domain**: wp-plugin-starter-template
|
||||
- **Namespace**: WPALLSTARS\PluginStarterTemplate
|
||||
- **Version**: 0.1.1
|
||||
- **Requires WordPress**: 5.0+
|
||||
- **Requires PHP**: 7.0+
|
||||
- **License**: GPL-2.0+
|
||||
* **Plugin Name**: WordPress Plugin Starter Template
|
||||
* **Plugin Slug**: wp-plugin-starter-template
|
||||
* **Text Domain**: wp-plugin-starter-template
|
||||
* **Namespace**: WPALLSTARS\PluginStarterTemplate
|
||||
* **Version**: 0.1.10
|
||||
* **Requires WordPress**: 5.0+
|
||||
* **Requires PHP**: 7.0+
|
||||
* **License**: GPL-2.0+
|
||||
|
||||
## Repository Structure
|
||||
|
||||
- **wp-plugin-starter-template.php**: Main plugin file with plugin headers
|
||||
- **includes/**: Core plugin functionality
|
||||
- **plugin.php**: Main plugin class that initializes everything
|
||||
- **core.php**: Core functionality class
|
||||
- **updater.php**: Update mechanism for multiple sources
|
||||
- **admin/**: Admin-specific functionality
|
||||
- **lib/**: Admin classes
|
||||
- **css/**: Admin stylesheets
|
||||
- **js/**: Admin JavaScript files
|
||||
- **languages/**: Translation files
|
||||
- **.github/workflows/**: GitHub Actions workflows
|
||||
- **.ai-workflows/**: Documentation for AI assistants
|
||||
- **.wiki/**: Wiki documentation templates
|
||||
* **wp-plugin-starter-template.php**: Main plugin file with plugin headers
|
||||
* **includes/**: Core plugin functionality
|
||||
* **plugin.php**: Main plugin class that initializes everything
|
||||
* **core.php**: Core functionality class
|
||||
* **updater.php**: Update mechanism for multiple sources
|
||||
* **admin/**: Admin-specific functionality
|
||||
* **lib/**: Admin classes
|
||||
* **css/**: Admin stylesheets
|
||||
* **js/**: Admin JavaScript files
|
||||
* **languages/**: Translation files
|
||||
* **.github/workflows/**: GitHub Actions workflows
|
||||
* **.ai-workflows/**: Documentation for AI assistants
|
||||
* **.wiki/**: Wiki documentation templates
|
||||
|
||||
## Coding Standards
|
||||
|
||||
This project follows the [WordPress Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/):
|
||||
|
||||
- Use tabs for indentation, not spaces
|
||||
- Follow WordPress naming conventions:
|
||||
- Class names: `Class_Name`
|
||||
- Function names: `function_name`
|
||||
- Variable names: `$variable_name`
|
||||
- Use proper DocBlocks for all classes, methods, and functions
|
||||
- Ensure all user-facing strings are translatable
|
||||
- Validate and sanitize all inputs
|
||||
- Escape all outputs
|
||||
* Use 4 spaces for indentation, not tabs (this is a project-specific override of WordPress standards)
|
||||
* Follow WordPress naming conventions:
|
||||
* Class names: `Class_Name`
|
||||
* Function names: `function_name`
|
||||
* Variable names: `$variable_name`
|
||||
* Use proper DocBlocks for all classes, methods, and functions
|
||||
* Ensure all user-facing strings are translatable
|
||||
* Validate and sanitize all inputs
|
||||
* Escape all outputs
|
||||
* Use asterisks (*) for bullet points in all Markdown files, not hyphens (-)
|
||||
|
||||
### Code Quality Tools
|
||||
|
||||
This project uses several automated code quality tools to ensure high standards:
|
||||
|
||||
1. **PHP_CodeSniffer (PHPCS)**: Checks PHP code against the WordPress Coding Standards
|
||||
```bash
|
||||
composer run phpcs
|
||||
```
|
||||
|
||||
2. **PHP Code Beautifier and Fixer (PHPCBF)**: Automatically fixes some coding standard violations
|
||||
```bash
|
||||
composer run phpcbf
|
||||
```
|
||||
|
||||
3. **ESLint**: Checks JavaScript code against the WordPress Coding Standards
|
||||
```bash
|
||||
npm run lint:js
|
||||
```
|
||||
|
||||
4. **Stylelint**: Checks CSS code against the WordPress Coding Standards
|
||||
```bash
|
||||
npm run lint:css
|
||||
```
|
||||
|
||||
5. **Continuous Integration Tools**: The project integrates with several code quality tools:
|
||||
* **CodeRabbit**: AI-powered code review tool
|
||||
* **CodeFactor**: Continuous code quality monitoring
|
||||
* **Codacy**: Code quality and static analysis
|
||||
* **SonarCloud**: Code quality and security analysis
|
||||
|
||||
Always run PHPCS and PHPCBF locally before committing code to ensure it meets the project's coding standards.
|
||||
|
||||
## Common Tasks
|
||||
|
||||
@@ -71,15 +104,17 @@ When working in a multi-repository workspace, follow these guidelines to avoid c
|
||||
|
||||
6. **Verify Before Implementation**: Before implementing or documenting a feature, verify that it actually exists in the current repository by checking the codebase.
|
||||
|
||||
7. **Consistent Markdown Formatting**: Always use asterisks (*) for bullet points in Markdown files, not hyphens (-).
|
||||
|
||||
## Internationalization (i18n)
|
||||
|
||||
All user-facing strings should be translatable:
|
||||
|
||||
- Use `__()` for simple strings
|
||||
- Use `_e()` for echoed strings
|
||||
- Use `esc_html__()` for escaped strings
|
||||
- Use `esc_html_e()` for escaped and echoed strings
|
||||
- Always use the plugin's text domain: `wp-plugin-starter-template`
|
||||
* Use `__()` for simple strings
|
||||
* Use `_e()` for echoed strings
|
||||
* Use `esc_html__()` for escaped strings
|
||||
* Use `esc_html_e()` for escaped and echoed strings
|
||||
* Always use the plugin's text domain: `wp-plugin-starter-template`
|
||||
|
||||
Example:
|
||||
```php
|
||||
@@ -88,26 +123,27 @@ echo esc_html__('This is a translatable string', 'wp-plugin-starter-template');
|
||||
|
||||
## Security Best Practices
|
||||
|
||||
- Validate and sanitize all inputs
|
||||
- Escape all outputs
|
||||
- Use nonces for form submissions
|
||||
- Use capability checks for user actions
|
||||
- Follow the principle of least privilege
|
||||
* Validate and sanitize all inputs
|
||||
* Escape all outputs
|
||||
* Use nonces for form submissions
|
||||
* Use capability checks for user actions
|
||||
* Follow the principle of least privilege
|
||||
|
||||
## Documentation
|
||||
|
||||
- Keep code comments up-to-date
|
||||
- Update README.md and readme.txt when adding new features
|
||||
- Update wiki documentation in the `.wiki/` directory
|
||||
- Update changelog in both CHANGELOG.md and readme.txt
|
||||
* Keep code comments up-to-date
|
||||
* Update README.md and readme.txt when adding new features
|
||||
* Update wiki documentation in the `.wiki/` directory
|
||||
* Update changelog in both CHANGELOG.md and readme.txt
|
||||
* Use asterisks (*) for bullet points in all Markdown files
|
||||
|
||||
## Git Workflow
|
||||
|
||||
- Create feature branches from `main`
|
||||
- Use descriptive branch names (e.g., `feature/add-settings-page`)
|
||||
- Make atomic commits with clear messages
|
||||
- Create pull requests for review
|
||||
- Tag releases with version numbers (e.g., `v1.0.0`)
|
||||
* Create feature branches from `main`
|
||||
* Use descriptive branch names (e.g., `feature/add-settings-page`)
|
||||
* Make atomic commits with clear messages
|
||||
* Create pull requests for review
|
||||
* Tag releases with version numbers (e.g., `v1.0.0`)
|
||||
|
||||
## Developer Preferences
|
||||
|
||||
|
||||
+137
-65
@@ -1,6 +1,6 @@
|
||||
# Code Review Guide for AI Assistants
|
||||
|
||||
This document provides guidance for AI assistants to help with code review for the Fix Plugin Does Not Exist Notices plugin.
|
||||
This document provides guidance for AI assistants to help with code review for this project.
|
||||
|
||||
## Code Review Checklist
|
||||
|
||||
@@ -8,54 +8,126 @@ When reviewing code, check for the following:
|
||||
|
||||
### Functionality
|
||||
|
||||
- [ ] Does the code work as expected?
|
||||
- [ ] Does it handle edge cases appropriately?
|
||||
- [ ] Are there any logical errors?
|
||||
- [ ] Is error handling implemented properly?
|
||||
* [ ] Does the code work as expected?
|
||||
* [ ] Does it handle edge cases appropriately?
|
||||
* [ ] Are there any logical errors?
|
||||
* [ ] Is error handling implemented properly?
|
||||
|
||||
### Code Quality
|
||||
|
||||
- [ ] Does the code follow WordPress coding standards?
|
||||
- [ ] Is the code well-organized and easy to understand?
|
||||
- [ ] Are there any code smells (duplicate code, overly complex functions, etc.)?
|
||||
- [ ] Are functions and variables named appropriately?
|
||||
- [ ] Are there appropriate comments and documentation?
|
||||
* [ ] Does the code follow WordPress coding standards?
|
||||
* [ ] Is the code well-organized and easy to understand?
|
||||
* [ ] Are there any code smells (duplicate code, overly complex functions, etc.)?
|
||||
* [ ] Are functions and variables named appropriately?
|
||||
* [ ] Are there appropriate comments and documentation?
|
||||
|
||||
### Security
|
||||
|
||||
- [ ] Is user input properly validated and sanitized?
|
||||
- [ ] Is output properly escaped?
|
||||
- [ ] Are capability checks used for user actions?
|
||||
- [ ] Are nonces used for form submissions?
|
||||
- [ ] Are there any potential SQL injection vulnerabilities?
|
||||
- [ ] Are there any potential XSS vulnerabilities?
|
||||
* [ ] Is user input properly validated and sanitized?
|
||||
* [ ] Is output properly escaped?
|
||||
* [ ] Are capability checks used for user actions?
|
||||
* [ ] Are nonces used for form submissions?
|
||||
* [ ] Are there any potential SQL injection vulnerabilities?
|
||||
* [ ] Are there any potential XSS vulnerabilities?
|
||||
|
||||
### Performance
|
||||
|
||||
- [ ] Are there any performance bottlenecks?
|
||||
- [ ] Are database queries optimized?
|
||||
- [ ] Is caching used appropriately?
|
||||
- [ ] Are assets (CSS, JS) properly enqueued?
|
||||
* [ ] Are there any performance bottlenecks?
|
||||
* [ ] Are database queries optimized?
|
||||
* [ ] Is caching used appropriately?
|
||||
* [ ] Are assets (CSS, JS) properly enqueued?
|
||||
|
||||
### Compatibility
|
||||
|
||||
- [ ] Is the code compatible with the minimum supported WordPress version (5.0)?
|
||||
- [ ] Is the code compatible with the minimum supported PHP version (7.0)?
|
||||
- [ ] Are there any browser compatibility issues?
|
||||
- [ ] Are there any conflicts with other plugins?
|
||||
* [ ] Is the code compatible with the minimum supported WordPress version (5.0)?
|
||||
* [ ] Is the code compatible with the minimum supported PHP version (7.0)?
|
||||
* [ ] Are there any browser compatibility issues?
|
||||
* [ ] Are there any conflicts with other plugins?
|
||||
|
||||
### Internationalization
|
||||
|
||||
- [ ] Are all user-facing strings translatable?
|
||||
- [ ] Is the correct text domain used?
|
||||
- [ ] Are translation functions used correctly?
|
||||
* [ ] Are all user-facing strings translatable?
|
||||
* [ ] Is the correct text domain used?
|
||||
* [ ] Are translation functions used correctly?
|
||||
|
||||
### Accessibility
|
||||
|
||||
- [ ] Does the code follow accessibility best practices?
|
||||
- [ ] Are ARIA attributes used appropriately?
|
||||
- [ ] Is keyboard navigation supported?
|
||||
- [ ] Is screen reader support implemented?
|
||||
* [ ] Does the code follow accessibility best practices?
|
||||
* [ ] Are ARIA attributes used appropriately?
|
||||
* [ ] Is keyboard navigation supported?
|
||||
* [ ] Is screen reader support implemented?
|
||||
|
||||
## Automated Code Review Tools
|
||||
|
||||
This project uses several automated code review tools to maintain high code quality standards. These tools are free to use for public repositories and should be integrated into any new repositories based on this template.
|
||||
|
||||
### 1. CodeRabbit
|
||||
|
||||
[CodeRabbit](https://www.coderabbit.ai/) is an AI-powered code review tool that provides automated feedback on pull requests.
|
||||
|
||||
* **Integration**: Add the CodeRabbit GitHub App to your repository
|
||||
* **Benefits**: Provides AI-powered code reviews, identifies potential issues, and suggests improvements
|
||||
* **Usage**: CodeRabbit automatically reviews pull requests when they are created or updated
|
||||
|
||||
### 2. CodeFactor
|
||||
|
||||
[CodeFactor](https://www.codefactor.io/) continuously monitors code quality and provides feedback on code style, complexity, and potential issues.
|
||||
|
||||
* **Integration**: Add the CodeFactor GitHub App to your repository
|
||||
* **Benefits**: Provides a grade for your codebase, identifies issues, and tracks code quality over time
|
||||
* **Usage**: CodeFactor automatically analyzes your codebase and provides feedback on pull requests
|
||||
|
||||
### 3. Codacy
|
||||
|
||||
[Codacy](https://www.codacy.com/) is a code quality tool that provides static analysis, code coverage, and code duplication detection.
|
||||
|
||||
* **Integration**: Add the Codacy GitHub App to your repository
|
||||
* **Benefits**: Provides a grade for your codebase, identifies issues, and tracks code quality over time
|
||||
* **Usage**: Codacy automatically analyzes your codebase and provides feedback on pull requests
|
||||
|
||||
### 4. PHPStan
|
||||
|
||||
[PHPStan](https://phpstan.org/) is a static analysis tool that finds errors in your code without running it.
|
||||
|
||||
* **Integration**: Included in the project's composer.json and GitHub Actions workflow
|
||||
* **Benefits**: Detects undefined variables, methods, and properties; type-related issues; and logical errors
|
||||
* **Usage**: Run `composer phpstan` or `npm run lint:phpstan` locally, or let GitHub Actions run it automatically
|
||||
|
||||
### 5. PHP Mess Detector
|
||||
|
||||
[PHP Mess Detector](https://phpmd.org/) is a tool that looks for potential problems in your code such as possible bugs, suboptimal code, overcomplicated expressions, and unused parameters, variables, and methods.
|
||||
|
||||
* **Integration**: Included in the project's composer.json and GitHub Actions workflow
|
||||
* **Benefits**: Identifies code smells, complexity issues, unused code, naming problems, and more
|
||||
* **Usage**: Run `composer phpmd` or `npm run lint:phpmd` locally, or let GitHub Actions run it automatically
|
||||
|
||||
### Using AI Assistants with Code Review Tools
|
||||
|
||||
When you receive feedback from these code review tools, you can use AI assistants to help address the issues:
|
||||
|
||||
1. Copy the output from the code review tool
|
||||
2. Paste it into your AI assistant chat
|
||||
3. Ask the AI to help you understand and resolve the issues
|
||||
4. Apply the suggested fixes
|
||||
5. Commit the changes and verify that the issues are resolved
|
||||
|
||||
### Markdown Formatting Standards
|
||||
|
||||
When writing or updating Markdown files in this project, follow these standards:
|
||||
|
||||
* Always use asterisks (*) for bullet points, not hyphens (-)
|
||||
* Use proper heading hierarchy (# for main title, ## for sections, etc.)
|
||||
* Use code blocks with language specification for code examples
|
||||
* Use relative links for internal documentation
|
||||
* Include alt text for images
|
||||
|
||||
Example prompt for AI assistants:
|
||||
|
||||
```text
|
||||
I received the following feedback from [Tool Name]. Please help me understand and resolve these issues:
|
||||
|
||||
[Paste the tool output here]
|
||||
```
|
||||
|
||||
## Code Review Process
|
||||
|
||||
@@ -63,9 +135,9 @@ When reviewing code, check for the following:
|
||||
|
||||
Before reviewing code, understand:
|
||||
|
||||
- What problem is the code trying to solve?
|
||||
- What are the requirements?
|
||||
- What are the constraints?
|
||||
* What problem is the code trying to solve?
|
||||
* What are the requirements?
|
||||
* What are the constraints?
|
||||
|
||||
### 2. Review the Code
|
||||
|
||||
@@ -75,60 +147,60 @@ Review the code with the checklist above in mind.
|
||||
|
||||
When providing feedback:
|
||||
|
||||
- Be specific and clear
|
||||
- Explain why a change is needed
|
||||
- Provide examples or suggestions when possible
|
||||
- Prioritize feedback (critical issues vs. minor improvements)
|
||||
- Be constructive and respectful
|
||||
* Be specific and clear
|
||||
* Explain why a change is needed
|
||||
* Provide examples or suggestions when possible
|
||||
* Prioritize feedback (critical issues vs. minor improvements)
|
||||
* Be constructive and respectful
|
||||
|
||||
### 4. Follow Up
|
||||
|
||||
After the code has been updated:
|
||||
|
||||
- Review the changes
|
||||
- Verify that issues have been addressed
|
||||
- Provide additional feedback if necessary
|
||||
* Review the changes
|
||||
* Verify that issues have been addressed
|
||||
* Provide additional feedback if necessary
|
||||
|
||||
## Common Issues to Look For
|
||||
|
||||
### PHP Issues
|
||||
|
||||
- Undefined variables or functions
|
||||
- Incorrect function parameters
|
||||
- Missing return statements
|
||||
- Improper error handling
|
||||
- Inefficient loops or conditionals
|
||||
- Hardcoded values that should be configurable
|
||||
* Undefined variables or functions
|
||||
* Incorrect function parameters
|
||||
* Missing return statements
|
||||
* Improper error handling
|
||||
* Inefficient loops or conditionals
|
||||
* Hardcoded values that should be configurable
|
||||
|
||||
### WordPress-Specific Issues
|
||||
|
||||
- Incorrect hook usage
|
||||
- Missing or incorrect nonces
|
||||
- Missing capability checks
|
||||
- Direct database queries instead of using WordPress functions
|
||||
- Improper enqueuing of scripts and styles
|
||||
- Not using WordPress functions for common tasks
|
||||
* Incorrect hook usage
|
||||
* Missing or incorrect nonces
|
||||
* Missing capability checks
|
||||
* Direct database queries instead of using WordPress functions
|
||||
* Improper enqueuing of scripts and styles
|
||||
* Not using WordPress functions for common tasks
|
||||
|
||||
### JavaScript Issues
|
||||
|
||||
- Undefined variables or functions
|
||||
- Event listener memory leaks
|
||||
- jQuery conflicts
|
||||
- Browser compatibility issues
|
||||
- Missing error handling
|
||||
* Undefined variables or functions
|
||||
* Event listener memory leaks
|
||||
* jQuery conflicts
|
||||
* Browser compatibility issues
|
||||
* Missing error handling
|
||||
|
||||
### CSS Issues
|
||||
|
||||
- Browser compatibility issues
|
||||
- Specificity issues
|
||||
- Unused styles
|
||||
- Overriding WordPress admin styles inappropriately
|
||||
* Browser compatibility issues
|
||||
* Specificity issues
|
||||
* Unused styles
|
||||
* Overriding WordPress admin styles inappropriately
|
||||
|
||||
## Example Feedback
|
||||
|
||||
### Good Feedback Example
|
||||
|
||||
```
|
||||
```markdown
|
||||
In function `handle_remove_reference()`:
|
||||
|
||||
1. The nonce check is missing, which could lead to CSRF vulnerabilities.
|
||||
@@ -161,6 +233,6 @@ In function `handle_remove_reference()`:
|
||||
|
||||
### Poor Feedback Example
|
||||
|
||||
```
|
||||
```text
|
||||
This code has security issues and doesn't follow best practices. Fix it.
|
||||
```
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
---
|
||||
engines:
|
||||
markdownlint:
|
||||
enabled: true
|
||||
config_file: .markdownlint.json
|
||||
phpmd:
|
||||
enabled: true
|
||||
phpcs:
|
||||
enabled: true
|
||||
stylelint:
|
||||
enabled: false
|
||||
shellcheck:
|
||||
enabled: false
|
||||
# Disable tools that are causing issues
|
||||
eslint:
|
||||
enabled: false
|
||||
eslint-8:
|
||||
enabled: false
|
||||
eslint-9:
|
||||
enabled: false
|
||||
trivy:
|
||||
enabled: false
|
||||
semgrep:
|
||||
enabled: false
|
||||
checkov:
|
||||
enabled: false
|
||||
pmd:
|
||||
enabled: false
|
||||
pmd-7:
|
||||
enabled: false
|
||||
lizard:
|
||||
enabled: false
|
||||
jshint:
|
||||
enabled: false
|
||||
csslint:
|
||||
enabled: false
|
||||
jacksonlinter:
|
||||
enabled: false
|
||||
spectral:
|
||||
enabled: false
|
||||
|
||||
duplication:
|
||||
enabled: true
|
||||
exclude_patterns:
|
||||
- "tests/**"
|
||||
- "vendor/**"
|
||||
- "node_modules/**"
|
||||
|
||||
metrics:
|
||||
enabled: true
|
||||
|
||||
exclude_paths:
|
||||
- "vendor/**"
|
||||
- "node_modules/**"
|
||||
- "build/**"
|
||||
- "dist/**"
|
||||
- "bin/**"
|
||||
- ".github/**"
|
||||
- "tests/**"
|
||||
- "*.lock"
|
||||
- "*.json"
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"jquery": true,
|
||||
"es6": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"globals": {
|
||||
"wp": "readonly",
|
||||
"wpstData": "readonly",
|
||||
"wpstModalData": "readonly",
|
||||
"Cypress": "readonly",
|
||||
"cy": "readonly",
|
||||
"describe": "readonly",
|
||||
"it": "readonly",
|
||||
"before": "readonly",
|
||||
"module": "readonly"
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"indent": ["error", 2],
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"quotes": ["error", "single"],
|
||||
"semi": ["error", "always"]
|
||||
},
|
||||
"ignorePatterns": ["vendor/**", "node_modules/**", "build/**", "dist/**", "bin/**"]
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
name: Code Quality
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
phpcs:
|
||||
name: PHP CodeSniffer
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
clean: 'true'
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
extensions: mbstring, intl, zip
|
||||
tools: composer:v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
- name: Install WordPress Coding Standards
|
||||
run: |
|
||||
composer require --dev wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer
|
||||
vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs
|
||||
|
||||
- name: Run PHPCS
|
||||
run: composer phpcs
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run PHPCBF (report only)
|
||||
run: |
|
||||
echo "Running PHPCBF in dry-run mode to show what would be fixed"
|
||||
composer phpcbf -- --dry-run
|
||||
continue-on-error: true
|
||||
|
||||
phpstan:
|
||||
name: PHPStan Static Analysis
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
extensions: mbstring, intl, zip
|
||||
tools: composer:v2, phpstan
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
- name: Install PHPStan WordPress stubs
|
||||
run: composer require --dev szepeviktor/phpstan-wordpress
|
||||
|
||||
- name: Run PHPStan
|
||||
run: composer phpstan
|
||||
continue-on-error: true
|
||||
|
||||
phpmd:
|
||||
name: PHP Mess Detector
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
extensions: mbstring, intl, zip
|
||||
tools: composer:v2, phpmd
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
- name: Run PHPMD
|
||||
run: composer phpmd
|
||||
continue-on-error: true
|
||||
|
||||
sonarcloud:
|
||||
name: SonarCloud Analysis
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Cache SonarCloud packages
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.sonar/cache
|
||||
key: ${{ runner.os }}-sonar
|
||||
restore-keys: ${{ runner.os }}-sonar
|
||||
|
||||
- name: SonarCloud Scan
|
||||
uses: SonarSource/sonarqube-scan-action@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
with:
|
||||
args: >
|
||||
-Dsonar.projectKey=wpallstars_wp-plugin-starter-template-for-ai-coding
|
||||
-Dsonar.organization=wpallstars
|
||||
-Dsonar.sources=.
|
||||
-Dsonar.exclusions=vendor/**,node_modules/**,tests/**,bin/**,build/**,dist/**
|
||||
-Dsonar.sourceEncoding=UTF-8
|
||||
continue-on-error: true
|
||||
|
||||
codacy:
|
||||
name: Codacy Analysis
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run Codacy Analysis CLI
|
||||
uses: codacy/codacy-analysis-cli-action@v4.3.0
|
||||
with:
|
||||
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
|
||||
verbose: true
|
||||
output: results.sarif
|
||||
format: sarif
|
||||
# Limit the number of issues to prevent GitHub Code Scanning rejection
|
||||
gh-code-scanning-compat: true
|
||||
max-allowed-issues: 20
|
||||
# Limit tools to prevent timeouts and stay under GitHub's 20 runs limit
|
||||
tool: phpcs,phpmd,markdownlint
|
||||
continue-on-error: true
|
||||
|
||||
- name: Upload SARIF results file
|
||||
uses: github/codeql-action/upload-sarif@v3
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
continue-on-error: true
|
||||
@@ -63,5 +63,12 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
# - name: Run PHPCS
|
||||
# run: ./vendor/bin/phpcs --standard=WordPress ./includes ./admin ./wp-plugin-starter-template.php
|
||||
- name: Run PHPCS
|
||||
run: composer run phpcs
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run PHPCBF (report only)
|
||||
run: |
|
||||
echo "Running PHPCBF in dry-run mode to show what would be fixed"
|
||||
composer run phpcbf -- --dry-run
|
||||
continue-on-error: true
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"default": true,
|
||||
"MD004": {
|
||||
"style": "asterisk"
|
||||
},
|
||||
"MD007": {
|
||||
"indent": 2
|
||||
},
|
||||
"MD013": false,
|
||||
"MD033": false,
|
||||
"MD040": true,
|
||||
"MD041": false,
|
||||
"MD046": {
|
||||
"style": "fenced"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"default": true,
|
||||
"MD004": {
|
||||
"style": "asterisk"
|
||||
},
|
||||
"MD007": {
|
||||
"indent": 2
|
||||
},
|
||||
"MD013": false,
|
||||
"MD033": false,
|
||||
"MD040": true,
|
||||
"MD041": false,
|
||||
"MD046": {
|
||||
"style": "fenced"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "stylelint-config-standard",
|
||||
"rules": {
|
||||
"alpha-value-notation": "percentage",
|
||||
"color-function-notation": "modern",
|
||||
"font-weight-notation": "numeric",
|
||||
"media-feature-range-notation": "context"
|
||||
},
|
||||
"ignoreFiles": [
|
||||
"vendor/**",
|
||||
"node_modules/**",
|
||||
"build/**",
|
||||
"dist/**",
|
||||
"bin/**"
|
||||
]
|
||||
}
|
||||
+95
-32
@@ -8,40 +8,40 @@ This plugin follows the [WordPress Coding Standards](https://developer.wordpress
|
||||
|
||||
### File Structure
|
||||
|
||||
- Each PHP file should begin with the PHP opening tag `<?php` (no closing tag)
|
||||
- Files should use the Unix line endings (LF)
|
||||
- Files should be encoded in UTF-8 without BOM
|
||||
* Each PHP file should begin with the PHP opening tag `<?php` (no closing tag)
|
||||
* Files should use the Unix line endings (LF)
|
||||
* Files should be encoded in UTF-8 without BOM
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
- **Classes**: Use `PascalCase` for class names
|
||||
* **Classes**: Use `PascalCase` for class names
|
||||
```php
|
||||
class MyClassName {}
|
||||
```
|
||||
|
||||
- **Methods and Functions**: Use `snake_case` for method and function names
|
||||
* **Methods and Functions**: Use `snake_case` for method and function names
|
||||
```php
|
||||
function my_function_name() {}
|
||||
public function my_method_name() {}
|
||||
```
|
||||
|
||||
- **Variables**: Use `snake_case` for variable names
|
||||
* **Variables**: Use `snake_case` for variable names
|
||||
```php
|
||||
$my_variable_name = 'value';
|
||||
```
|
||||
|
||||
- **Constants**: Use `UPPERCASE_WITH_UNDERSCORES` for constants
|
||||
* **Constants**: Use `UPPERCASE_WITH_UNDERSCORES` for constants
|
||||
```php
|
||||
define('MY_CONSTANT', 'value');
|
||||
const MY_CLASS_CONSTANT = 'value';
|
||||
```
|
||||
|
||||
- **Namespaces**: Use `PascalCase` for namespace segments
|
||||
* **Namespaces**: Use `PascalCase` for namespace segments
|
||||
```php
|
||||
namespace WPALLSTARS\PluginStarterTemplate;
|
||||
```
|
||||
|
||||
- **Hooks**: Prefix hooks with the plugin's prefix
|
||||
* **Hooks**: Prefix hooks with the plugin's prefix
|
||||
```php
|
||||
do_action('wpst_hook_name');
|
||||
apply_filters('wpst_filter_name', $value);
|
||||
@@ -49,10 +49,10 @@ This plugin follows the [WordPress Coding Standards](https://developer.wordpress
|
||||
|
||||
### Indentation and Formatting
|
||||
|
||||
- Use 4 spaces for indentation (not tabs)
|
||||
- Opening braces for classes and functions should be on the same line
|
||||
- Control structures should have one space between the statement and the opening parenthesis
|
||||
- Each line should be no longer than 100 characters
|
||||
* Use 4 spaces for indentation (not tabs)
|
||||
* Opening braces for classes and functions should be on the same line
|
||||
* Control structures should have one space between the statement and the opening parenthesis
|
||||
* Each line should be no longer than 100 characters
|
||||
|
||||
```php
|
||||
if ($condition) {
|
||||
@@ -66,8 +66,8 @@ if ($condition) {
|
||||
|
||||
### Documentation
|
||||
|
||||
- All classes, methods, and functions should be documented using PHPDoc
|
||||
- Include a description, parameters, return values, and exceptions
|
||||
* All classes, methods, and functions should be documented using PHPDoc
|
||||
* Include a description, parameters, return values, and exceptions
|
||||
|
||||
```php
|
||||
/**
|
||||
@@ -87,9 +87,9 @@ function my_function($param1, $param2) {
|
||||
|
||||
### Object-Oriented Programming
|
||||
|
||||
- Each class should have a single responsibility
|
||||
- Use visibility declarations for all properties and methods (public, protected, private)
|
||||
- Use type hints for parameters and return types when possible
|
||||
* Each class should have a single responsibility
|
||||
* Use visibility declarations for all properties and methods (public, protected, private)
|
||||
* Use type hints for parameters and return types when possible
|
||||
|
||||
```php
|
||||
class MyClass {
|
||||
@@ -118,22 +118,22 @@ This plugin follows the [WordPress JavaScript Coding Standards](https://develope
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
- **Variables and Functions**: Use `camelCase` for variable and function names
|
||||
* **Variables and Functions**: Use `camelCase` for variable and function names
|
||||
```javascript
|
||||
var myVariableName = 'value';
|
||||
function myFunctionName() {}
|
||||
```
|
||||
|
||||
- **Constants**: Use `UPPERCASE_WITH_UNDERSCORES` for constants
|
||||
* **Constants**: Use `UPPERCASE_WITH_UNDERSCORES` for constants
|
||||
```javascript
|
||||
var MY_CONSTANT = 'value';
|
||||
```
|
||||
|
||||
### Indentation and Formatting
|
||||
|
||||
- Use 4 spaces for indentation (not tabs)
|
||||
- Opening braces should be on the same line as the statement
|
||||
- Each line should be no longer than 100 characters
|
||||
* Use 4 spaces for indentation (not tabs)
|
||||
* Opening braces should be on the same line as the statement
|
||||
* Each line should be no longer than 100 characters
|
||||
|
||||
```javascript
|
||||
if (condition) {
|
||||
@@ -147,7 +147,7 @@ if (condition) {
|
||||
|
||||
### Documentation
|
||||
|
||||
- Use JSDoc for documenting functions and objects
|
||||
* Use JSDoc for documenting functions and objects
|
||||
|
||||
```javascript
|
||||
/**
|
||||
@@ -168,9 +168,9 @@ This plugin follows the [WordPress CSS Coding Standards](https://developer.wordp
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
- Use lowercase for selectors
|
||||
- Use hyphens to separate words in class and ID names
|
||||
- Prefix classes and IDs with the plugin's prefix
|
||||
* Use lowercase for selectors
|
||||
* Use hyphens to separate words in class and ID names
|
||||
* Prefix classes and IDs with the plugin's prefix
|
||||
|
||||
```css
|
||||
.wpst-container {
|
||||
@@ -184,11 +184,11 @@ This plugin follows the [WordPress CSS Coding Standards](https://developer.wordp
|
||||
|
||||
### Indentation and Formatting
|
||||
|
||||
- Use 4 spaces for indentation (not tabs)
|
||||
- Each property should be on its own line
|
||||
- Include a space after the colon in property declarations
|
||||
- End each declaration with a semicolon
|
||||
- Use single quotes for attribute selectors and property values
|
||||
* Use 4 spaces for indentation (not tabs)
|
||||
* Each property should be on its own line
|
||||
* Include a space after the colon in property declarations
|
||||
* End each declaration with a semicolon
|
||||
* Use single quotes for attribute selectors and property values
|
||||
|
||||
```css
|
||||
.wpst-container {
|
||||
@@ -202,6 +202,8 @@ This plugin follows the [WordPress CSS Coding Standards](https://developer.wordp
|
||||
|
||||
This plugin uses automated tools to enforce coding standards:
|
||||
|
||||
### Local Development Tools
|
||||
|
||||
1. **PHP_CodeSniffer (PHPCS)**: Checks PHP code against the WordPress Coding Standards
|
||||
```bash
|
||||
composer run phpcs
|
||||
@@ -222,6 +224,67 @@ This plugin uses automated tools to enforce coding standards:
|
||||
npm run lint:css
|
||||
```
|
||||
|
||||
### Continuous Integration Tools
|
||||
|
||||
This project integrates with several code quality tools that automatically analyze your code when you create a pull request. These tools are free for public repositories and should be integrated into any new repositories based on this template.
|
||||
|
||||
1. **CodeRabbit**: AI-powered code review tool
|
||||
* Provides automated feedback on pull requests
|
||||
* Identifies potential issues and suggests improvements
|
||||
* [Website](https://www.coderabbit.ai/)
|
||||
|
||||
2. **CodeFactor**: Continuous code quality monitoring
|
||||
* Provides a grade for your codebase
|
||||
* Identifies issues related to code style, complexity, and potential bugs
|
||||
* Tracks code quality over time
|
||||
* [Website](https://www.codefactor.io/)
|
||||
|
||||
3. **Codacy**: Code quality and static analysis
|
||||
* Provides a grade for your codebase
|
||||
* Identifies issues related to code style, security, and performance
|
||||
* Tracks code quality over time
|
||||
* [Website](https://www.codacy.com/)
|
||||
|
||||
4. **SonarCloud**: Code quality and security analysis
|
||||
* Provides detailed analysis of code quality
|
||||
* Identifies security vulnerabilities and technical debt
|
||||
* Tracks code quality over time
|
||||
* [Website](https://sonarcloud.io/)
|
||||
|
||||
### How to Pass Code Quality Checks
|
||||
|
||||
To ensure your code passes the quality checks from these tools, follow these guidelines:
|
||||
|
||||
1. **Run Local Checks First**
|
||||
* Before pushing your code, run PHPCS and PHPCBF locally
|
||||
* Fix any issues identified by these tools
|
||||
|
||||
2. **Address Common Issues**
|
||||
* **Indentation**: Use 4 spaces for indentation (not tabs)
|
||||
* **Line Length**: Keep lines under 100 characters
|
||||
* **Naming Conventions**: Follow WordPress naming conventions
|
||||
* **Documentation**: Add PHPDoc comments to classes, methods, and functions
|
||||
* **Error Handling**: Implement proper error handling
|
||||
* **Security**: Validate and sanitize input, escape output
|
||||
* **Markdown**: Use asterisks (*) for bullet points, not hyphens (-)
|
||||
|
||||
3. **Using AI Assistants with Code Quality Tools**
|
||||
* When you receive feedback from code quality tools, you can use AI assistants to help address the issues
|
||||
* Copy the output from the code quality tool and paste it into your AI assistant chat
|
||||
* Ask the AI to help you understand and resolve the issues
|
||||
* Example prompt:
|
||||
|
||||
```text
|
||||
I received the following feedback from [Tool Name]. Please help me understand and resolve these issues:
|
||||
|
||||
[Paste the tool output here]
|
||||
```
|
||||
|
||||
4. **Iterative Improvement**
|
||||
* Address issues one at a time, starting with the most critical
|
||||
* Commit and push your changes to see if they resolve the issues
|
||||
* Continue this process until all issues are resolved
|
||||
|
||||
## Conclusion
|
||||
|
||||
Following these coding standards ensures that the plugin's code is consistent, readable, and maintainable. All contributors should adhere to these standards when submitting code to the project.
|
||||
+62
-12
@@ -78,6 +78,45 @@ If you want to contribute code:
|
||||
- Keep pull requests focused on a single change
|
||||
- Write a clear, descriptive title and description
|
||||
- Reference any related issues
|
||||
- Ensure your code passes the automated code quality checks (see below)
|
||||
|
||||
#### Code Quality Tools
|
||||
|
||||
This project uses several automated code quality tools to ensure high standards. These tools are free for public repositories and will automatically analyze your code when you create a pull request:
|
||||
|
||||
1. **CodeRabbit**: AI-powered code review tool
|
||||
- [Website](https://www.coderabbit.ai/)
|
||||
- Provides automated feedback on pull requests
|
||||
|
||||
2. **CodeFactor**: Continuous code quality monitoring
|
||||
- [Website](https://www.codefactor.io/)
|
||||
- Provides a grade for your codebase
|
||||
|
||||
3. **Codacy**: Code quality and static analysis
|
||||
- [Website](https://www.codacy.com/)
|
||||
- Identifies issues related to code style, security, and performance
|
||||
|
||||
4. **SonarCloud**: Code quality and security analysis
|
||||
- [Website](https://sonarcloud.io/)
|
||||
- Provides detailed analysis of code quality and security
|
||||
|
||||
#### Using AI Assistants with Code Quality Tools
|
||||
|
||||
When you receive feedback from these code quality tools, you can use AI assistants to help address the issues:
|
||||
|
||||
1. Copy the output from the code quality tool
|
||||
2. Paste it into your AI assistant chat
|
||||
3. Ask the AI to help you understand and resolve the issues
|
||||
4. Apply the suggested fixes
|
||||
5. Commit the changes and verify that the issues are resolved
|
||||
|
||||
Example prompt for AI assistants:
|
||||
|
||||
```text
|
||||
I received the following feedback from [Tool Name]. Please help me understand and resolve these issues:
|
||||
|
||||
[Paste the tool output here]
|
||||
```
|
||||
|
||||
## Development Environment
|
||||
|
||||
@@ -91,33 +130,44 @@ To set up your development environment:
|
||||
|
||||
Before submitting a pull request, make sure to run the tests:
|
||||
|
||||
- PHP Unit Tests: `npm run test:php`
|
||||
- End-to-End Tests: `npm run test:e2e`
|
||||
- Coding Standards: `npm run lint:php`
|
||||
* PHP Unit Tests: `npm run test:php`
|
||||
* End-to-End Tests: `npm run test:e2e`
|
||||
* Coding Standards: `npm run lint:php`
|
||||
|
||||
#### Code Quality Checks
|
||||
|
||||
To ensure your code meets the quality standards, run these commands before submitting a pull request:
|
||||
|
||||
* Check coding standards: `composer run phpcs`
|
||||
* Fix coding standards automatically: `composer run phpcbf`
|
||||
* Check JavaScript coding standards: `npm run lint:js`
|
||||
* Check CSS coding standards: `npm run lint:css`
|
||||
|
||||
These checks will help identify and fix issues before they are caught by the automated code quality tools in the pull request process.
|
||||
|
||||
## Documentation
|
||||
|
||||
If you're adding a new feature or changing existing functionality, please update the documentation:
|
||||
|
||||
- Update the README.md file if necessary
|
||||
- Update the readme.txt file if necessary
|
||||
- Update or create wiki pages as needed
|
||||
- Update code comments
|
||||
* Update the README.md file if necessary
|
||||
* Update the readme.txt file if necessary
|
||||
* Update or create wiki pages as needed
|
||||
* Update code comments
|
||||
|
||||
## Community
|
||||
|
||||
Join our community to discuss the project:
|
||||
|
||||
- [GitHub Discussions](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/discussions)
|
||||
- [Gitea Issues](https://gitea.wpallstars.com/wpallstars/wp-plugin-starter-template-for-ai-coding/issues)
|
||||
* [GitHub Discussions](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/discussions)
|
||||
* [Gitea Issues](https://gitea.wpallstars.com/wpallstars/wp-plugin-starter-template-for-ai-coding/issues)
|
||||
|
||||
## Recognition
|
||||
|
||||
Contributors will be recognized in the following ways:
|
||||
|
||||
- Added to the contributors list in readme.txt
|
||||
- Mentioned in release notes for significant contributions
|
||||
- Thanked in the Changelog for specific contributions
|
||||
* Added to the contributors list in readme.txt
|
||||
* Mentioned in release notes for significant contributions
|
||||
* Thanked in the Changelog for specific contributions
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
All notable changes to this project should be documented both here and in the main Readme files.
|
||||
|
||||
#### [0.1.11] - 2023-04-21
|
||||
|
||||
#### Improved
|
||||
|
||||
- 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
|
||||
|
||||
#### [0.1.10] - 2025-04-20
|
||||
|
||||
#### Fixed
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# WordPress Plugin Starter Template for AI Coding
|
||||
|
||||
[](https://www.gnu.org/licenses/gpl-2.0.html) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/actions/workflows/tests.yml) [](https://wordpress.org/about/requirements/) [](https://wordpress.org/about/requirements/) [](https://wordpress.org/plugins/your-plugin-slug/) [](https://wordpress.org/plugins/your-plugin-slug/reviews/) [](https://wordpress.org/plugins/your-plugin-slug/) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/releases) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/issues) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/graphs/contributors) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/wiki)  [](https://www.codefactor.io/repository/github/wpallstars/wp-plugin-starter-template-for-ai-coding) [](https://sonarcloud.io/summary/new_code?id=wpallstars_wp-plugin-starter-template-for-ai-coding) [](https://app.codacy.com/gh/wpallstars/wp-plugin-starter-template-for-ai-coding/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
||||
[](https://www.gnu.org/licenses/gpl-2.0.html) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/actions/workflows/tests.yml) [](https://wordpress.org/about/requirements/) [](https://wordpress.org/about/requirements/) [](https://wordpress.org/plugins/your-plugin-slug/) [](https://wordpress.org/plugins/your-plugin-slug/reviews/) [](https://wordpress.org/plugins/your-plugin-slug/) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/releases) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/issues) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/graphs/contributors) [](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/wiki)  [](https://www.codefactor.io/repository/github/wpallstars/wp-plugin-starter-template-for-ai-coding) [](https://sonarcloud.io/summary/new_code?id=wpallstars_wp-plugin-starter-template-for-ai-coding) [](https://sonarcloud.io/summary/new_code?id=wpallstars_wp-plugin-starter-template-for-ai-coding) [](https://sonarcloud.io/summary/new_code?id=wpallstars_wp-plugin-starter-template-for-ai-coding) [](https://sonarcloud.io/summary/new_code?id=wpallstars_wp-plugin-starter-template-for-ai-coding) [](https://sonarcloud.io/summary/new_code?id=wpallstars_wp-plugin-starter-template-for-ai-coding) [](https://app.codacy.com/gh/wpallstars/wp-plugin-starter-template-for-ai-coding/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
||||
|
||||
A comprehensive starter template for WordPress plugins with best practices for AI-assisted development.
|
||||
|
||||
@@ -235,6 +235,205 @@ Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
4. Push to the branch: `git push origin feature/amazing-feature`
|
||||
5. Submit a pull request
|
||||
|
||||
For more detailed information, see the [Contributing Guide](.wiki/Contributing.md).
|
||||
|
||||
### Code Quality Tools
|
||||
|
||||
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:
|
||||
|
||||
1. **CodeRabbit**: AI-powered code review tool
|
||||
* [Website](https://www.coderabbit.ai/)
|
||||
* Provides automated feedback on pull requests
|
||||
|
||||
2. **CodeFactor**: Continuous code quality monitoring
|
||||
* [Website](https://www.codefactor.io/)
|
||||
* Provides a grade for your codebase
|
||||
|
||||
3. **Codacy**: Code quality and static analysis
|
||||
* [Website](https://www.codacy.com/)
|
||||
* Identifies issues related to code style, security, and performance
|
||||
* Requires a `CODACY_PROJECT_TOKEN` secret in your GitHub repository settings
|
||||
* To set up Codacy:
|
||||
1. Go to [Codacy](https://www.codacy.com/) and sign in with your GitHub account
|
||||
2. Add your repository to Codacy
|
||||
3. Go to your project settings > Integrations > Project API
|
||||
4. Generate a project API token
|
||||
5. Add the token as a secret named `CODACY_PROJECT_TOKEN` in your GitHub repository settings
|
||||
6. 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.
|
||||
|
||||
4. **SonarCloud**: Code quality and security analysis
|
||||
* [Website](https://sonarcloud.io/)
|
||||
* Provides detailed analysis of code quality and security
|
||||
* Requires a `SONAR_TOKEN` secret in your GitHub repository settings
|
||||
* To set up SonarCloud:
|
||||
1. Go to [SonarCloud](https://sonarcloud.io/) and sign in with your GitHub account
|
||||
2. Create a new organization or use an existing one
|
||||
3. Add your repository to SonarCloud
|
||||
4. Generate a token in SonarCloud (Account > Security > Tokens)
|
||||
5. Add the token as a secret named `SONAR_TOKEN` in your GitHub repository or organization settings (see "GitHub Secrets Management" section below)
|
||||
|
||||
5. **PHP_CodeSniffer (PHPCS)**: PHP code style checker
|
||||
* Enforces WordPress Coding Standards
|
||||
* Automatically runs in GitHub Actions workflow
|
||||
* Run locally with `composer phpcs`
|
||||
|
||||
6. **PHP Code Beautifier and Fixer (PHPCBF)**: Automatically fixes coding standard violations
|
||||
* Run locally with `composer phpcbf`
|
||||
|
||||
7. **PHPStan**: PHP static analysis tool
|
||||
* Detects bugs and errors without running the code
|
||||
* Run locally with `composer phpstan`
|
||||
|
||||
8. **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](docs/code-quality-setup.md).
|
||||
|
||||
### Using AI Assistants with Code Quality Tools
|
||||
|
||||
When you receive feedback from these code quality tools, you can use AI assistants to help address the issues:
|
||||
|
||||
1. Copy the output from the code quality tool
|
||||
2. Paste it into your AI assistant chat
|
||||
3. Ask the AI to help you understand and resolve the issues
|
||||
4. Apply the suggested fixes
|
||||
5. 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](.wiki/Coding-Standards.md).
|
||||
|
||||
### GitHub Secrets Management
|
||||
|
||||
GitHub offers three levels of secrets management, each with different scopes and use cases:
|
||||
|
||||
1. **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
|
||||
|
||||
2. **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
|
||||
|
||||
3. **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.
|
||||
|
||||
### Local Environment Setup for Code Quality Tools
|
||||
|
||||
To run code quality tools locally before committing to GitHub:
|
||||
|
||||
1. **Install dependencies**:
|
||||
|
||||
```bash
|
||||
composer install
|
||||
```
|
||||
|
||||
2. **Run PHP CodeSniffer**:
|
||||
|
||||
```bash
|
||||
composer phpcs
|
||||
```
|
||||
|
||||
3. **Fix coding standards automatically**:
|
||||
|
||||
```bash
|
||||
composer phpcbf
|
||||
```
|
||||
|
||||
4. **Run PHPStan static analysis**:
|
||||
|
||||
```bash
|
||||
composer phpstan
|
||||
```
|
||||
|
||||
5. **Run PHP Mess Detector**:
|
||||
|
||||
```bash
|
||||
composer phpmd
|
||||
```
|
||||
|
||||
6. **Run all linters at once**:
|
||||
|
||||
```bash
|
||||
composer lint
|
||||
```
|
||||
|
||||
7. **Set up environment variables for SonarCloud and Codacy**:
|
||||
|
||||
* **For macOS/Linux**:
|
||||
```bash
|
||||
export SONAR_TOKEN=your_sonar_token
|
||||
export CODACY_PROJECT_TOKEN=your_codacy_token
|
||||
```
|
||||
|
||||
* **For Windows (Command Prompt)**:
|
||||
|
||||
```cmd
|
||||
set SONAR_TOKEN=your_sonar_token
|
||||
set CODACY_PROJECT_TOKEN=your_codacy_token
|
||||
```
|
||||
|
||||
* **For Windows (PowerShell)**:
|
||||
|
||||
```powershell
|
||||
$env:SONAR_TOKEN="your_sonar_token"
|
||||
$env:CODACY_PROJECT_TOKEN="your_codacy_token"
|
||||
```
|
||||
|
||||
8. **Create a .env file** (alternative approach):
|
||||
|
||||
```env
|
||||
# .env (already included in .gitignore to prevent committing secrets)
|
||||
SONAR_TOKEN=your_sonar_token
|
||||
CODACY_PROJECT_TOKEN=your_codacy_token
|
||||
```
|
||||
|
||||
Then load these variables:
|
||||
|
||||
```bash
|
||||
# Using a tool like dotenv
|
||||
source .env
|
||||
```
|
||||
|
||||
9. **Run SonarCloud locally**:
|
||||
|
||||
```bash
|
||||
# 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
|
||||
```
|
||||
|
||||
10. **Run Codacy locally**:
|
||||
|
||||
```bash
|
||||
# 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](docs/code-quality-setup.md).
|
||||
|
||||
By running these tools locally, you can identify and fix issues before pushing your code to GitHub, ensuring smoother CI/CD workflows.
|
||||
|
||||
## Developers
|
||||
|
||||
### AI-Powered Development
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
|
||||
}
|
||||
|
||||
.wpst-admin-header {
|
||||
@@ -98,7 +98,7 @@
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
border-radius: 3px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
|
||||
}
|
||||
|
||||
.wpst-card-header {
|
||||
@@ -124,7 +124,7 @@
|
||||
}
|
||||
|
||||
/* Responsive Styles */
|
||||
@media screen and (max-width: 782px) {
|
||||
@media screen and (width <= 782px) {
|
||||
.wpst-form-table th {
|
||||
width: 100%;
|
||||
display: block;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
background-color: rgb(0 0 0 / 40%);
|
||||
}
|
||||
|
||||
.wpst-modal-content {
|
||||
@@ -23,7 +23,7 @@
|
||||
margin: 10% auto;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
box-shadow: 0 4px 8px rgb(0 0 0 / 10%);
|
||||
width: 500px;
|
||||
max-width: 90%;
|
||||
}
|
||||
@@ -45,7 +45,7 @@
|
||||
top: 10px;
|
||||
right: 15px;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
font-weight: 700;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -108,7 +108,7 @@
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid rgba(0, 0, 0, 0.1);
|
||||
border: 2px solid rgb(0 0 0 / 10%);
|
||||
border-radius: 50%;
|
||||
border-top-color: #0073aa;
|
||||
animation: wpst-spin 1s ease-in-out infinite;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
border: 1px solid #ccd0d4;
|
||||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
|
||||
box-shadow: 0 1px 1px rgb(0 0 0 / 4%);
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,19 @@ echo "Creating build directory..."
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir -p "$BUILD_DIR"
|
||||
|
||||
# Run code quality checks
|
||||
echo "Running code quality checks..."
|
||||
if command -v composer &> /dev/null; then
|
||||
echo "Running PHPCS..."
|
||||
composer run phpcs || { echo "⚠️ PHPCS found issues. Consider running 'composer run phpcbf' to fix them."; }
|
||||
|
||||
# Uncomment the following line to automatically fix coding standards issues
|
||||
# echo "Running PHPCBF..."
|
||||
# composer run phpcbf
|
||||
else
|
||||
echo "⚠️ Composer not found, skipping code quality checks"
|
||||
fi
|
||||
|
||||
# Install composer dependencies
|
||||
echo "Installing composer dependencies..."
|
||||
composer install --no-dev --optimize-autoloader
|
||||
|
||||
+20
-5
@@ -15,11 +15,20 @@
|
||||
"php": ">=7.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"phpunit/phpunit": "^9.5.0",
|
||||
"10up/wp_mock": "^1.0",
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
|
||||
"wp-coding-standards/wpcs": "^3.0",
|
||||
"phpcompatibility/phpcompatibility-wp": "^2.1"
|
||||
"phpcompatibility/phpcompatibility-wp": "^2.1",
|
||||
"phpstan/phpstan": "^1.10.0",
|
||||
"szepeviktor/phpstan-wordpress": "^1.3",
|
||||
"phpmd/phpmd": "^2.13.0",
|
||||
"symfony/dependency-injection": "^5.4",
|
||||
"symfony/config": "^5.4",
|
||||
"symfony/filesystem": "^5.4",
|
||||
"symfony/deprecation-contracts": "^2.5",
|
||||
"doctrine/instantiator": "^1.5.0",
|
||||
"psr/log": "^1.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -37,8 +46,14 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"phpcs": "phpcs --standard=WordPress",
|
||||
"phpcbf": "phpcbf --standard=WordPress",
|
||||
"test": "phpunit"
|
||||
"phpcs": "vendor/bin/phpcs --standard=phpcs.xml",
|
||||
"phpcs:simple": "vendor/bin/phpcs --standard=phpcs-simple.xml",
|
||||
"phpcbf": "vendor/bin/phpcbf --standard=phpcs.xml",
|
||||
"phpcbf:simple": "vendor/bin/phpcbf --standard=phpcs-simple.xml",
|
||||
"phpstan": "vendor/bin/phpstan analyse --level=5 .",
|
||||
"phpmd": "vendor/bin/phpmd . text cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor,node_modules,tests,bin,build,dist",
|
||||
"test": "vendor/bin/phpunit",
|
||||
"lint": ["@phpcs", "@phpstan", "@phpmd"],
|
||||
"fix": ["@phpcbf"]
|
||||
}
|
||||
}
|
||||
Generated
+1348
-7
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,107 @@
|
||||
# Code Quality Tools Setup
|
||||
|
||||
This document explains how to set up and use the code quality tools for this project.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* PHP 7.4 or higher
|
||||
* Composer
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone the repository:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding.git
|
||||
cd wp-plugin-starter-template-for-ai-coding
|
||||
```
|
||||
|
||||
2. Install dependencies:
|
||||
|
||||
```bash
|
||||
composer install
|
||||
```
|
||||
|
||||
## Available Tools
|
||||
|
||||
### PHP CodeSniffer (PHPCS)
|
||||
|
||||
PHPCS checks your code against the WordPress Coding Standards.
|
||||
|
||||
```bash
|
||||
# Run PHPCS
|
||||
composer phpcs
|
||||
|
||||
# Run PHPCS with a simplified ruleset
|
||||
composer phpcs:simple
|
||||
```
|
||||
|
||||
### PHP Code Beautifier and Fixer (PHPCBF)
|
||||
|
||||
PHPCBF automatically fixes coding standard violations.
|
||||
|
||||
```bash
|
||||
# Run PHPCBF to fix coding standard violations
|
||||
composer phpcbf
|
||||
|
||||
# Run PHPCBF with a simplified ruleset
|
||||
composer phpcbf:simple
|
||||
```
|
||||
|
||||
### PHPStan
|
||||
|
||||
PHPStan performs static analysis to find bugs in your code.
|
||||
|
||||
```bash
|
||||
# Run PHPStan
|
||||
composer phpstan
|
||||
```
|
||||
|
||||
### PHP Mess Detector (PHPMD)
|
||||
|
||||
PHPMD detects potential problems in your code.
|
||||
|
||||
```bash
|
||||
# Run PHPMD
|
||||
composer phpmd
|
||||
```
|
||||
|
||||
### Running All Linters
|
||||
|
||||
```bash
|
||||
# Run all linters (PHPCS, PHPStan, PHPMD)
|
||||
composer lint
|
||||
```
|
||||
|
||||
### Running All Fixers
|
||||
|
||||
```bash
|
||||
# Run all fixers (PHPCBF)
|
||||
composer fix
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
For SonarCloud and Codacy integration, you need to set up the following environment variables:
|
||||
|
||||
### SonarCloud
|
||||
|
||||
```bash
|
||||
export SONAR_TOKEN=your_sonar_token
|
||||
```
|
||||
|
||||
### Codacy
|
||||
|
||||
```bash
|
||||
export CODACY_PROJECT_TOKEN=your_codacy_token
|
||||
```
|
||||
|
||||
## CI/CD Integration
|
||||
|
||||
The project includes GitHub Actions workflows for running these tools automatically on each push and pull request. See the `.github/workflows/code-quality.yml` file for details.
|
||||
|
||||
## Customization
|
||||
|
||||
* PHPCS rules can be customized in `phpcs.xml`
|
||||
* PHPStan configuration is in `phpstan.neon`
|
||||
* SonarCloud configuration is in `sonar-project.properties`
|
||||
@@ -34,7 +34,7 @@ class Admin {
|
||||
/**
|
||||
* Initializes WordPress hooks.
|
||||
*/
|
||||
private function initialize_hooks() {
|
||||
private function initialize_hooks(): void {
|
||||
\add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
|
||||
}
|
||||
|
||||
@@ -47,26 +47,26 @@ class Admin {
|
||||
|
||||
*
|
||||
* @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
||||
* @param string $hook_suffix The hook suffix of the current admin page.
|
||||
*/
|
||||
public function enqueue_admin_assets( string $hook_suffix ): void {
|
||||
public function enqueue_admin_assets(): void {
|
||||
|
||||
// @phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
// @phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
if ( ! isset( $_GET['page'] ) || 'wp_plugin_starter_template_settings' !== $_GET['page'] ) {
|
||||
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
|
||||
if ( ! $page || 'wp_plugin_starter_template_settings' !== $page ) {
|
||||
return;
|
||||
}
|
||||
// @phpcs:enable
|
||||
|
||||
// Get the plugin version.
|
||||
$plugin_version = $this->core->get_plugin_version();
|
||||
$pluginVersion = $this->core->get_plugin_version();
|
||||
|
||||
// Enqueue styles.
|
||||
\wp_enqueue_style(
|
||||
'wpst-admin-styles',
|
||||
\plugin_dir_url( __FILE__ ) . '../../admin/css/admin-styles.css',
|
||||
array(), // Dependencies.
|
||||
$plugin_version // Version.
|
||||
$pluginVersion // Version.
|
||||
);
|
||||
|
||||
// Enqueue admin scripts.
|
||||
@@ -74,26 +74,11 @@ class Admin {
|
||||
'wpst-admin-script',
|
||||
\plugin_dir_url( __FILE__ ) . '../../admin/js/admin-scripts.js',
|
||||
array( 'jquery' ),
|
||||
$plugin_version, // Version.
|
||||
$pluginVersion, // Version.
|
||||
true
|
||||
);
|
||||
|
||||
// Prepare data for localization.
|
||||
$data = array(
|
||||
'ajax_url' => \admin_url( 'admin-ajax.php' ),
|
||||
// @TODO: Fix mocking for wp_create_nonce. Issue #1.
|
||||
// 'nonce' => \wp_create_nonce( 'wpst_admin_nonce' ),
|
||||
);
|
||||
|
||||
// Localize the script with the data.
|
||||
// @TODO: Fix mocking for wp_localize_script. Issue #1.
|
||||
// @phpcs:ignore Squiz.PHP.CommentedOutCode.Found
|
||||
/*
|
||||
\wp_localize_script(
|
||||
'wpst-admin-script',
|
||||
'wpst_admin_data',
|
||||
$data
|
||||
);
|
||||
*/
|
||||
// TODO: Implement localization when mocking is fixed (Issue #1).
|
||||
// This will include ajax_url and nonce for security.
|
||||
}
|
||||
}
|
||||
+21
-2
@@ -13,10 +13,20 @@ namespace WPALLSTARS\PluginStarterTemplate;
|
||||
class Core {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Plugin version
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public function __construct() {
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $version Plugin version.
|
||||
*/
|
||||
public function __construct( $version = '' ) {
|
||||
// Initialize hooks.
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,4 +38,13 @@ class Core {
|
||||
public function filter_content( $content ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin version
|
||||
*
|
||||
* @return string The plugin version.
|
||||
*/
|
||||
public function get_plugin_version() {
|
||||
return $this->version;
|
||||
}
|
||||
}
|
||||
@@ -29,11 +29,11 @@ class Plugin {
|
||||
private $admin;
|
||||
|
||||
/**
|
||||
* Plugin file
|
||||
* Plugin file path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_file;
|
||||
private string $pluginFile;
|
||||
|
||||
/**
|
||||
* Plugin version
|
||||
@@ -45,13 +45,13 @@ class Plugin {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $plugin_file Main plugin file path.
|
||||
* @param string $pluginFile Main plugin file path.
|
||||
* @param string $version Plugin version.
|
||||
*/
|
||||
public function __construct( $plugin_file, $version ) {
|
||||
$this->plugin_file = $plugin_file;
|
||||
public function __construct( string $pluginFile, string $version ) {
|
||||
$this->pluginFile = $pluginFile;
|
||||
$this->version = $version;
|
||||
$this->core = new Core();
|
||||
$this->core = new Core( $version );
|
||||
$this->admin = new Admin( $this->core );
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -12,8 +12,15 @@
|
||||
"test:e2e:headless": "cypress run --config-file tests/e2e/cypress.json",
|
||||
"build": "./build.sh",
|
||||
"lint:php": "composer run-script phpcs",
|
||||
"lint:php:simple": "composer run-script phpcs:simple",
|
||||
"lint:phpstan": "composer run-script phpstan",
|
||||
"lint:phpmd": "composer run-script phpmd",
|
||||
"fix:php": "composer run-script phpcbf",
|
||||
"test:php": "composer run-script test"
|
||||
"fix:php:simple": "composer run-script phpcbf:simple",
|
||||
"test:php": "composer run-script test",
|
||||
"lint": "composer run-script lint",
|
||||
"fix": "composer run-script fix",
|
||||
"quality": "npm run lint && npm run test:php"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="WordPress Plugin Starter Template Simple">
|
||||
<description>A simplified ruleset for WordPress Plugin Starter Template.</description>
|
||||
|
||||
<!-- Check all PHP files in directory tree by default. -->
|
||||
<file>.</file>
|
||||
|
||||
<!-- Exclude paths -->
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
||||
<exclude-pattern>*/bin/*</exclude-pattern>
|
||||
<exclude-pattern>*/.github/*</exclude-pattern>
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
<exclude-pattern>*/build/*</exclude-pattern>
|
||||
<exclude-pattern>*/dist/*</exclude-pattern>
|
||||
|
||||
<!-- Command line arguments -->
|
||||
<arg value="sp"/>
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg name="basepath" value="."/>
|
||||
<arg name="parallel" value="8"/>
|
||||
|
||||
<!-- Configs -->
|
||||
<config name="minimum_supported_wp_version" value="5.0"/>
|
||||
<config name="testVersion" value="7.0-"/>
|
||||
|
||||
<!-- Rules -->
|
||||
<rule ref="WordPress">
|
||||
<!-- Exclude rules that are too strict for this project -->
|
||||
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
|
||||
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase"/>
|
||||
</rule>
|
||||
|
||||
<!-- Additional rules for better code quality -->
|
||||
<rule ref="Generic.Formatting.MultipleStatementAlignment">
|
||||
<properties>
|
||||
<property name="maxPadding" value="1"/>
|
||||
<property name="error" value="false"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Use spaces for indentation -->
|
||||
<rule ref="Generic.WhiteSpace.ScopeIndent">
|
||||
<properties>
|
||||
<property name="indent" value="4"/>
|
||||
<property name="tabIndent" value="false"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
|
||||
|
||||
<!-- Enforce proper line endings -->
|
||||
<rule ref="Generic.Files.LineEndings">
|
||||
<properties>
|
||||
<property name="eolChar" value="\n"/>
|
||||
</properties>
|
||||
</rule>
|
||||
</ruleset>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="WordPress Coding Standards">
|
||||
<description>WordPress dev PHP_CodeSniffer ruleset.</description>
|
||||
|
||||
<!-- Check all PHP files in directory tree by default. -->
|
||||
<file>.</file>
|
||||
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
||||
<exclude-pattern>*/bin/*</exclude-pattern>
|
||||
<exclude-pattern>*/.github/*</exclude-pattern>
|
||||
<exclude-pattern>*/tests/*</exclude-pattern>
|
||||
<exclude-pattern>libs/</exclude-pattern>
|
||||
|
||||
<arg name="extensions" value="php" />
|
||||
<arg name="basepath" value="." />
|
||||
<arg name="parallel" value="8" />
|
||||
|
||||
<!-- Configs -->
|
||||
<config name="minimum_supported_wp_version" value="5.2" />
|
||||
|
||||
<!-- Rules -->
|
||||
<rule ref="WordPress">
|
||||
<exclude name="WordPress.NamingConventions.ValidVariableName" />
|
||||
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition" />
|
||||
|
||||
<!-- Disable Strict comparison in array check. Not applicable in the majority of cases. -->
|
||||
<exclude name="WordPress.PHP.StrictInArray" />
|
||||
|
||||
<exclude name="WordPress.WP.I18n" />
|
||||
|
||||
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
|
||||
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching" />
|
||||
|
||||
<exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundIfWithInlineHTML" />
|
||||
<exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundForeachWithInlineHTML" />
|
||||
<exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundIf" />
|
||||
<exclude name="Universal.ControlStructures.IfElseDeclaration.NoNewLine" />
|
||||
<exclude name="Universal.Classes.RequireFinalClass.NonFinalClassFound" />
|
||||
<exclude name="Universal.Namespaces.EnforceCurlyBraceSyntax.Forbidden" />
|
||||
|
||||
<exclude name="Generic.Commenting.Todo" />
|
||||
<exclude name="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition" />
|
||||
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch" />
|
||||
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
|
||||
<exclude name="WordPress.WP.CapitalPDangit.Misspelled" />
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.WhiteSpace.ScopeIndent">
|
||||
<properties>
|
||||
<property name="indent" value="4"/>
|
||||
<property name="tabIndent" value="false"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.WhiteSpace.DisallowTabIndent" />
|
||||
|
||||
<rule ref="Generic.Formatting.MultipleStatementAlignment">
|
||||
<properties>
|
||||
<property name="maxPadding" value="1" />
|
||||
<property name="error" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
@@ -0,0 +1,25 @@
|
||||
parameters:
|
||||
level: 5
|
||||
paths:
|
||||
- includes
|
||||
- admin
|
||||
- wp-plugin-starter-template.php
|
||||
excludePaths:
|
||||
paths:
|
||||
- vendor
|
||||
- node_modules
|
||||
- tests
|
||||
- bin
|
||||
- build
|
||||
- dist
|
||||
ignoreErrors:
|
||||
- '#Function apply_filters invoked with [0-9]+ parameters, 2 required.#'
|
||||
- '#Function [a-zA-Z0-9_]+ not found.#'
|
||||
- '#Call to static method [a-zA-Z0-9_:()]+ on an unknown class [a-zA-Z0-9_]+.#'
|
||||
- '#Function do_action invoked with [0-9]+ parameters, 1 required.#'
|
||||
- '#Function add_action invoked with [0-9]+ parameters, 2 required.#'
|
||||
- '#Function add_filter invoked with [0-9]+ parameters, 2 required.#'
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
|
||||
includes:
|
||||
- vendor/szepeviktor/phpstan-wordpress/extension.neon
|
||||
+36
-1
@@ -5,7 +5,7 @@ Tags: starter, template, boilerplate, plugin development, ai coding
|
||||
Requires at least: 5.0
|
||||
Tested up to: 6.5
|
||||
Requires PHP: 7.4
|
||||
Stable tag: 0.1.10
|
||||
Stable tag: 0.1.11
|
||||
License: GPL-2.0-or-later
|
||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
@@ -133,6 +133,29 @@ Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
4. Push to the branch: `git push origin feature/amazing-feature`
|
||||
5. Submit a pull request
|
||||
|
||||
For more detailed information, see the [Contributing Guide](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/wiki/Contributing) in the wiki.
|
||||
|
||||
= Code Quality Tools =
|
||||
|
||||
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:
|
||||
|
||||
1. **[CodeRabbit](https://www.coderabbit.ai/)**: AI-powered code review tool that provides automated feedback on pull requests
|
||||
2. **[CodeFactor](https://www.codefactor.io/)**: Continuous code quality monitoring that provides a grade for your codebase
|
||||
3. **[Codacy](https://www.codacy.com/)**: Code quality and static analysis that identifies issues related to code style, security, and performance
|
||||
4. **[SonarCloud](https://sonarcloud.io/)**: Code quality and security analysis that provides detailed analysis of code quality and security
|
||||
|
||||
= Using AI Assistants with Code Quality Tools =
|
||||
|
||||
When you receive feedback from these code quality tools, you can use AI assistants to help address the issues:
|
||||
|
||||
1. Copy the output from the code quality tool
|
||||
2. Paste it into your AI assistant chat
|
||||
3. Ask the AI to help you understand and resolve the issues
|
||||
4. Apply the suggested fixes
|
||||
5. 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](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/wiki/Coding-Standards) in the wiki.
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Clone or download this repository
|
||||
@@ -205,6 +228,15 @@ npm run multisite
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 0.1.11 =
|
||||
* 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
|
||||
|
||||
= 0.1.10 =
|
||||
* Fixed: Formatting issues in markdown files for better code quality
|
||||
* Fixed: Improved URL formatting with angle brackets
|
||||
@@ -256,6 +288,9 @@ npm run multisite
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 0.1.11 =
|
||||
Improved code quality with comprehensive fixes, better security, and standardized naming conventions across the codebase.
|
||||
|
||||
= 0.1.10 =
|
||||
Improved code quality with better formatting in documentation files, standardized list formatting, and proper URL formatting.
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Required metadata
|
||||
sonar.projectKey=wpallstars_wp-plugin-starter-template-for-ai-coding
|
||||
sonar.organization=wpallstars
|
||||
sonar.projectName=wp-plugin-starter-template-for-ai-coding
|
||||
sonar.projectVersion=0.1.10
|
||||
|
||||
# Path to source directories
|
||||
sonar.sources=.
|
||||
|
||||
# Path to test directories (comment if no test)
|
||||
sonar.tests=tests
|
||||
|
||||
# Source encoding
|
||||
sonar.sourceEncoding=UTF-8
|
||||
|
||||
# Exclusions for copy-paste detection
|
||||
sonar.cpd.exclusions=tests/**
|
||||
|
||||
# Exclude directories and files
|
||||
sonar.exclusions=vendor/**,node_modules/**,tests/**,bin/**,build/**,dist/**,.github/**,.git/**
|
||||
|
||||
# PHP specific configuration
|
||||
sonar.php.coverage.reportPaths=coverage.xml
|
||||
sonar.php.tests.reportPath=test-report.xml
|
||||
|
||||
# Additional parameters
|
||||
sonar.verbose=true
|
||||
+6
-171
@@ -65,179 +65,14 @@ class AdminTest extends \WP_Mock\Tools\TestCase {
|
||||
$this->assertInstanceOf(Admin::class, $this->admin);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Test the enqueue_admin_assets method.
|
||||
*/
|
||||
/*
|
||||
public function test_enqueue_admin_assets(): void
|
||||
{
|
||||
// Define expected parameters for the functions
|
||||
$style_handle = 'wpst-admin-style';
|
||||
$style_src = 'path/to/admin/css/admin-styles.css';
|
||||
$script_handle = 'wpst-admin-script';
|
||||
$script_src = 'path/to/admin/js/admin-scripts.js';
|
||||
$version = '1.0.0'; // Match the version returned by the mocked core->get_plugin_version()
|
||||
|
||||
// Expect wp_enqueue_style to be called
|
||||
\WP_Mock::userFunction(
|
||||
'wp_enqueue_style',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ $style_handle, $style_src, [], $version ],
|
||||
]
|
||||
);
|
||||
|
||||
// Expect wp_enqueue_script to be called
|
||||
\WP_Mock::userFunction(
|
||||
'wp_enqueue_script',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ $script_handle, $script_src, [ 'jquery' ], $version, true ],
|
||||
]
|
||||
);
|
||||
|
||||
// Expect wp_localize_script to be called
|
||||
$expected_data = [
|
||||
'ajax_url' => 'mock_ajax_url',
|
||||
'nonce' => 'mock_nonce',
|
||||
];
|
||||
// Mock admin_url() before wp_localize_script uses it
|
||||
\WP_Mock::userFunction(
|
||||
'admin_url',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ 'admin-ajax.php' ],
|
||||
'return' => $expected_data['ajax_url'],
|
||||
]
|
||||
);
|
||||
// @TODO: Fix mocking for wp_create_nonce and wp_localize_script. Issue #1
|
||||
// We need to mock wp_create_nonce as it's called directly in the method
|
||||
/*
|
||||
\WP_Mock::userFunction(
|
||||
'wp_create_nonce',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ 'wpst_admin_nonce' ], // Match the action string used in class-admin.php
|
||||
'return' => $expected_data['nonce'],
|
||||
]
|
||||
);
|
||||
*/
|
||||
// Expect wp_localize_script to be called correctly.
|
||||
/*
|
||||
\WP_Mock::userFunction(
|
||||
'wp_localize_script',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [
|
||||
$script_handle,
|
||||
'wpst_admin_params',
|
||||
\Mockery::on(
|
||||
function ( $data ) use ( $expected_data ) {
|
||||
// Verify the structure and types of the localized data.
|
||||
return is_array( $data )
|
||||
&& isset( $data['ajax_url'] )
|
||||
&& $data['ajax_url'] === $expected_data['ajax_url']
|
||||
&& isset( $data['nonce'] )
|
||||
&& is_string( $data['nonce'] ); // Check nonce exists and is a string
|
||||
}
|
||||
),
|
||||
],
|
||||
]
|
||||
);
|
||||
*/
|
||||
|
||||
// Call the method under test.
|
||||
$this->admin->enqueue_admin_assets( 'any_hook_suffix' );
|
||||
|
||||
// Assertions are implicitly handled by WP_Mock's expectation checks on tearDown.
|
||||
$this->assertTrue( true ); // Add a basic assertion to prevent risky test warning
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Test the enqueue_admin_assets method.
|
||||
*
|
||||
* @covers ::enqueue_admin_assets
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* This test is currently disabled due to issues with mocking.
|
||||
* TODO: Fix this test in a future update.
|
||||
*/
|
||||
public function test_enqueue_admin_assets(): void {
|
||||
// Define the hook suffix for the specific admin page.
|
||||
$hook_suffix = 'toplevel_page_wp_plugin_starter_template_settings';
|
||||
$_GET['page'] = 'wp_plugin_starter_template_settings'; // Simulate being on the correct page.
|
||||
|
||||
// Define expected values.
|
||||
$style_handle = 'wpst-admin-styles';
|
||||
$style_src = plugin_dir_url( dirname( __DIR__ ) ) . 'admin/css/admin-styles.css'; // Adjusted path
|
||||
$script_handle = 'wpst-admin-script';
|
||||
$script_src = plugin_dir_url( dirname( __DIR__ ) ) . 'admin/js/admin-scripts.js'; // Adjusted path
|
||||
$version = '1.0.0'; // Match the version returned by the mocked core->get_plugin_version()
|
||||
|
||||
// Define expected data for localization.
|
||||
$expected_data = [
|
||||
'ajax_url' => 'http://example.org/wp-admin/admin-ajax.php',
|
||||
'nonce' => 'test_nonce',
|
||||
];
|
||||
|
||||
// Expect admin_url to be called.
|
||||
\WP_Mock::userFunction(
|
||||
'admin_url',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ 'admin-ajax.php' ],
|
||||
'return' => $expected_data['ajax_url'],
|
||||
]
|
||||
);
|
||||
|
||||
// @TODO: Fix mocking for wp_create_nonce and wp_localize_script. Issue #1
|
||||
// We need to mock wp_create_nonce as it's called directly in the method
|
||||
/*
|
||||
\WP_Mock::userFunction(
|
||||
'wp_create_nonce',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ 'wpst_admin_ajax_nonce' ],
|
||||
'return' => $expected_data['nonce'],
|
||||
]
|
||||
);
|
||||
*/
|
||||
|
||||
// Expect wp_enqueue_style to be called.
|
||||
\WP_Mock::userFunction(
|
||||
'wp_enqueue_style',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ $style_handle, $style_src, [], $version ],
|
||||
]
|
||||
);
|
||||
|
||||
// Expect wp_enqueue_script to be called.
|
||||
\WP_Mock::userFunction(
|
||||
'wp_enqueue_script',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ $script_handle, $script_src, [ 'jquery' ], $version, true ],
|
||||
]
|
||||
);
|
||||
|
||||
// Expect wp_localize_script to be called.
|
||||
/*
|
||||
\WP_Mock::userFunction(
|
||||
'wp_localize_script',
|
||||
[
|
||||
'times' => 1,
|
||||
'args' => [ $script_handle, 'wpst_admin_data', $expected_data ],
|
||||
]
|
||||
);
|
||||
*/
|
||||
|
||||
// Call the method to test.
|
||||
$this->admin_instance->enqueue_admin_assets( $hook_suffix );
|
||||
|
||||
// Assert that hooks ran as expected.
|
||||
$this->assertHooksAdded();
|
||||
// public function test_enqueue_admin_assets(): void
|
||||
// {
|
||||
// // Test implementation will be added in a future update
|
||||
// }
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,290 @@
|
||||
# Coding Standards
|
||||
|
||||
This document outlines the coding standards used in this plugin. Following these standards ensures consistency, readability, and maintainability of the codebase.
|
||||
|
||||
## PHP Coding Standards
|
||||
|
||||
This plugin follows the [WordPress Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/) with some additional guidelines.
|
||||
|
||||
### File Structure
|
||||
|
||||
* Each PHP file should begin with the PHP opening tag `<?php` (no closing tag)
|
||||
* Files should use the Unix line endings (LF)
|
||||
* Files should be encoded in UTF-8 without BOM
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
* **Classes**: Use `PascalCase` for class names
|
||||
```php
|
||||
class MyClassName {}
|
||||
```
|
||||
|
||||
* **Methods and Functions**: Use `snake_case` for method and function names
|
||||
```php
|
||||
function my_function_name() {}
|
||||
public function my_method_name() {}
|
||||
```
|
||||
|
||||
* **Variables**: Use `snake_case` for variable names
|
||||
```php
|
||||
$my_variable_name = 'value';
|
||||
```
|
||||
|
||||
* **Constants**: Use `UPPERCASE_WITH_UNDERSCORES` for constants
|
||||
```php
|
||||
define('MY_CONSTANT', 'value');
|
||||
const MY_CLASS_CONSTANT = 'value';
|
||||
```
|
||||
|
||||
* **Namespaces**: Use `PascalCase` for namespace segments
|
||||
```php
|
||||
namespace WPALLSTARS\PluginStarterTemplate;
|
||||
```
|
||||
|
||||
* **Hooks**: Prefix hooks with the plugin's prefix
|
||||
```php
|
||||
do_action('wpst_hook_name');
|
||||
apply_filters('wpst_filter_name', $value);
|
||||
```
|
||||
|
||||
### Indentation and Formatting
|
||||
|
||||
* Use 4 spaces for indentation (not tabs)
|
||||
* Opening braces for classes and functions should be on the same line
|
||||
* Control structures should have one space between the statement and the opening parenthesis
|
||||
* Each line should be no longer than 100 characters
|
||||
|
||||
```php
|
||||
if ($condition) {
|
||||
// Code here
|
||||
} elseif ($another_condition) {
|
||||
// More code
|
||||
} else {
|
||||
// Default code
|
||||
}
|
||||
```
|
||||
|
||||
### Documentation
|
||||
|
||||
* All classes, methods, and functions should be documented using PHPDoc
|
||||
* Include a description, parameters, return values, and exceptions
|
||||
|
||||
```php
|
||||
/**
|
||||
* Short description of the function.
|
||||
*
|
||||
* Longer description if needed.
|
||||
*
|
||||
* @param string $param1 Description of the parameter.
|
||||
* @param int $param2 Description of the parameter.
|
||||
* @return bool Description of the return value.
|
||||
* @throws Exception When something goes wrong.
|
||||
*/
|
||||
function my_function($param1, $param2) {
|
||||
// Function code
|
||||
}
|
||||
```
|
||||
|
||||
### Object-Oriented Programming
|
||||
|
||||
* Each class should have a single responsibility
|
||||
* Use visibility declarations for all properties and methods (public, protected, private)
|
||||
* Use type hints for parameters and return types when possible
|
||||
|
||||
```php
|
||||
class MyClass {
|
||||
/**
|
||||
* Property description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $property;
|
||||
|
||||
/**
|
||||
* Method description.
|
||||
*
|
||||
* @param string $param Description of the parameter.
|
||||
* @return bool Description of the return value.
|
||||
*/
|
||||
public function my_method(string $param): bool {
|
||||
// Method code
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## JavaScript Coding Standards
|
||||
|
||||
This plugin follows the [WordPress JavaScript Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/).
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
* **Variables and Functions**: Use `camelCase` for variable and function names
|
||||
```javascript
|
||||
var myVariableName = 'value';
|
||||
function myFunctionName() {}
|
||||
```
|
||||
|
||||
* **Constants**: Use `UPPERCASE_WITH_UNDERSCORES` for constants
|
||||
```javascript
|
||||
var MY_CONSTANT = 'value';
|
||||
```
|
||||
|
||||
### Indentation and Formatting
|
||||
|
||||
* Use 4 spaces for indentation (not tabs)
|
||||
* Opening braces should be on the same line as the statement
|
||||
* Each line should be no longer than 100 characters
|
||||
|
||||
```javascript
|
||||
if (condition) {
|
||||
// Code here
|
||||
} else if (anotherCondition) {
|
||||
// More code
|
||||
} else {
|
||||
// Default code
|
||||
}
|
||||
```
|
||||
|
||||
### Documentation
|
||||
|
||||
* Use JSDoc for documenting functions and objects
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* Short description of the function.
|
||||
*
|
||||
* @param {string} param1 - Description of the parameter.
|
||||
* @param {number} param2 - Description of the parameter.
|
||||
* @returns {boolean} Description of the return value.
|
||||
*/
|
||||
function myFunction(param1, param2) {
|
||||
// Function code
|
||||
}
|
||||
```
|
||||
|
||||
## CSS Coding Standards
|
||||
|
||||
This plugin follows the [WordPress CSS Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/).
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
* Use lowercase for selectors
|
||||
* Use hyphens to separate words in class and ID names
|
||||
* Prefix classes and IDs with the plugin's prefix
|
||||
|
||||
```css
|
||||
.wpst-container {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#wpst-header {
|
||||
padding: 10px;
|
||||
}
|
||||
```
|
||||
|
||||
### Indentation and Formatting
|
||||
|
||||
* Use 4 spaces for indentation (not tabs)
|
||||
* Each property should be on its own line
|
||||
* Include a space after the colon in property declarations
|
||||
* End each declaration with a semicolon
|
||||
* Use single quotes for attribute selectors and property values
|
||||
|
||||
```css
|
||||
.wpst-container {
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
font-family: 'Helvetica', sans-serif;
|
||||
}
|
||||
```
|
||||
|
||||
## Automated Code Checking
|
||||
|
||||
This plugin uses automated tools to enforce coding standards:
|
||||
|
||||
### Local Development Tools
|
||||
|
||||
1. **PHP_CodeSniffer (PHPCS)**: Checks PHP code against the WordPress Coding Standards
|
||||
```bash
|
||||
composer run phpcs
|
||||
```
|
||||
|
||||
2. **PHP Code Beautifier and Fixer (PHPCBF)**: Automatically fixes some coding standard violations
|
||||
```bash
|
||||
composer run phpcbf
|
||||
```
|
||||
|
||||
3. **ESLint**: Checks JavaScript code against the WordPress Coding Standards
|
||||
```bash
|
||||
npm run lint:js
|
||||
```
|
||||
|
||||
4. **Stylelint**: Checks CSS code against the WordPress Coding Standards
|
||||
```bash
|
||||
npm run lint:css
|
||||
```
|
||||
|
||||
### Continuous Integration Tools
|
||||
|
||||
This project integrates with several code quality tools that automatically analyze your code when you create a pull request. These tools are free for public repositories and should be integrated into any new repositories based on this template.
|
||||
|
||||
1. **CodeRabbit**: AI-powered code review tool
|
||||
* Provides automated feedback on pull requests
|
||||
* Identifies potential issues and suggests improvements
|
||||
* [Website](https://www.coderabbit.ai/)
|
||||
|
||||
2. **CodeFactor**: Continuous code quality monitoring
|
||||
* Provides a grade for your codebase
|
||||
* Identifies issues related to code style, complexity, and potential bugs
|
||||
* Tracks code quality over time
|
||||
* [Website](https://www.codefactor.io/)
|
||||
|
||||
3. **Codacy**: Code quality and static analysis
|
||||
* Provides a grade for your codebase
|
||||
* Identifies issues related to code style, security, and performance
|
||||
* Tracks code quality over time
|
||||
* [Website](https://www.codacy.com/)
|
||||
|
||||
4. **SonarCloud**: Code quality and security analysis
|
||||
* Provides detailed analysis of code quality
|
||||
* Identifies security vulnerabilities and technical debt
|
||||
* Tracks code quality over time
|
||||
* [Website](https://sonarcloud.io/)
|
||||
|
||||
### How to Pass Code Quality Checks
|
||||
|
||||
To ensure your code passes the quality checks from these tools, follow these guidelines:
|
||||
|
||||
1. **Run Local Checks First**
|
||||
* Before pushing your code, run PHPCS and PHPCBF locally
|
||||
* Fix any issues identified by these tools
|
||||
|
||||
2. **Address Common Issues**
|
||||
* **Indentation**: Use 4 spaces for indentation (not tabs)
|
||||
* **Line Length**: Keep lines under 100 characters
|
||||
* **Naming Conventions**: Follow WordPress naming conventions
|
||||
* **Documentation**: Add PHPDoc comments to classes, methods, and functions
|
||||
* **Error Handling**: Implement proper error handling
|
||||
* **Security**: Validate and sanitize input, escape output
|
||||
* **Markdown**: Use asterisks (*) for bullet points, not hyphens (-)
|
||||
|
||||
3. **Using AI Assistants with Code Quality Tools**
|
||||
* When you receive feedback from code quality tools, you can use AI assistants to help address the issues
|
||||
* Copy the output from the code quality tool and paste it into your AI assistant chat
|
||||
* Ask the AI to help you understand and resolve the issues
|
||||
* Example prompt:
|
||||
|
||||
```text
|
||||
I received the following feedback from [Tool Name]. Please help me understand and resolve these issues:
|
||||
|
||||
[Paste the tool output here]
|
||||
```
|
||||
|
||||
4. **Iterative Improvement**
|
||||
* Address issues one at a time, starting with the most critical
|
||||
* Commit and push your changes to see if they resolve the issues
|
||||
* Continue this process until all issues are resolved
|
||||
|
||||
## Conclusion
|
||||
|
||||
Following these coding standards ensures that the plugin's code is consistent, readable, and maintainable. All contributors should adhere to these standards when submitting code to the project.
|
||||
@@ -0,0 +1,180 @@
|
||||
# Contributing
|
||||
|
||||
Thank you for considering contributing to this project! This document provides guidelines and instructions for contributing.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
By participating in this project, you agree to abide by our code of conduct:
|
||||
|
||||
- Be respectful and inclusive
|
||||
- Be patient and welcoming
|
||||
- Be considerate
|
||||
- Be collaborative
|
||||
- Be open-minded
|
||||
|
||||
## How to Contribute
|
||||
|
||||
### Reporting Bugs
|
||||
|
||||
If you find a bug, please report it by creating an issue on GitHub:
|
||||
|
||||
1. Go to the [Issues](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/issues) page
|
||||
2. Click "New Issue"
|
||||
3. Select "Bug Report"
|
||||
4. Fill out the template with as much detail as possible
|
||||
5. Submit the issue
|
||||
|
||||
Please include:
|
||||
|
||||
- A clear, descriptive title
|
||||
- Steps to reproduce the bug
|
||||
- Expected behavior
|
||||
- Actual behavior
|
||||
- Screenshots (if applicable)
|
||||
- Your environment (WordPress version, PHP version, browser, etc.)
|
||||
|
||||
### Suggesting Enhancements
|
||||
|
||||
If you have an idea for an enhancement:
|
||||
|
||||
1. Go to the [Issues](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/issues) page
|
||||
2. Click "New Issue"
|
||||
3. Select "Feature Request"
|
||||
4. Fill out the template with as much detail as possible
|
||||
5. Submit the issue
|
||||
|
||||
Please include:
|
||||
|
||||
- A clear, descriptive title
|
||||
- A detailed description of the enhancement
|
||||
- Why this enhancement would be useful
|
||||
- Any relevant examples or mockups
|
||||
|
||||
### Pull Requests
|
||||
|
||||
If you want to contribute code:
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a new branch for your feature or bugfix
|
||||
3. Make your changes
|
||||
4. Run tests to ensure your changes don't break anything
|
||||
5. Submit a pull request
|
||||
|
||||
#### Pull Request Process
|
||||
|
||||
1. Fork the repository on [GitHub](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/) or [Gitea](https://gitea.wpallstars.com/wpallstars/wp-plugin-starter-template-for-ai-coding/)
|
||||
2. Clone your fork: `git clone https://github.com/YOUR-USERNAME/wp-plugin-starter-template-for-ai-coding.git`
|
||||
3. Create your feature branch: `git checkout -b feature/amazing-feature`
|
||||
4. Make your changes
|
||||
5. Commit your changes: `git commit -m 'Add some amazing feature'`
|
||||
6. Push to the branch: `git push origin feature/amazing-feature`
|
||||
7. Submit a pull request
|
||||
|
||||
#### Pull Request Guidelines
|
||||
|
||||
- Follow the coding standards (see [Coding Standards](Coding-Standards))
|
||||
- Write tests for your changes
|
||||
- Update documentation as needed
|
||||
- Keep pull requests focused on a single change
|
||||
- Write a clear, descriptive title and description
|
||||
- Reference any related issues
|
||||
- Ensure your code passes the automated code quality checks (see below)
|
||||
|
||||
#### Code Quality Tools
|
||||
|
||||
This project uses several automated code quality tools to ensure high standards. These tools are free for public repositories and will automatically analyze your code when you create a pull request:
|
||||
|
||||
1. **CodeRabbit**: AI-powered code review tool
|
||||
- [Website](https://www.coderabbit.ai/)
|
||||
- Provides automated feedback on pull requests
|
||||
|
||||
2. **CodeFactor**: Continuous code quality monitoring
|
||||
- [Website](https://www.codefactor.io/)
|
||||
- Provides a grade for your codebase
|
||||
|
||||
3. **Codacy**: Code quality and static analysis
|
||||
- [Website](https://www.codacy.com/)
|
||||
- Identifies issues related to code style, security, and performance
|
||||
|
||||
4. **SonarCloud**: Code quality and security analysis
|
||||
- [Website](https://sonarcloud.io/)
|
||||
- Provides detailed analysis of code quality and security
|
||||
|
||||
#### Using AI Assistants with Code Quality Tools
|
||||
|
||||
When you receive feedback from these code quality tools, you can use AI assistants to help address the issues:
|
||||
|
||||
1. Copy the output from the code quality tool
|
||||
2. Paste it into your AI assistant chat
|
||||
3. Ask the AI to help you understand and resolve the issues
|
||||
4. Apply the suggested fixes
|
||||
5. Commit the changes and verify that the issues are resolved
|
||||
|
||||
Example prompt for AI assistants:
|
||||
|
||||
```text
|
||||
I received the following feedback from [Tool Name]. Please help me understand and resolve these issues:
|
||||
|
||||
[Paste the tool output here]
|
||||
```
|
||||
|
||||
## Development Environment
|
||||
|
||||
To set up your development environment:
|
||||
|
||||
1. Clone the repository: `git clone https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding.git`
|
||||
2. Install dependencies: `composer install && npm install`
|
||||
3. Start the development environment: `npm run start`
|
||||
|
||||
### Testing
|
||||
|
||||
Before submitting a pull request, make sure to run the tests:
|
||||
|
||||
* PHP Unit Tests: `npm run test:php`
|
||||
* End-to-End Tests: `npm run test:e2e`
|
||||
* Coding Standards: `npm run lint:php`
|
||||
|
||||
#### Code Quality Checks
|
||||
|
||||
To ensure your code meets the quality standards, run these commands before submitting a pull request:
|
||||
|
||||
* Check coding standards: `composer run phpcs`
|
||||
* Fix coding standards automatically: `composer run phpcbf`
|
||||
* Check JavaScript coding standards: `npm run lint:js`
|
||||
* Check CSS coding standards: `npm run lint:css`
|
||||
|
||||
These checks will help identify and fix issues before they are caught by the automated code quality tools in the pull request process.
|
||||
|
||||
## Documentation
|
||||
|
||||
If you're adding a new feature or changing existing functionality, please update the documentation:
|
||||
|
||||
* Update the README.md file if necessary
|
||||
* Update the readme.txt file if necessary
|
||||
* Update or create wiki pages as needed
|
||||
* Update code comments
|
||||
|
||||
## Community
|
||||
|
||||
Join our community to discuss the project:
|
||||
|
||||
* [GitHub Discussions](https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding/discussions)
|
||||
* [Gitea Issues](https://gitea.wpallstars.com/wpallstars/wp-plugin-starter-template-for-ai-coding/issues)
|
||||
|
||||
## Recognition
|
||||
|
||||
Contributors will be recognized in the following ways:
|
||||
|
||||
* Added to the contributors list in readme.txt
|
||||
* Mentioned in release notes for significant contributions
|
||||
* Thanked in the Changelog for specific contributions
|
||||
|
||||
## License
|
||||
|
||||
By contributing to this project, you agree that your contributions will be licensed under the project's [GPL-2.0+ License](https://www.gnu.org/licenses/gpl-2.0.html).
|
||||
|
||||
## Questions?
|
||||
|
||||
If you have any questions about contributing, please open an issue or contact the maintainers.
|
||||
|
||||
Thank you for your contributions!
|
||||
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: WordPress Plugin Starter Template
|
||||
* Plugin URI: https://www.wpallstars.com
|
||||
* Description: A comprehensive starter template for WordPress plugins with best practices for AI-assisted development.
|
||||
* Version: 0.1.10
|
||||
* Version: 0.1.11
|
||||
* Author: Your Name & The WPALLSTARS Team
|
||||
* Author URI: https://www.wpallstars.com
|
||||
* License: GPL-2.0+
|
||||
@@ -34,5 +34,8 @@ if ( ! defined( 'WPINC' ) ) {
|
||||
// Load the main plugin class.
|
||||
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin.php';
|
||||
|
||||
// Initialize the plugin and store the instance in a global variable.
|
||||
$wpst_plugin = new WPALLSTARS\PluginStarterTemplate\Plugin( __FILE__, '0.1.11' );
|
||||
|
||||
// Initialize the plugin.
|
||||
new WPALLSTARS\PluginStarterTemplate\Plugin( __FILE__, '0.1.10' );
|
||||
$wpst_plugin->init();
|
||||
Reference in new issue
Block a user