Skip to content

Latest commit

 

History

History
174 lines (125 loc) · 2.89 KB

File metadata and controls

174 lines (125 loc) · 2.89 KB

Developer Documentation

Architecture

The plugin follows a modern PHP architecture with the following components:

  • Core: Base functionality and plugin lifecycle
  • Services: Reusable business logic
  • Models: Database interaction and data structures
  • Admin: WordPress admin interface components
  • API: REST API endpoints and handlers

Directory Structure

custom-plugin/
├── assets/
│   ├── css/
│   ├── js/
│   └── vendor/
├── config/
│   ├── app.php
│   └── database.php
├── docs/
├── languages/
├── src/
│   ├── Admin/
│   ├── Api/
│   ├── Core/
│   ├── Database/
│   ├── Models/
│   └── Services/
├── templates/
│   ├── admin/
│   ├── components/
│   └── layouts/
├── composer.json
└── custom-plugin.php

Development Setup

  1. Clone the repository
  2. Install dependencies:
composer install
  1. Set up development environment:
composer run-script dev-setup

Coding Standards

The plugin follows WordPress Coding Standards with some modern PHP practices:

  • PSR-4 autoloading
  • PHP 7.4+ features
  • WordPress coding style for templates
  • ESLint for JavaScript
  • SCSS for stylesheets

Code Style

namespace CustomPlugin\Feature;

class FeatureClass {
    private string $property;
    
    public function doSomething(): void {
        // Implementation
    }
}

Adding Features

New Service

  1. Create service class in src/Services/
  2. Register in Plugin class
  3. Add configuration if needed
  4. Write tests

New API Endpoint

  1. Create endpoint class in src/Api/
  2. Register routes in RestApi class
  3. Add documentation
  4. Write tests

New Admin Page

  1. Create page class in src/Admin/
  2. Add templates in templates/admin/
  3. Register in AdminInterface
  4. Add assets if needed

Testing

Unit Tests

composer test

Integration Tests

composer test-integration

WordPress Tests

composer test-wordpress

Building

Development Build

composer build-dev

Production Build

composer build

Hooks

Actions

  • custom_plugin_init: Fired when plugin initializes
  • custom_plugin_loaded: Fired after all components are loaded
  • custom_plugin_admin_init: Fired when admin interface initializes

Filters

  • custom_plugin_settings: Modify plugin settings
  • custom_plugin_api_response: Modify API responses
  • custom_plugin_cache_ttl: Modify cache duration

Database

Migrations

Create new migration:

composer create-migration "AddNewTable"

Models

Create new model:

composer create-model "CustomModel"

Contributing

  1. Fork the repository
  2. Create feature branch
  3. Write tests
  4. Submit pull request

See CONTRIBUTING.md for detailed guidelines.