Skip to main content

🔄 Development Workflow

This guide outlines the development workflow for WP LLM contributors and advanced users. It covers best practices, development processes, and how to effectively contribute to the project.

🎯 Development Philosophy

Core Principles

  1. WordPress-First Approach - All generated code must follow WordPress standards
  2. Security by Design - Security considerations are built into every component
  3. Performance Optimization - Code should be efficient and scalable
  4. Accessibility - Generated interfaces must be accessible to all users
  5. Documentation - Comprehensive documentation for all features

Quality Standards

  • WordPress Coding Standards - Follow PSR-12 and WordPress-specific guidelines
  • Security Best Practices - Proper sanitization, validation, and nonce verification
  • Performance Guidelines - Efficient queries, caching, and asset optimization
  • Accessibility Standards - WCAG 2.1 AA compliance for frontend components

🛠️ Development Environment Setup

Required Tools

  1. Ollama - For running WP LLM locally
  2. WordPress Development Environment - LocalWP, XAMPP, or similar
  3. Code Editor - VS Code with WordPress extensions
  4. Git - Version control
  5. Node.js - For block development and build tools

Local Development Setup

bash
# Clone the repository
git clone https://github.com/artificialpoets/wp-llm-docs.git
cd wp-llm

# Install dependencies
npm install

# Set up WordPress development environment
# (Follow your preferred local development setup)

# Start Ollama with WP LLM
ollama serve
ollama pull wp-llm

VS Code Configuration

Recommended Extensions:

  • WordPress Snippets
  • PHP Intelephense
  • Ollama
  • GitLens
  • Prettier

Settings:

json
{
  "php.validate.executablePath": "/usr/bin/php",
  "php.suggest.basic": false,
  "wordpress.suggest.basic": true,
  "ollama.model": "wp-llm",
  "ollama.host": "http://localhost:11434"
}

🔄 Development Process

1. Planning Phase

Define Requirements:

  • Clear specification of what needs to be built
  • User stories and acceptance criteria
  • Technical constraints and considerations

Example Planning Template:

Feature: Custom Post Type Generator
- User Story: As a developer, I want to generate custom post types with meta fields
- Acceptance Criteria:
  * Generates proper post type registration
  * Includes meta boxes for custom fields
  * Follows WordPress coding standards
  * Includes proper sanitization
- Technical Considerations:
  * REST API support
  * Admin columns
  * Custom taxonomies

2. Development Phase

Using WP LLM for Development:

  1. Start with a Clear Prompt:

    bash
    ollama run wp-llm "Create a custom post type for 'Products' with the following requirements:
    - Must support: title, editor, thumbnail, excerpt, custom-fields
    - Include meta fields: price (number), sku (text), stock_status (select)
    - Add proper sanitization and validation
    - Follow WordPress coding standards
    - Include REST API support"
    
  2. Review and Refine:

    • Check generated code for accuracy
    • Verify security measures
    • Test functionality
    • Optimize performance
  3. Iterate and Improve:

    bash
    ollama run wp-llm "Improve this custom post type code by adding:
    - Admin columns for price and stock status
    - Better error handling
    - Additional meta field validation"
    

3. Testing Phase

Code Review Checklist:

  • WordPress coding standards compliance
  • Security measures implemented
  • Performance considerations
  • Accessibility features
  • Error handling
  • Documentation

Testing Procedures:

bash
# Test in WordPress environment
# 1. Activate plugin/theme
# 2. Test functionality
# 3. Check for errors
# 4. Validate security
# 5. Performance testing

4. Documentation Phase

Documentation Requirements:

  • Code comments and inline documentation
  • README updates
  • API documentation
  • Usage examples
  • Changelog entries

🎨 Block Development Workflow

Block Creation Process

  1. Define Block Requirements:

    json
    {
      "name": "my-theme/hero-section",
      "title": "Hero Section",
      "category": "design",
      "attributes": {
        "title": { "type": "string" },
        "backgroundImage": { "type": "object" },
        "buttonText": { "type": "string" }
      }
    }
    
  2. Generate Block Structure:

    bash
    ollama run wp-llm "Create a Gutenberg block for 'hero-section' with:
    - Background image support
    - Editable title and subtitle
    - Call-to-action button
    - Responsive design
    - Accessibility features"
    
  3. Implement Block Files:

    • block.json - Block configuration
    • edit.js - Editor component
    • save.js - Frontend render
    • style.css - Styling
    • index.js - Block registration
  4. Test and Refine:

    • Test in block editor
    • Verify frontend rendering
    • Check responsive behavior
    • Validate accessibility

Block Pattern Development

  1. Define Pattern Structure:

    php
    register_block_pattern(
        'my-theme/hero-pattern',
        array(
            'title' => __('Hero Section', 'my-theme'),
            'description' => __('A hero section with background image and call-to-action', 'my-theme'),
            'categories' => array('hero'),
            'content' => '<!-- wp:my-theme/hero-section -->...',
        )
    );
    
  2. Generate Pattern Content:

    bash
    ollama run wp-llm "Create a block pattern for a hero section that includes:
    - Hero block with background image
    - Heading and subtitle
    - Call-to-action button
    - Proper spacing and layout"
    

🔌 Plugin Development Workflow

Plugin Structure

my-plugin/
├── my-plugin.php          # Main plugin file
├── includes/              # PHP classes and functions
│   ├── class-plugin.php
│   ├── class-admin.php
│   └── class-api.php
├── admin/                 # Admin interface
│   ├── css/
│   ├── js/
│   └── views/
├── public/                # Frontend assets
│   ├── css/
│   ├── js/
│   └── views/
├── languages/             # Translation files
├── assets/                # Build assets
└── tests/                 # Unit tests

