Development Guide

This guide covers development workflows, build processes, and coding standards for the DocSync plugin.

Development Environment

Local Setup

  1. Clone repository:

    bash
    git clone https://github.com/chubes4/docsync.git
    cd docsync
    
  2. Install dependencies:

    bash
    composer install
    
  3. WordPress setup:

    • Use testing-grounds.local (multisite WordPress installation)
    • Activate the Chubes theme
    • Activate the DocSync plugin

Development Workflow

Code Changes

  1. Create feature branch from main
  2. Make changes following coding standards
  3. Test changes locally
  4. Run build process
  5. 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 docsync

Coding 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 install

API Development

Adding New Endpoints

  1. Define route in Routes.php:

    php
    register_rest_route(self::NAMESPACE, '/new-endpoint', [
        'methods' => 'GET',
        'callback' => [NewController::class, 'handle_request'],
        'permission_callback' => [self::class, 'check_edit_permission'],
    ]);
    
  2. Create controller method:

    php
    class NewController {
        public static function handle_request(WP_REST_Request $request): WP_REST_Response|WP_Error {
            // Implementation
            return rest_ensure_response($data);
        }
    }
    
  3. Add route registration:

    php
    private static function register_new_routes(): void {
        // Route definitions
    }
    

Parameter Validation

bash
git clone https://github.com/chubes4/docsync.git
cd docsync

Database Operations

Post Meta

bash
composer install

Taxonomy 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

  1. Update version in composer.json
  2. Update CHANGELOG.md
  3. Create git tag
  4. Run production build
  5. Test production package
  6. 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 enhancements

API 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 enhancements

Performance 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_Query with proper caching
  • Avoid N+1 query problems
  • Cache expensive operations
  • Use transients for external API data

Contributing

Pull Request Process

  1. Fork repository
  2. Create feature branch
  3. Make changes
  4. Add tests if applicable
  5. Update documentation
  6. Create pull request
  7. Code review
  8. 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

  1. Build production package
  2. Deploy to staging environment
  3. Test all functionality
  4. Verify no regressions

Production Deployment

  1. Backup production database
  2. Deploy plugin update
  3. Monitor error logs
  4. Verify functionality
  5. Update external systems if needed

Support

Clone repository:

  • Process large datasets in chunks
  • Clean up object references
  • Use generators for large iterations