### MainWP Extension Development Example
Source: https://mainwp.dev/getting-started
This PHP code snippet illustrates the fundamental structure for creating a MainWP extension. It demonstrates how to register the extension using `mainwp_getextensions` filter, check for MainWP activation status, and define callback functions for extension settings and initialization. It also shows how to use `mainwp_activated_check` and `mainwp_extension_enabled_check` filters.
```php
__FILE__, 'callback' => 'my_plugin_extension_settings');
return $extensions;
}
function my_plugin_extension_settings() {
do_action( 'mainwp_pageheader_extensions', __FILE__ );
echo 'Your custom settings page';
do_action( 'mainwp_pagefooter_extensions', __FILE__ );
}
function activate_this_plugin() {
global $childEnabled;
$childEnabled = apply_filters('mainwp_extension_enabled_check', __FILE__);
if ( ! $childEnabled ) return;
$childKey = $childEnabled['key'];
//Code to initialize your plugin
}
?>
```
--------------------------------
### MainWP REST API Reference
Source: https://mainwp.dev/getting-started
This entry provides a link to the MainWP REST API documentation hosted on Postman. It serves as a reference for developers looking to interact with MainWP programmatically.
```APIDOC
REST API Documentation:
URL: https://www.postman.com/mainwp/workspace/mainwp/collection/25047126-5ed97ddf-1d45-4bd1-bede-1a1f3b7584ef
Description: Provides access to MainWP functionalities via a RESTful API, allowing for programmatic control and integration.
```
--------------------------------
### MainWP Add-on Development Setup
Source: https://mainwp.dev/docs/category/mainwp-affiliates
Guide for setting up a development environment for creating MainWP add-ons. Covers essential steps for beginners.
```markdown
## Lesson 1: Setting Up a MainWP Development Environment
This guide will walk you through the initial steps to prepare your system for MainWP add-on development.
**Prerequisites:**
* A working WordPress installation.
* Basic understanding of PHP, HTML, CSS, and JavaScript.
**Steps:**
1. **Install MainWP:** Ensure you have MainWP installed and configured on a WordPress site.
2. **Set up a Local Development Environment:** Use tools like LocalWP, XAMPP, or MAMP for local development.
3. **Install a Code Editor:** Recommended editors include VS Code, Sublime Text, or Atom.
4. **Understand the MainWP Plugin Structure:** Familiarize yourself with the core plugin files and directories.
**Further Resources:**
* [MainWP Developers](https://mainwp.dev/)
* [Contributing to MainWP](https://github.com/mainwp/mainwp/blob/master/.github/CONTRIBUTING.md)
```
--------------------------------
### Initialize Extension with MainWP
Source: https://mainwp.dev/getting-started
This code snippet shows how to initialize your extension when MainWP is initialized. It includes a check using the `mainwp_extension_enabled_check` hook to ensure your specific extension is enabled before proceeding with its functionality.
```php
add_action( 'mainwp_init', 'my_extension_init' );
function my_extension_init() {
$is_enabled = apply_filters( 'mainwp_extension_enabled_check', false, 'my-extension-slug' );
if ( $is_enabled ) {
// Extension is enabled, proceed with initialization
// $extension_key = $is_enabled['key']; // Get the key for data requests
} else {
// Extension is not enabled, do nothing or handle accordingly
}
}
```
--------------------------------
### Add MainWP Extension (Custom Name/Icon)
Source: https://mainwp.dev/getting-started
Adds a custom extension to MainWP with a specified name and icon. This allows for greater customization of how the extension appears in the MainWP dashboard.
```php
__FILE__,
'callback' => 'my_plugin_extension_settings',
'apiManager' => false,
'name' => 'Custom Extension Name',
'icon' => 'custom icon path',
);
return $extensions;
}
function my_plugin_extension_settings() {
do_action( 'mainwp_pageheader_extensions', __FILE__) ;
echo 'Your custom settings page';
do_action( 'mainwp_pagefooter_extensions', __FILE__ );
}
?>
```
--------------------------------
### MainWP Add-on Development Setup
Source: https://mainwp.dev/contact
Guide to setting up your development environment for creating MainWP add-ons. Covers essential steps and prerequisites.
```php
```
--------------------------------
### Add MainWP Extension (With Auth)
Source: https://mainwp.dev/getting-started
Adds a custom extension to MainWP that requires authentication. The 'apiManager' parameter is set to true to enable this.
```php
__FILE__,
'callback' => 'my_plugin_extension_settings',
'apiManager' => true,
);
return $extensions;
}
function my_plugin_extension_settings() {
do_action( 'mainwp_pageheader_extensions', __FILE__) ;
echo 'Your custom settings page';
do_action( 'mainwp_pagefooter_extensions', __FILE__ );
}
?>
```
--------------------------------
### Add MainWP Extension (No Auth)
Source: https://mainwp.dev/getting-started
Adds a custom extension to MainWP without requiring authentication. The extension is registered with a callback function and a boolean for apiManager.
```php
__FILE__,
'callback' => 'my_plugin_extension_settings',
'apiManager' => false,
);
return $extensions;
}
function my_plugin_extension_settings() {
do_action( 'mainwp_pageheader_extensions', __FILE__) ;
echo 'Your custom settings page';
do_action( 'mainwp_pagefooter_extensions', __FILE__ );
}
?>
```
--------------------------------
### MainWP Add-on Development Guide
Source: https://mainwp.dev/docs/category/customization
A guide for developers on how to create add-ons for MainWP. This includes setting up a development environment.
```en
Add-on Development Guide:
URL: https://mainwp.dev/lesson-1-setting-up-a-mainwp-development-environment/
Content: Guide to setting up a MainWP development environment for creating add-ons.
```
--------------------------------
### MainWP Overview and Installation Hooks
Source: https://mainwp.dev/hooks
These hooks relate to the MainWP Overview page, allowing customization of enabled widgets and the addition of metaboxes. They also cover preparation for bulk installation uploads and adding support for additional installation data.
```APIDOC
mainwp_overview_enabled_widgets:
description: Contains the list of enabled widgets and allows filtering them for the Overview page.
parameters: []
returns: array (enabled widgets)
mainwp_getmetaboxes:
description: Adds metaboxes (widgets) to the Overview page.
parameters: []
returns: array (metaboxes)
mainwp_installbulk_prepareupload:
description: Prepares upload URLs for the bulk install process.
parameters: []
returns: array (upload URLs)
mainwp_perform_install_data:
description: Adds support for additional data such as custom fields during the installation process.
parameters: []
returns: mixed (additional data)
```
--------------------------------
### MainWP Add-on Development Guide
Source: https://mainwp.dev/docs/category/faqs
This guide covers the initial steps for developing add-ons for MainWP. It focuses on setting up the development environment to begin creating custom functionalities.
```php
Add-on Development Guide:
Topic: Setting up a MainWP development environment.
Prerequisites:
- Basic understanding of PHP and WordPress development.
- A local development environment (e.g., LocalWP, MAMP, XAMPP).
Steps:
1. Install MainWP on your local environment.
2. Set up a child site for testing.
3. Understand the MainWP plugin structure.
4. Learn about MainWP hooks and filters for customization.
Resources:
- [Add-on Development Guide](https://mainwp.dev/lesson-1-setting-up-a-mainwp-development-environment/)
- [MainWP Hooks](https://mainwp.dev/hooks)
```
--------------------------------
### MainWP Add-on Development Guide
Source: https://mainwp.dev/docs/category/miscellaneous
Guides for developing add-ons for MainWP. Covers setting up a development environment and understanding the core concepts for creating custom functionality.
```en
Add-on Development Guide:
- Lesson 1: Setting up a MainWP development environment.
- Learn how to create custom add-ons to extend MainWP's functionality.
- Resources available at: https://mainwp.dev/lesson-1-setting-up-a-mainwp-development-environment/
```
--------------------------------
### Check MainWP Dashboard Activation
Source: https://mainwp.dev/getting-started
This snippet demonstrates how to check if the MainWP Dashboard plugin is active. It utilizes the `mainwp_activated_check` filter for an initial check and the `mainwp_activated` action as a fallback, ensuring reliable activation status detection.
```php
add_filter( 'mainwp_activated_check', 'my_extension_check_mainwp_activated' );
function my_extension_check_mainwp_activated( $is_mainwp_activated ) {
if ( $is_mainwp_activated ) {
return true;
}
// Fallback check using action
add_action( 'mainwp_activated', 'my_extension_mainwp_activated_action' );
return false;
}
function my_extension_mainwp_activated_action() {
// MainWP is activated, perform necessary actions
}
```
--------------------------------
### MainWP Development Add-on Framework Download
Source: https://mainwp.dev/lesson-2-creating-basic-mainwp-extension
Provides a starting point for MainWP add-on development with a pre-defined structure. Download the framework to begin creating your custom functionality.
```link
https://github.com/mainwp/mainwp-development-extension
```
--------------------------------
### MainWP Plugin/Theme Install Hooks
Source: https://mainwp.dev/hooks
Hooks that fire before and after plugin/theme installation.
```APIDOC
mainwp_before_plugin_theme_install($post_data: array): Fires before plugin/theme install. Parameters: $post_data (array).
mainwp_after_plugin_theme_install($output: mixed): Fires after plugin/theme install. Parameters: $output (mixed).
```
--------------------------------
### MainWP before_plugin_theme_install Hook Example
Source: https://mainwp.dev/hooks/mainwp_before_plugin_theme_install
This code snippet demonstrates how to use the `mainwp_before_plugin_theme_install` action hook in MainWP. It shows how to register a custom function that receives plugin/theme data and child site information before the installation process begins.
```php
add_action( 'mainwp_before_plugin_theme_install', 'your_custom_function_name' );
function your_custom_function_name( $post_data, $websites ) {
// Your code to execute before plugin/theme installation
// $post_data: Array containing the post data.
// $websites: Object containing the child sites data.
}
```
--------------------------------
### Install MainWP Dashboard Plugin
Source: https://mainwp.dev/lesson-1-setting-up-a-mainwp-development-environment
Steps to download and install the MainWP Dashboard plugin on a local WordPress site. This involves obtaining the plugin from the MainWP website and uploading it via the WordPress admin panel.
```php
1. Download MainWP Dashboard Plugin: Visit the MainWP website (https://mainwp.com/install-mainwp/) and download the MainWP Dashboard plugin. You can download it from the “Downloads” section after creating an account.
2. Install MainWP Dashboard Plugin: Log in to your WordPress dashboard for your Laragon project. Go to Plugins > Add New and upload the MainWP Dashboard plugin that you downloaded in the previous step. Activate the plugin once it’s uploaded & follow the on screen prompts to finish installing the MainWP Dashboard onto the WordPress Installation we created above.
```
--------------------------------
### Install and Connect MainWP Child Plugin
Source: https://mainwp.dev/lesson-1-setting-up-a-mainwp-development-environment
Instructions for installing the MainWP Child plugin on individual WordPress sites and connecting them to the MainWP Dashboard. This ensures that remote sites can be managed by the MainWP Dashboard.
```wordpress
3. Install MainWP Child Plugin: Now, you need to install the MainWP Child plugin on each of the WordPress sites you want to manage using MainWP. You can download the MainWP Child plugin from the WordPress plugin repository. Install and activate the MainWP Child plugin on each site.
4. Connect Child Sites to MainWP Dashboard: Once the MainWP Child plugin is activated on each site, go to the MainWP Dashboard (accessible via the WordPress admin menu) and navigate to Sites > Add New. Enter the URL and login credentials for each child site you want to connect to the MainWP Dashboard.
```
--------------------------------
### MainWP Development DB Install Method
Source: https://mainwp.dev/lesson-3-the-mainwp-development-extension-database
Handles the installation of the database tables required for the MainWP development add-on. It checks the current database version, creates the necessary tables using `dbDelta`, and updates the stored version number. This method is typically called during add-on activation.
```php
db_version, '>=' ) ) {
return;
}
$charset_collate = $wpdb->get_charset_collate();
$sql = array();
$table_name = $this->table_name('development'); // Assuming 'development' is the table suffix
$tbl = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url varchar(55) DEFAULT '' NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
$sql[] = $tbl;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
foreach ( $sql as $query ) {
dbDelta( $query );
}
update_option('mainwp_pressable_db_version', $this->db_version );
$this->check_update( $currentVersion ); // Assuming check_update method exists
}
?>
```
--------------------------------
### MainWP Add-on Development Lessons Overview
Source: https://mainwp.dev/lesson-8-packaging-and-distributing-your-extension
This section provides a structured overview of the MainWP Add-on Development Guide, linking to various lessons that cover specific aspects of creating and managing MainWP add-ons. It serves as a roadmap for developers.
```html
Lesson 1 – Setting up a MainWP Development Environment
Lesson 2 – Creating a Basic MainWP Add-on
Lesson 3 - The MainWP Development Add-on
Lesson 3 - Main File
Lesson 3 - Admin Class
Lesson 3 - Database Class
Lesson 3 - Utility Class
Lesson 3 - Overview Class
Lesson 3 - Individual Class
Lesson 3 - Ajax Class
Lesson 3 - Widget Class
Lesson 4 – Building intuitive admin interfaces for MainWP Add-ons
Lesson 5 – Storing and retrieving data with a WordPress Plugin
Lesson 6 – How to use MainWP Actions & Filters
Lesson 7 – Debugging common issues in MainWP Add-ons
Lesson 8 – Packaging and distributing your Add-on
Lesson 9 – Writing Clean & Maintainable MainWP Code: Best Practices
```
--------------------------------
### MainWP Add-on Packaging and Distribution
Source: https://mainwp.dev/lesson-8-packaging-and-distributing-your-extension
This section details the essential steps for preparing, packaging, and distributing a MainWP add-on. It covers aspects like versioning, documentation, licensing, and marketplace listing.
```html
Prepare Your Add-on
Package Your Add-on
Versioning
Documentation
Licensing
Distribution Platforms
MainWP Marketplace Listing Details
Promotion
Support and Updates
Feedback and Iteration
```
--------------------------------
### MainWP Install Plugin Card Bottom Hook Example
Source: https://mainwp.dev/hooks/mainwp_install_plugin_card_bottom
This code snippet demonstrates how to use the 'mainwp_install_plugin_card_bottom' hook to add custom functionality to the plugin card on the Install Plugins page. It includes the action to hook into and a sample function that receives plugin data.
```php
add_action( 'mainwp_install_plugin_card_bottom', 'your_custom_function_name' );
function your_custom_function_name( $plugin ) {
// Your code
}
```
--------------------------------
### MainWP Add-on Development - Packaging and Distribution
Source: https://mainwp.dev/lesson-4-building-intuitive-admin-interfaces-for-mainwp-extensions
This snippet covers the process of packaging and distributing MainWP add-ons. It outlines the necessary steps to prepare your add-on for release, including creating a zip file and providing necessary documentation.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```
--------------------------------
### Usage Example for mainwp_install_themes_actions_bar_left
Source: https://mainwp.dev/hooks/mainwp_install_themes_actions_bar_left
This code snippet demonstrates how to hook into the 'mainwp_install_themes_actions_bar_left' action. It allows you to add custom functionality to the left side of the actions bar on the MainWP Install Themes screen.
```php
add_action( 'mainwp_install_themes_actions_bar_left', 'your_custom_function_name' );
function your_custom_function_name() {
// Your code
}
```
--------------------------------
### Usage Example for mainwp_install_plugin_card_top
Source: https://mainwp.dev/hooks/mainwp_install_plugin_card_top
This code snippet demonstrates how to use the 'mainwp_install_plugin_card_top' hook by adding a custom function to it. This hook is triggered on the Install Plugins page in MainWP, specifically at the top of the plugin card.
```php
add_action( 'mainwp_install_plugin_card_top', 'your_custom_function_name' );
function your_custom_function_name() {
// Your code
}
```
--------------------------------
### Usage Example for mainwp_after_system_requirements_check
Source: https://mainwp.dev/hooks/mainwp_after_system_requirements_check
Demonstrates how to hook into the mainwp_after_system_requirements_check action to execute custom PHP code. This is typically used to add or modify content on the System Requirements page within the MainWP Quick Setup Wizard.
```php
add_action( 'mainwp_after_system_requirements_check', 'your_custom_function_name' );
function your_custom_function_name() {
// Your custom code here
}
```
--------------------------------
### MainWP Add-on Development - Packaging and Distribution
Source: https://mainwp.dev/lesson-3-mainwp-development-extension
This snippet covers the process of packaging and distributing MainWP add-ons. It outlines the necessary steps to prepare your add-on for release, including creating a zip file and providing necessary documentation.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```
--------------------------------
### MainWP Add-on Development - Packaging and Distribution
Source: https://mainwp.dev/lesson-2-creating-basic-mainwp-extension
This snippet covers the process of packaging and distributing MainWP add-ons. It outlines the necessary steps to prepare your add-on for release, including creating a zip file and providing necessary documentation.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```
--------------------------------
### MainWP Add-on Development - Packaging and Distribution
Source: https://mainwp.dev/lesson-3-the-mainwp-development-extension-overview-page
This snippet covers the process of packaging and distributing MainWP add-ons. It outlines the necessary steps to prepare your add-on for release, including creating a zip file and providing necessary documentation.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```
--------------------------------
### MainWP Install Theme Hooks
Source: https://mainwp.dev/hook-type/action
Hooks for customizing the Install Themes page, specifically for action bars.
```APIDOC
mainwp_install_themes_actions_bar_right:
Fires at the right side of the Install Themes action bar.
mainwp_install_themes_actions_bar_left:
Fires at the left side of the Install Themes action bar.
```
--------------------------------
### MainWP Install Plugin Card Hooks
Source: https://mainwp.dev/hook-type/action
Hooks for adding content to the plugin cards on the Install Plugin page.
```APIDOC
mainwp_install_plugin_card_bottom:
Fires at the plugin card at the bottom of the Install Plugin page.
mainwp_install_plugin_card_top:
Fires at the plugin card at the top of the Install Plugin page.
```
--------------------------------
### MainWP Add-on Development - Packaging and Distribution
Source: https://mainwp.dev/lesson-9-writing-clean-maintainable-mainwp-code-best-practices
This snippet covers the process of packaging and distributing MainWP add-ons. It outlines the necessary steps to prepare your add-on for release, including creating a zip file and providing necessary documentation.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```
--------------------------------
### PHP Usage Example for mainwp_updates_pergroup_before_abandoned_plugins
Source: https://mainwp.dev/hooks/mainwp_updates_pergroup_before_abandoned_plugins
Example of how to hook into the mainwp_updates_pergroup_before_abandoned_plugins action in PHP to execute custom functionality.
```php
add_action( 'mainwp_updates_pergroup_before_abandoned_plugins', 'your_custom_function_name' );
function your_custom_function_name( $websites, $all_groups_sites, $all_groups, $allPluginsOutdate, $decodedDismissedPlugins, $site_offset_for_groups ) {
// Your custom code here
// You can access and manipulate the provided parameters to customize behavior.
}
```
--------------------------------
### MainWP REST API Documentation
Source: https://mainwp.dev/lesson-1-setting-up-a-mainwp-development-environment
Provides access to MainWP's REST API for programmatic interaction. This documentation includes endpoints for managing sites, updates, and other core functionalities. It is designed for developers who need to integrate MainWP with other systems or automate tasks.
```APIDOC
MainWP REST API:
Base URL: https://your-mainwp-domain.com/wp-json/mainwp/v1
Authentication:
API Key authentication is required. Obtain your API key from the MainWP Dashboard under Users > API Keys.
Endpoints:
Sites:
GET /sites
Description: Retrieves a list of all connected sites.
Parameters:
- status (string, optional): Filter sites by status (e.g., 'active', 'inactive').
Returns:
- An array of site objects, each containing id, name, url, etc.
GET /sites/{id}
Description: Retrieves details for a specific connected site.
Parameters:
- id (integer): The ID of the site to retrieve.
Returns:
- A site object with detailed information.
Updates:
GET /updates
Description: Retrieves available updates for plugins, themes, and core across all sites.
Parameters:
- type (string, optional): Filter updates by type ('plugin', 'theme', 'core').
- site_id (integer, optional): Filter updates for a specific site.
Returns:
- An object containing lists of available updates for plugins, themes, and core.
Actions:
POST /sites/{id}/update-plugin
Description: Updates a specific plugin on a given site.
Parameters:
- id (integer): The ID of the site.
- plugin_uid (string): The unique identifier of the plugin to update.
Returns:
- A success or failure message.
Error Handling:
- 401 Unauthorized: Invalid or missing API key.
- 404 Not Found: The requested endpoint or resource does not exist.
- 500 Internal Server Error: An error occurred on the server.
Rate Limiting:
- Check MainWP API documentation for specific rate limits.
```
--------------------------------
### PHP Usage Example for mainwp_recent_posts_before_trash_list
Source: https://mainwp.dev/hooks/mainwp_recent_posts_before_trash_list
Example of how to hook into the `mainwp_recent_posts_before_trash_list` action in PHP to execute custom code.
```php
add_action( 'mainwp_recent_posts_before_trash_list', 'your_custom_function_name' );
function your_custom_function_name( $allPosts, $recent_number ) {
// Your code
}
```
--------------------------------
### MainWP Add-on Development - Core Concepts
Source: https://mainwp.dev/lesson-3-mainwp-development-extension
This section covers the fundamental aspects of MainWP add-on development, including setting up the development environment, creating a basic add-on structure, and understanding the core files and classes involved. It serves as an introduction to the MainWP development ecosystem.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```
--------------------------------
### PHP Usage Example for mainwp_before_plugin_unignore
Source: https://mainwp.dev/hooks/mainwp_before_plugin_unignore
Example of how to hook into the 'mainwp_before_plugin_unignore' action in WordPress using PHP. This function will be executed before a plugin is unignored.
```php
add_action( 'mainwp_before_plugin_unignore', 'your_custom_function_name' );
function your_custom_function_name( $decodedIgnoredPlugins, $website ) {
// Your code
// Access ignored plugins: $decodedIgnoredPlugins
// Access website data: $website
}
```
--------------------------------
### MainWP Add-on Development - Packaging and Distribution
Source: https://mainwp.dev/lesson-7-debugging-common-issues-in-mainwp-extensions
This snippet covers the process of packaging and distributing MainWP add-ons. It outlines the necessary steps to prepare your add-on for release, including creating a zip file and providing necessary documentation.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```
--------------------------------
### PHP Usage Example for mainwp_before_active_themes_list
Source: https://mainwp.dev/hooks/mainwp_before_active_themes_list
Example of how to hook into the `mainwp_before_active_themes_list` action in PHP. This function demonstrates the basic structure for adding a custom action.
```php
add_action( 'mainwp_before_active_themes_list', 'your_custom_function_name' );
function your_custom_function_name( $website, $actived_themes ) {
// Your code
}
```
--------------------------------
### Contributing to MainWP
Source: https://mainwp.dev/hooks/mainwp_after_plugin_theme_install_progress
Guidelines for developers who wish to contribute to the MainWP project. This includes information on how to set up the development environment and follow coding standards.
```markdown
Contributing to MainWP:
- https://github.com/mainwp/mainwp/blob/master/.github/CONTRIBUTING.md
```
--------------------------------
### MainWP Plugin Installation Checks Filter
Source: https://mainwp.dev/hook-type/filter
Filters the list of required plugins for installation. This hook allows developers to modify or add to the default plugin requirements.
```php
/**
* Filters the list of required plugins by...
* @param array $required_plugins The array of required plugins.
* @return array Modified array of required plugins.
*/
add_filter( 'mainwp_plugins_install_checks', 'my_custom_plugin_checks' );
```
--------------------------------
### MainWP Add-on Development - Packaging and Distribution
Source: https://mainwp.dev/lesson-3-the-mainwp-development-extension-individual-site-subpage
This snippet covers the process of packaging and distributing MainWP add-ons. It outlines the necessary steps to prepare your add-on for release, including creating a zip file and providing necessary documentation.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```
--------------------------------
### MainWP Add-on Development - Packaging and Distribution
Source: https://mainwp.dev/lesson-3-the-mainwp-development-extension-database
This snippet covers the process of packaging and distributing MainWP add-ons. It outlines the necessary steps to prepare your add-on for release, including creating a zip file and providing necessary documentation.
```php
open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
exit('cannot open zip file');
}
$source_dir = '/path/to/your/addon/directory';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOT_FILES));
foreach ($iterator as $file) {
if ($file->isDir()) continue;
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($source_dir) + 1);
$zip->addFile($filePath, $relativePath);
}
$zip->close();
*/
// For distribution, you would manually create the zip file or use a build script.
// Include a README.txt file with installation and usage instructions.
```