# AuraSEO - Development Guide

## Setting Up Development Environment

### Prerequisites
- WordPress 5.6+ with WP_DEBUG enabled
- PHP 7.4+ with error reporting enabled
- Yoast SEO or Rank Math plugin
- Google Gemini or OpenAI API key

### Configuration

Add to wp-config.php:
```php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', true);
```

## File Organization

### Main Plugin File (auraseo.php)
- Plugin header and metadata
- Version constants
- Core class initialization
- Action hooks registration

### Assets Directory (assets/)
```
assets/
├── css/style.css       # 2,500+ lines of professional styling
└── js/script.js        # AJAX handling and UI logic
```

### Languages Directory (languages/)
For translation support using gettext:
```
languages/
├── auraseo.pot     # Translation template
├── auraseo-en_US.po
└── auraseo-en_US.mo
```

### Documentation (docs/)
```
docs/
├── API.md              # API documentation
└── DEVELOPMENT.md      # This file
```

## Coding Standards

### PHP Standards
```php
<?php
/**
 * Function description
 *
 * @param string $param Parameter description
 * @return array Return value description
 */
function function_name( $param ) {
    // Code here
}
```

### JavaScript Standards
```javascript
/**
 * Function description
 *
 * @param {string} param - Parameter description
 * @returns {boolean} Return value description
 */
function functionName(param) {
    // Code here
}
```

### CSS Standards
```css
/* Component description */
.component-name {
    property: value;
    transition: property duration ease;
}

.component-name:hover {
    property: new-value;
}
```

## Testing Checklist

### Before Committing
- No PHP errors or warnings
- No JavaScript console errors
- AJAX requests work properly
- Nonce verification passes
- Database sanitization correct
- HTML properly escaped
- Responsive design works

### Browser Testing
- Chrome (Desktop)
- Firefox (Desktop)
- Safari (Desktop)
- Chrome Mobile
- Safari Mobile

### WordPress Integration
- Plugin activates/deactivates cleanly
- Works with Yoast SEO
- Works with Rank Math
- No conflicts with other plugins
- Database options properly stored

## Debugging Tips

### PHP Debugging
```php
// Log to debug.log
if ( WP_DEBUG ) {
    error_log( 'Message: ' . print_r( $data, true ) );
}

// Die with debug info
wp_die( '<pre>' . print_r( $data, true ) . '</pre>' );
```

### JavaScript Debugging
```javascript
// Console logging
console.log('Debug info:', data);
console.error('Error:', error);

// Conditional debugging
if (amai_vars.debug) {
    console.log('Debug mode enabled');
}
```

### WordPress Actions
```php
// Hook into specific actions for debugging
add_action( 'wp_ajax_amai_generate_meta', function() {
    error_log( 'AJAX called' );
}, 1 );
```

## Performance Optimization

### CSS
- Minified for production
- CSS variables for maintainability
- Proper specificity
- Avoiding redundant rules

### JavaScript
- AJAX error handling
- Proper event delegation
- Memory leak prevention
- Load only on admin page

### PHP
- Use constants instead of hardcoded paths
- Proper nonce verification
- Database query optimization
- Sanitize user input

## Release Process

1. Update version in header comment
2. Update AUTOMETA_AI_VERSION constant
3. Update CHANGELOG.md with changes
4. Commit with message: Release v1.x.x
5. Create git tag: git tag v1.x.x
6. Push to repository

## Common Issues & Solutions

### Issue: AJAX 404 Error
Solution: Verify admin_url() is returning correct URL

### Issue: Nonce Verification Fails
Solution: Check nonce is created and verified properly

### Issue: CSS Not Loading
Solution: Clear browser cache, check URL in header

### Issue: JavaScript Errors
Solution: Check jQuery is enqueued, verify selectors

## Future Enhancements

### Short Term
- i18n support setup
- Error logging improvements
- CLI commands

### Medium Term
- Object-oriented refactoring
- Custom AI provider support
- Advanced filtering

### Long Term
- WordPress REST API endpoints
- Mobile app integration
- Machine learning improvements

## Resources

- WordPress Plugin Handbook
- WordPress Coding Standards
- AJAX in Plugins
- Security in Plugins

## Getting Help

1. Check existing Issues
2. Review INSTALLATION.md
3. Ask in Discussions
4. Contact author: https://mostafijemon.com/


