This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # WordPress Best Practices Checker using Gemini AI | |
| # Analyzes commits for WordPress coding standards and best practices compliance | |
| name: WordPress Best Practices Check | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| workflow_dispatch: | |
| # Cancel previous workflow runs for the same branch | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| wordpress-standards-check: | |
| name: WordPress Standards & Best Practices | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get changed PHP files | |
| id: changed-files | |
| uses: tj-actions/changed-files@v46 | |
| with: | |
| files: | | |
| **/*.php | |
| separator: "\n" | |
| - name: Run WordPress Best Practices Analysis | |
| if: steps.changed-files.outputs.any_changed == 'true' | |
| uses: google-github-actions/run-gemini-cli@v0.1.10 | |
| with: | |
| prompt: | | |
| You are a WordPress development expert and WordPress.org plugin reviewer. | |
| WORDPRESS BEST PRACTICES ANALYSIS: | |
| Review the following code changes for WordPress coding standards and best practices: | |
| π CODING STANDARDS (WordPress Coding Standards): | |
| - PSR-4 autoloading compliance | |
| - Proper function and variable naming (snake_case) | |
| - Class naming conventions (PascalCase with underscores) | |
| - File naming conventions (lowercase with hyphens) | |
| - Proper indentation (tabs vs spaces - WordPress uses tabs) | |
| - Line length limits (150 characters max) | |
| - Proper commenting and PHPDoc blocks | |
| ποΈ ARCHITECTURE & STRUCTURE: | |
| - Single responsibility principle | |
| - Proper use of WordPress hooks (actions/filters) | |
| - Singleton pattern implementation | |
| - Plugin structure and organization | |
| - Proper use of WordPress APIs | |
| π§ WORDPRESS-SPECIFIC BEST PRACTICES: | |
| - Proper plugin header format | |
| - Text domain usage and internationalization | |
| - Capability checks and user permissions | |
| - Database interaction using WordPress functions | |
| - Proper enqueueing of scripts and styles | |
| - Use of WordPress constants and globals | |
| - Plugin activation/deactivation hooks | |
| β‘ PERFORMANCE CONSIDERATIONS: | |
| - Efficient database queries | |
| - Proper caching strategies | |
| - Lazy loading where appropriate | |
| - Avoiding resource-heavy operations | |
| - Proper use of transients | |
| π― PLUGIN-SPECIFIC CHECKS: | |
| - WooCommerce integration best practices | |
| - Admin interface conventions | |
| - REST API implementation | |
| - Custom post type registration | |
| - Meta box implementation | |
| π± COMPATIBILITY: | |
| - PHP version compatibility (7.4+) | |
| - WordPress version compatibility (6.5+) | |
| - Plugin conflicts avoidance | |
| - Theme compatibility | |
| For each finding: | |
| 1. Specify the file and line number | |
| 2. Explain the issue and why it matters | |
| 3. Provide the correct WordPress way to implement it | |
| 4. Reference relevant WordPress Codex documentation | |
| 5. Rate severity: CRITICAL, HIGH, MEDIUM, LOW, or INFO | |
| Focus on improvements that enhance: | |
| - Code maintainability | |
| - WordPress ecosystem compatibility | |
| - Performance and user experience | |
| - Developer experience | |
| FILES TO ANALYZE: | |
| ${{ steps.changed-files.outputs.all_changed_files }} | |
| env: | |
| GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | |
| - name: Comment on PR with Findings | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| // This would be the output from Gemini CLI | |
| const comment = ` | |
| ## π― WordPress Best Practices Review | |
| Thank you for your contribution! I've analyzed your code changes for WordPress best practices and coding standards. | |
| ### π Analysis Summary | |
| - **Files Analyzed:** ${{ steps.changed-files.outputs.all_changed_files_count }} | |
| - **WordPress Version:** 6.5+ compatible | |
| - **PHP Version:** 7.4+ compatible | |
| ### π Key Areas Reviewed | |
| β WordPress Coding Standards | |
| β Plugin Architecture | |
| β Security Best Practices | |
| β Performance Considerations | |
| β Internationalization | |
| > **Note:** This is an AI-powered analysis. Please review suggestions carefully and validate against the [WordPress Plugin Developer Handbook](https://developer.wordpress.org/plugins/). | |
| **Workflow Run:** ${context.payload.repository.html_url}/actions/runs/${context.runId} | |
| `; | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); |