Structure
Folder and file structure
Base Structure
plugin.php
uninstall.php
wordpress-plugin-boilerplate.php
Detailed Explanation
Root Directory
The root directory contains the main plugin files:
plugin.php
: Initializes the plugin and includes necessary files.uninstall.php
: Contains code that runs when the plugin is uninstalled.wordpress-plugin-boilerplate.php
: The primary plugin file that WordPress uses to identify and load the plugin.
Config
The config
directory stores configuration files:
plugin.php
: Contains plugin-wide configuration settings and constants.
Database
The database
directory manages database-related operations:
- Migrations: Contains files for creating and modifying database tables.
- Seeders: Includes files for populating the database with initial data.
Includes
The includes
directory contains the core functionality of the plugin:
- Admin: Handles admin-specific functionality.
- Controllers: Contains classes for handling various plugin actions.
- Core: Houses core plugin classes and functionality.
- Frontend: Manages frontend-specific functionality and display.
- Interfaces: Defines interfaces used throughout the plugin.
- Models: Contains classes for interacting with the database.
- Routes: Manages custom routes and endpoints for the plugin.
- Traits: Stores reusable trait files.
functions.php
: Contains utility functions used throughout the plugin.
JavaScript (src)
The src
directory manages the JavaScript and React components:
- admin: Contains the source files for the React application.
- components: Reusable React components.
- pages: React components for specific pages or views.
- lib: Utility functions and helper libraries.
- types: TypeScript type definitions (if using TypeScript).
App.jsx
: The main React application component.main.jsx
: The entry point for the React application.index.css
: Global CSS styles.router.jsx
: Manages routing for the React application.
Additional Directories
- libs: Contains third-party libraries or custom libraries.
- views: Stores template files for rendering HTML output.
- vendor: Managed by Composer, contains third-party dependencies.
This structure provides a solid foundation for building scalable and maintainable WordPress plugins, following modern development practices and separation of concerns.