|
| 1 | +# Project-specific instructions for Gemini AI |
| 2 | +# This file provides context about the Simple WP Optimizer WordPress plugin |
| 3 | +# to help Gemini understand the codebase and provide better analysis |
| 4 | + |
| 5 | +# Simple WP Optimizer - WordPress Plugin |
| 6 | + |
| 7 | +## Project Overview |
| 8 | +This is a WordPress performance optimization plugin that removes unnecessary features and scripts to improve site performance. Designed for WordPress administrators who want to optimize their site's speed by disabling unused functionality and reducing resource overhead. |
| 9 | + |
| 10 | +## Plugin Details |
| 11 | +- **Name:** Simple WP Optimizer |
| 12 | +- **Version:** 1.7.0 |
| 13 | +- **WordPress Compatibility:** 6.5+ |
| 14 | +- **PHP Compatibility:** 7.4+ |
| 15 | +- **License:** GPL-3.0-or-later |
| 16 | +- **Text Domain:** simple-wp-optimizer |
| 17 | + |
| 18 | +## Architecture & Design Patterns |
| 19 | + |
| 20 | +### Single-File Plugin Architecture |
| 21 | +The plugin follows a single-file architecture pattern for simplicity: |
| 22 | +```php |
| 23 | +// All functionality contained in simple-wp-optimizer.php |
| 24 | +// Functions prefixed with 'es_optimizer_' for namespace consistency |
| 25 | +function es_optimizer_function_name() { |
| 26 | + // Implementation |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +### Plugin Initialization |
| 31 | +The plugin uses proper WordPress initialization patterns with plugins_loaded hook: |
| 32 | +```php |
| 33 | +function es_optimizer_init() { |
| 34 | + // Hook admin menu creation |
| 35 | + add_action( 'admin_menu', 'es_optimizer_admin_page' ); |
| 36 | + // Hook optimization features |
| 37 | + add_action( 'init', 'es_optimizer_apply_optimizations' ); |
| 38 | + // Other initialization code |
| 39 | +} |
| 40 | +add_action( 'plugins_loaded', 'es_optimizer_init' ); |
| 41 | +``` |
| 42 | + |
| 43 | +### File Structure |
| 44 | +- `simple-wp-optimizer.php` - Main plugin file (all functionality) |
| 45 | +- `languages/` - Translation files (.pot file included) |
| 46 | +- `CHANGELOG.md` - Developer changelog |
| 47 | +- `README.md` - Developer documentation |
| 48 | +- `readme.txt` - WordPress.org plugin directory readme |
| 49 | +- `.github/workflows/` - CI/CD automation with AI-powered analysis |
| 50 | + |
| 51 | +## WordPress Coding Standards |
| 52 | + |
| 53 | +### Naming Conventions |
| 54 | +- **Functions:** `es_optimizer_snake_case` (WordPress standard with plugin prefix) |
| 55 | +- **Variables:** `$snake_case` |
| 56 | +- **Constants:** `ES_WP_OPTIMIZER_UPPER_SNAKE_CASE` |
| 57 | +- **Text Domain:** Always use `'simple-wp-optimizer'` |
| 58 | + |
| 59 | +### Security Requirements |
| 60 | +- Always use `esc_html()`, `esc_attr()`, `esc_url()` for output |
| 61 | +- Sanitize input with `sanitize_text_field()`, `wp_unslash()`, etc. |
| 62 | +- Use `current_user_can( 'manage_options' )` for capability checks |
| 63 | +- Implement proper nonce verification for all forms and actions |
| 64 | +- Validate and sanitize all user-provided URLs and domains |
| 65 | +- Use WordPress Options API for settings storage |
| 66 | + |
| 67 | +### WordPress Integration |
| 68 | +- **Hooks:** Proper use of actions and filters with appropriate priorities |
| 69 | +- **Performance Features:** Integration with WordPress caching and optimization APIs |
| 70 | +- **Settings API:** WordPress Settings API for admin interface |
| 71 | +- **Internationalization:** All strings use `esc_html__()` or `esc_html_e()` |
| 72 | +- **Admin Interface:** Proper admin page integration with WordPress UI standards |
| 73 | + |
| 74 | +## Plugin-Specific Context |
| 75 | + |
| 76 | +### Core Functionality |
| 77 | + |
| 78 | +#### Performance Optimization Features |
| 79 | +- **XML-RPC Disabling:** Remove XML-RPC functionality for security and performance |
| 80 | +- **JSON REST API Control:** Disable REST API for non-logged users |
| 81 | +- **jQuery Migrate Removal:** Remove unnecessary jQuery Migrate script |
| 82 | +- **Header Meta Cleanup:** Remove unnecessary WordPress meta tags from head |
| 83 | +- **Auto-Embeds Disabling:** Disable WordPress auto-embed functionality |
| 84 | +- **Emoji Support Removal:** Remove emoji scripts and styles |
| 85 | +- **Gutenberg CSS Removal:** Remove unused Gutenberg block styles |
| 86 | +- **DNS Prefetch Management:** User-configurable DNS prefetch for external domains |
| 87 | + |
| 88 | +#### Settings Management |
| 89 | +- **Options Caching:** Static caching system to reduce database queries |
| 90 | +- **Conditional Admin Loading:** Admin assets only load on plugin settings page |
| 91 | +- **User-Friendly Interface:** Toggle-based settings for easy optimization control |
| 92 | +- **Input Validation:** Comprehensive validation for all user inputs |
| 93 | + |
| 94 | +#### Security Features |
| 95 | +- **Domain Validation:** DNS prefetch domains validated to prevent injection |
| 96 | +- **Input Sanitization:** All user inputs properly sanitized and escaped |
| 97 | +- **Capability Checks:** Admin-only access with proper permission verification |
| 98 | +- **Nonce Protection:** CSRF protection on all form submissions |
| 99 | + |
| 100 | +### Performance Optimization Focus |
| 101 | +- **Frontend Performance:** Reduces HTTP requests and removes unused resources |
| 102 | +- **Admin Performance:** Conditional loading of admin assets |
| 103 | +- **Database Optimization:** Option caching to minimize database queries |
| 104 | +- **Script Optimization:** Selective removal of unnecessary WordPress scripts |
| 105 | + |
| 106 | +### DNS Prefetch Security |
| 107 | +- **Domain Validation:** All DNS prefetch domains validated to prevent injection |
| 108 | +- **Clean Domain Enforcement:** Only clean domains without paths/parameters allowed |
| 109 | +- **Input Sanitization:** URL validation prevents malicious domain injection |
| 110 | +- **Output Escaping:** All domain outputs properly escaped for security |
| 111 | + |
| 112 | +### WordPress Hook Management |
| 113 | +- **Priority Handling:** High-priority hooks (PHP_INT_MAX) to ensure optimization execution |
| 114 | +- **Hook Timing:** Proper use of init, wp_head, and other WordPress lifecycle hooks |
| 115 | +- **Filter Override Protection:** Prevents other plugins from disabling optimizations |
| 116 | +- **Action Consolidation:** Organized hook management for better performance |
| 117 | + |
| 118 | +### Option Caching System |
| 119 | +- **Static Caching:** `es_optimizer_get_options()` function with static cache |
| 120 | +- **Database Query Reduction:** Minimizes repeated option retrieval |
| 121 | +- **Memory Efficiency:** Efficient caching without memory overhead |
| 122 | +- **Cache Invalidation:** Proper cache clearing when options change |
| 123 | + |
| 124 | +## Development Standards |
| 125 | + |
| 126 | +### Error Handling |
| 127 | +- **WP_Error Usage:** Consistent error object returns throughout |
| 128 | +- **Comprehensive Logging:** Structured logging with severity levels |
| 129 | +- **Security Logging:** Detailed logs for security events |
| 130 | +- **User Feedback:** Clear error messages without information disclosure |
| 131 | + |
| 132 | +### Documentation |
| 133 | +- **PHPDoc Compliance:** Complete documentation for all functions |
| 134 | +- **Security Comments:** Detailed security justifications |
| 135 | +- **Code Examples:** Clear usage examples in documentation |
| 136 | +- **Version Control:** Comprehensive changelog maintenance |
| 137 | + |
| 138 | +### Testing & Quality Assurance |
| 139 | +- **PHPStan Level 5:** Static analysis compliance |
| 140 | +- **PHPCS WordPress Standards:** Full coding standards compliance |
| 141 | +- **PHPMD Compliance:** Code quality and complexity management |
| 142 | +- **Security Analysis:** Regular vulnerability assessments |
| 143 | + |
| 144 | +## When Reviewing Code |
| 145 | + |
| 146 | +### Critical Issues to Flag |
| 147 | +1. **Performance Impact** (optimization conflicts, excessive resource usage) |
| 148 | +2. **WordPress Compatibility** (plugin/theme conflicts, hook interference) |
| 149 | +3. **Security Vulnerabilities** (input validation, output escaping) |
| 150 | +4. **WordPress Standard Violations** (coding standards, API misuse) |
| 151 | +5. **Option Management Issues** (database performance, caching problems) |
| 152 | + |
| 153 | +### Plugin-Specific Security Concerns |
| 154 | +1. **DNS Prefetch Validation:** Ensure domain inputs are properly validated |
| 155 | +2. **Settings Security:** Verify admin-only access and nonce verification |
| 156 | +3. **Hook Priority Conflicts:** Check for potential conflicts with other plugins |
| 157 | +4. **Input Sanitization:** Validate all user-provided domains and settings |
| 158 | +5. **Output Escaping:** Ensure all dynamic content is properly escaped |
| 159 | + |
| 160 | +### Performance Focus Areas |
| 161 | +1. **Frontend Optimization:** Script and style removal effectiveness |
| 162 | +2. **Admin Performance:** Conditional asset loading efficiency |
| 163 | +3. **Database Optimization:** Option caching and query reduction |
| 164 | +4. **Hook Performance:** Efficient hook management and execution |
| 165 | +5. **Memory Usage:** Optimization without excessive memory consumption |
| 166 | + |
| 167 | +### Positive Patterns to Recognize |
| 168 | +1. **WordPress API Compliance:** Proper use of WordPress hooks and functions |
| 169 | +2. **Performance-First Design:** Optimizations that genuinely improve site speed |
| 170 | +3. **User Experience:** Clear interface for managing optimizations |
| 171 | +4. **Compatibility Focus:** Safe optimizations that don't break functionality |
| 172 | +5. **Documentation Quality:** Clear documentation of optimization effects |
| 173 | + |
| 174 | +### Suggestions to Provide |
| 175 | +1. **WordPress-Specific Solutions:** Prefer WordPress APIs over generic PHP |
| 176 | +2. **Performance Enhancements:** Additional optimization opportunities |
| 177 | +3. **Compatibility Improvements:** Better plugin/theme compatibility |
| 178 | +4. **User Experience:** Interface and workflow improvements |
| 179 | +5. **Documentation Updates:** Clear explanation of optimization benefits |
| 180 | + |
| 181 | +Remember: This plugin prioritizes WordPress performance optimization, security through input validation, and compatibility with the WordPress ecosystem. All optimizations must maintain site functionality while improving performance. |
0 commit comments