Prerequisites {#prerequisites}
Before you begin developing for MainWP, ensure you have:
- PHP 7.4 or higher
- WordPress 5.6 or higher
- MainWP Dashboard plugin installed
- A code editor (we recommend VS Code)
- Basic knowledge of PHP and WordPress development
Environment Setup {#environment-setup}
- Set up a local WordPress development environment:
# Using Local by Flywheel or similar tool
local-by-flywheel create-site mainwp-dev
- Install required development tools:
# Install Composer globally
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Install Node.js and npm (optional, for build tools)
brew install node
MainWP Installation {#mainwp-installation}
-
Install the MainWP Dashboard plugin:
- Download from MainWP.com
- Upload and activate in WordPress
- Complete the setup wizard
-
Install MainWP Child plugin on test sites:
- Download the Child plugin
- Install on your test WordPress sites
- Connect sites to your dashboard
Creating Your First Extension {#create-extension}
Start with this basic extension structure:
<?php
/*
Plugin Name: My MainWP Extension
Plugin URI: https://yourwebsite.com/mainwp-extension
Description: Description of your extension
Version: 1.0
Author: Your Name
Author URI: https://yourwebsite.com
Documentation URI: https://yourwebsite.com/docs
*/
class My_MainWP_Extension {
public function __construct() {
add_action('init', array($this, 'init'));
}
public function init() {
// Your initialization code here
}
}
new My_MainWP_Extension();
Extension Structure {#basic-structure}
A typical MainWP extension includes:
- Main plugin file
- Admin interface files
- API handlers
- Helper classes
- Assets (CSS/JS)
Example directory structure:
my-mainwp-extension/
├── includes/
│ ├── class-admin.php
│ ├── class-api.php
│ └── class-helpers.php
├── assets/
│ ├── css/
│ └── js/
└── my-mainwp-extension.php
Testing Your Extension {#testing}
-
Local Testing
- Activate your extension on your development site
- Test all features thoroughly
- Check for conflicts with other extensions
-
Debug Mode
define('MAINWP_DEBUG', true); -
Common Test Cases
- Extension activation/deactivation
- Settings saving/loading
- API interactions
- User interface elements
- Error handling
-
Testing with Multiple Child Sites
- Test with various WordPress versions
- Test with different server configurations
- Verify performance with many connected sites
Remember to always follow MainWP's coding standards and best practices when developing your extension. For more detailed information, check out our Extension Development Guide.
这篇文档对你有帮助吗?
谢谢你的反馈!