Development Guide
This guide covers development workflows, build processes, and coding standards for the DocSync plugin.
Development Environment
Local Setup
Clone repository:
bashgit clone https://github.com/chubes4/docsync.git cd docsyncInstall dependencies:
bashcomposer installWordPress setup:
- Use testing-grounds.local (multisite WordPress installation)
- Activate the Chubes theme
- Activate the DocSync plugin
Development Workflow
Code Changes
- Create feature branch from
main - Make changes following coding standards
- Test changes locally
- Run build process
- Create pull request
Testing
- Use testing-grounds.local (multisite WordPress installation)
- Activate the Chubes theme
- Activate the DocSync plugin
Build Process
Production Build
Clone repository:
Build Configuration
Install dependencies:
- Use testing-grounds.local (multisite WordPress installation)
- Activate the Chubes theme
- Activate the DocSync plugin
WordPress setup:
- Manual testing on multisite WordPress installation
- API endpoint testing with curl/Postman
- Integration testing with Chubes theme
- Build validation with production ZIP creation
File Structure
bash
git clone https://github.com/chubes4/docsync.git
cd docsyncCoding Standards
PHP Standards
- All PHP source files
- Composer autoloader (production optimized)
- CSS assets
- Required documentation files
Architectural Principles
- Development files (
.buildignore,README.md) - Source control (
.git/,.gitignore) - Development documentation (
CLAUDE.md)
Code Structure
bash
composer installAPI Development
Adding New Endpoints
Define route in
Routes.php:phpregister_rest_route(self::NAMESPACE, '/new-endpoint', [ 'methods' => 'GET', 'callback' => [NewController::class, 'handle_request'], 'permission_callback' => [self::class, 'check_edit_permission'], ]);Create controller method:
phpclass NewController { public static function handle_request(WP_REST_Request $request): WP_REST_Response|WP_Error { // Implementation return rest_ensure_response($data); } }Add route registration:
phpprivate static function register_new_routes(): void { // Route definitions }
Parameter Validation
bash
git clone https://github.com/chubes4/docsync.git
cd docsyncDatabase Operations
Post Meta
bash
composer installTaxonomy Operations
php
register_rest_route(self::NAMESPACE, '/new-endpoint', [
'methods' => 'GET',
'callback' => [NewController::class, 'handle_request'],
'permission_callback' => [self::class, 'check_edit_permission'],
]);Security Considerations
Input Validation
- PSR-4 autoloading for all classes
- WordPress coding standards for PHP
- Single responsibility principle for class design
- Comprehensive error handling and input validation
SQL Injection Prevention
- KISS (Keep It Simple, Stupid): Favor direct, centralized solutions
- Single responsibility: Each file handles one concern
- Human-readable code: Minimize inline comments through clear naming
- Single source of truth: No data duplication
- REST API over admin-ajax.php
- Vanilla JavaScript over jQuery
- WordPress hooks and filters for extensibility
- Object-oriented programming to reduce duplication
XSS Prevention
- Always sanitize user input
- Use WordPress sanitization functions
- Validate data types and formats
- Check user capabilities
Testing
Manual Testing Checklist
- Use prepared statements
- Avoid direct SQL queries when possible
- Use WordPress query functions
API Testing
php
class NewController {
public static function handle_request(WP_REST_Request $request): WP_REST_Response|WP_Error {
// Implementation
return rest_ensure_response($data);
}
}Version Management
Semantic Versioning
- Use
wp_kses_post()for rich content - Escape output with
esc_html(),esc_attr() - Sanitize before storing
Release Process
- Update version in
composer.json - Update
CHANGELOG.md - Create git tag
- Run production build
- Test production package
- Publish release
Debugging
WordPress Debug Mode
php
private static function register_new_routes(): void {
// Route definitions
}Plugin Debug Logging
nginx
inc/
├── Api/ # REST API layer
│ ├── Controllers/ # Endpoint handlers
│ └── Routes.php # Route registration
├── Core/ # Plugin core systems
│ ├── Assets.php # Asset management
│ ├── Breadcrumbs.php # Breadcrumb generation
│ ├── Project.php # Taxonomy management
│ ├── Documentation.php # Post type handling
│ └── RewriteRules.php # URL routing
├── Fields/ # Admin interface
├── Sync/ # Synchronization
└── Templates/ # Frontend enhancementsAPI Debug Headers
nginx
inc/
├── Api/ # REST API layer
│ ├── Controllers/ # Endpoint handlers
│ └── Routes.php # Route registration
├── Core/ # Plugin core systems
│ ├── Assets.php # Asset management
│ ├── Breadcrumbs.php # Breadcrumb generation
│ ├── Project.php # Taxonomy management
│ ├── Documentation.php # Post type handling
│ └── RewriteRules.php # URL routing
├── Fields/ # Admin interface
├── Sync/ # Synchronization
└── Templates/ # Frontend enhancementsPerformance Optimization
Database Queries
- Plugin activation/deactivation
- API endpoints functionality
- Taxonomy term creation
- Document sync operations
- Frontend display
- Admin interface
- Error handling
Asset Loading
- MAJOR: Breaking changes
- MINOR: New features (backward compatible)
- PATCH: Bug fixes (backward compatible)
Memory Usage
- Use
WP_Querywith proper caching - Avoid N+1 query problems
- Cache expensive operations
- Use transients for external API data
Contributing
Pull Request Process
- Fork repository
- Create feature branch
- Make changes
- Add tests if applicable
- Update documentation
- Create pull request
- Code review
- Merge
Commit Messages
php
register_rest_route(self::NAMESPACE, '/new-endpoint', [
'methods' => 'GET',
'callback' => [NewController::class, 'handle_request'],
'permission_callback' => [self::class, 'check_edit_permission'],
]);Code Review Checklist
- Conditional loading based on page type
- Minify CSS/JS in production
- Use WordPress asset versioning
Deployment
Staging Deployment
- Build production package
- Deploy to staging environment
- Test all functionality
- Verify no regressions
Production Deployment
- Backup production database
- Deploy plugin update
- Monitor error logs
- Verify functionality
- Update external systems if needed
Support
Clone repository:
- Process large datasets in chunks
- Clean up object references
- Use generators for large iterations