- Break long lines into shorter paragraphs for better readability - Simplify verbose code examples in feedback loops documentation - Update file references from .ai-workflows/ to .agents/
141 lines
4.9 KiB
Markdown
141 lines
4.9 KiB
Markdown
# Architecture Overview
|
|
|
|
This document provides an overview of the plugin's architecture, explaining the core components and how they interact.
|
|
|
|
## Directory Structure
|
|
|
|
The plugin follows a structured organization to maintain clean separation of concerns:
|
|
|
|
```
|
|
wp-plugin-starter-template/
|
|
├── admin/ # Admin-specific functionality
|
|
│ ├── css/ # Admin stylesheets
|
|
│ ├── js/ # Admin JavaScript files
|
|
│ └── lib/ # Admin PHP classes
|
|
├── assets/ # Frontend assets
|
|
│ ├── css/ # Frontend stylesheets
|
|
│ ├── js/ # Frontend JavaScript files
|
|
│ └── images/ # Images used by the plugin
|
|
├── includes/ # Core plugin functionality
|
|
│ ├── core.php # Core functionality class
|
|
│ ├── plugin.php # Main plugin class
|
|
│ └── Multisite/ # Multisite-specific functionality
|
|
├── languages/ # Translation files
|
|
├── tests/ # Test files
|
|
│ ├── e2e/ # End-to-end tests
|
|
│ └── unit/ # Unit tests
|
|
├── cypress/ # Cypress testing files
|
|
│ └── e2e/ # End-to-end test specifications
|
|
├── bin/ # Utility scripts
|
|
│ └── setup-test-env.sh # Test environment setup script
|
|
├── .github/ # GitHub-specific files
|
|
│ └── workflows/ # GitHub Actions workflows
|
|
├── .agents/ # AI workflow documentation
|
|
├── .wiki/ # Wiki documentation
|
|
│ ├── Testing-Framework.md # Testing framework documentation
|
|
│ └── Multisite-Development.md # Multisite development guide
|
|
└── wp-plugin-starter-template.php # Main plugin file
|
|
```
|
|
|
|
## Core Components
|
|
|
|
### Main Plugin File
|
|
|
|
The `wp-plugin-starter-template.php` file serves as the entry point for WordPress. It:
|
|
|
|
1. Defines plugin metadata
|
|
2. Prevents direct access
|
|
3. Defines plugin constants
|
|
4. Loads the main plugin class
|
|
5. Initializes the plugin
|
|
|
|
### Plugin Class
|
|
|
|
The `Plugin` class in `includes/plugin.php` is the main controller for the plugin. It:
|
|
|
|
1. Initializes core functionality
|
|
2. Sets up hooks and filters
|
|
3. Manages plugin activation/deactivation
|
|
4. Handles plugin updates
|
|
|
|
### Core Class
|
|
|
|
The `Core` class in `includes/core.php` contains the core functionality of the plugin. It:
|
|
|
|
1. Implements the main plugin features
|
|
2. Provides utility methods
|
|
3. Manages data processing
|
|
|
|
### Admin Class
|
|
|
|
The `Admin` class in `admin/lib/admin.php` handles all admin-specific functionality. It:
|
|
|
|
1. Creates admin menu pages
|
|
2. Registers settings
|
|
3. Enqueues admin assets
|
|
4. Processes admin form submissions
|
|
|
|
### Multisite Support
|
|
|
|
The `Multisite` class in `includes/Multisite/class-multisite.php` provides a foundation for multisite functionality.
|
|
|
|
It:
|
|
|
|
1. Serves as a placeholder for multisite features
|
|
2. Can be extended for custom multisite functionality
|
|
3. Provides examples of multisite-specific methods
|
|
|
|
## Object-Oriented Approach
|
|
|
|
The plugin follows object-oriented programming principles:
|
|
|
|
1. **Encapsulation**: Each class encapsulates its own functionality
|
|
2. **Inheritance**: Classes can extend others to inherit functionality
|
|
3. **Namespaces**: PHP namespaces are used to avoid conflicts
|
|
4. **Autoloading**: PSR-4 autoloading for efficient class loading
|
|
|
|
## Hook System
|
|
|
|
The plugin integrates with WordPress through its hook system:
|
|
|
|
1. **Actions**: Used to add functionality at specific points
|
|
2. **Filters**: Used to modify data before it's used by WordPress
|
|
|
|
## Data Flow
|
|
|
|
1. WordPress loads the main plugin file
|
|
2. The Plugin class is instantiated
|
|
3. The Plugin class initializes the Core class
|
|
4. The Plugin class initializes the Admin class (in admin context)
|
|
5. WordPress hooks trigger plugin functionality as needed
|
|
|
|
## Extensibility
|
|
|
|
The plugin is designed to be extensible:
|
|
|
|
1. **Filters**: Key data points can be modified via filters
|
|
2. **Actions**: Additional functionality can be added via actions
|
|
3. **Class Structure**: Classes can be extended to add or modify functionality
|
|
|
|
## Testing
|
|
|
|
The plugin includes a comprehensive testing framework:
|
|
|
|
1. **Unit Tests**: For testing individual components
|
|
2. **End-to-End Tests**: For testing the plugin as a whole
|
|
3. **WordPress Environment**: Using wp-env for local testing
|
|
4. **Multisite Testing**: Support for testing in multisite environments
|
|
5. **Continuous Integration**: Automated tests via GitHub Actions
|
|
|
|
## Conclusion
|
|
|
|
This architecture provides a solid foundation for WordPress plugin development.
|
|
|
|
It follows best practices and modern coding standards.
|
|
|
|
It's designed to be maintainable, extensible, and easy to understand.
|
|
|
|
For testing framework details, see [Testing Framework](Testing-Framework.md).
|
|
|
|
For multisite development, refer to [Multisite Development](Multisite-Development.md).
|