Development Steps

  1. Generate Plugin Foundation:

    bash
    ollama run wp-llm "Create a WordPress plugin structure for 'Product Manager' with:
    - Custom post type for products
    - Meta boxes for product details
    - REST API endpoints
    - Admin interface
    - Proper file organization"
    
  2. Implement Core Features:

    • Custom post type registration
    • Meta box implementation
    • REST API endpoints
    • Admin interface
  3. Add Advanced Features:

    • Custom taxonomies
    • Admin columns
    • Import/export functionality
    • Settings page
  4. Testing and Optimization:

    • Unit tests
    • Integration tests
    • Performance optimization
    • Security audit

🎯 Theme Development Workflow

Theme Structure

my-theme/
├── style.css              # Theme information
├── index.php              # Main template
├── functions.php          # Theme functions
├── header.php             # Header template
├── footer.php             # Footer template
├── sidebar.php            # Sidebar template
├── single.php             # Single post template
├── page.php               # Page template
├── archive.php            # Archive template
├── search.php             # Search template
├── 404.php                # 404 error template
├── assets/                # Theme assets
│   ├── css/
│   ├── js/
│   └── images/
├── template-parts/        # Template parts
├── inc/                   # Include files
└── languages/             # Translation files

Development Process

  1. Generate Theme Foundation:

    bash
    ollama run wp-llm "Create a WordPress theme structure with:
    - Proper template hierarchy
    - Theme functions and hooks
    - Responsive design
    - SEO optimization
    - Accessibility features"
    
  2. Implement Templates:

    • Main template files
    • Template parts
    • Custom post type templates
    • Archive templates
  3. Add Functionality:

    • Custom widgets
    • Shortcodes
    • Customizer options
    • Theme hooks
  4. Optimization:

    • Performance optimization
    • SEO improvements
    • Accessibility enhancements
    • Cross-browser testing

🔒 Security Development Workflow

Security Checklist

Input Validation:

  • Sanitize all user inputs
  • Validate data types and formats
  • Check for malicious content
  • Implement proper escaping

Authentication & Authorization:

  • Verify user capabilities
  • Implement nonce verification
  • Check user permissions
  • Secure admin interfaces

Database Security:

  • Use prepared statements
  • Validate SQL queries
  • Implement proper escaping
  • Check for SQL injection

File Security:

  • Validate file uploads
  • Check file types and sizes
  • Secure file storage
  • Implement access controls

Security Testing

bash
# Test for common vulnerabilities
# 1. SQL injection testing
# 2. XSS vulnerability testing
# 3. CSRF protection testing
# 4. File upload security testing
# 5. Authentication bypass testing

📊 Performance Development Workflow

Performance Optimization

Database Optimization:

  • Use efficient queries
  • Implement proper indexing
  • Optimize meta queries
  • Use object caching

Asset Optimization:

  • Minify CSS and JavaScript
  • Optimize images
  • Implement lazy loading
  • Use CDN for assets

Caching Strategy:

  • Object caching
  • Page caching
  • Fragment caching
  • Transient API usage

Performance Testing

bash
# Performance testing tools
# 1. Query Monitor (WordPress plugin)
# 2. GTmetrix
# 3. Google PageSpeed Insights
# 4. WebPageTest

🔄 Continuous Integration

CI/CD Pipeline

yaml
# .github/workflows/ci.yml
name: CI/CD Pipeline

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
      - name: Install dependencies
        run: composer install
      - name: Run tests
        run: vendor/bin/phpunit
      - name: Code quality check
        run: vendor/bin/phpcs

Automated Testing

Unit Tests:

php
class TestCustomPostType extends WP_UnitTestCase {
    public function test_post_type_registration() {
        // Test post type registration
        $post_types = get_post_types();
        $this->assertArrayHasKey('product', $post_types);
    }
}

Integration Tests:

php
class TestRESTAPI extends WP_Test_REST_TestCase {
    public function test_get_products_endpoint() {
        // Test REST API endpoint
        $request = new WP_REST_Request('GET', '/wp-json/product-manager/v1/products');
        $response = rest_do_request($request);
        $this->assertEquals(200, $response->get_status());
    }
}

📝 Documentation Workflow

Documentation Standards

Code Documentation:

  • PHPDoc comments for functions
  • Inline comments for complex logic
  • README files for projects
  • API documentation

User Documentation:

  • Installation guides
  • Usage examples
  • Troubleshooting guides
  • FAQ sections

Documentation Process

  1. Write documentation alongside code
  2. Include usage examples
  3. Add troubleshooting sections
  4. Keep documentation updated
  5. Review and refine regularly

🚀 Deployment Workflow

Production Deployment

  1. Code Review:

    • Security audit
    • Performance review
    • Accessibility check
    • Cross-browser testing
  2. Testing:

    • Staging environment testing
    • User acceptance testing
    • Performance testing
    • Security testing
  3. Deployment:

    • Backup production environment
    • Deploy to production
    • Monitor for issues
    • Rollback if necessary

Deployment Checklist

  • Code review completed
  • Tests passing
  • Security audit passed
  • Performance benchmarks met
  • Documentation updated
  • Backup created
  • Deployment plan ready
  • Rollback plan prepared

Ready to contribute? Follow this development workflow to ensure high-quality, secure, and performant WordPress code that follows best practices and standards.