Introduction
Store Addons for WooCommerce is a comprehensive WordPress plugin boilerplate that provides a solid foundation for building modern WordPress plugins. It features a React-based admin interface, REST API endpoints, AJAX handling, WP-CLI commands, and more.
This plugin follows WordPress coding standards and best practices, using PSR-4 autoloading for PHP classes and modern tooling for frontend development.
Modern Architecture
PSR-4 autoloading, singleton patterns, and modular class structure.
React Admin Interface
Built with React, Semi UI components, and Webpack for asset compilation.
REST & AJAX APIs
Full REST API with namespace store-addons-for-woocommerce/v1 and AJAX endpoints.
Requirements
Before installing, ensure your environment meets the following requirements:
WordPress 5.8+ PHP 7.4+ Node.js 18+ Composer 2.0+The plugin uses WordPress REST API and requires the manage_options capability for most admin features.
Composer Installation
Install PHP dependencies using Composer. The plugin uses PSR-4 autoloading with the namespace MosPress\StoreAddonsForWoocommerce\.
NPM Installation
Install JavaScript dependencies and build the admin interface assets using Webpack.
Architecture
The plugin follows a modular architecture with clear separation of concerns. All PHP classes are located in the includes/ directory and use PSR-4 autoloading.
Core Classes
| Class | File | Purpose |
|---|---|---|
Plugin |
includes/Plugin.php |
Main plugin class that initializes all components |
Loader |
includes/Core/Loader.php |
Registers all actions, filters, and shortcodes |
Activator |
includes/Core/Activator.php |
Plugin activation tasks (create tables, set defaults) |
Deactivator |
includes/Core/Deactivator.php |
Plugin deactivation tasks |
Admin Classes
| Class | File | Purpose |
|---|---|---|
AdminClass |
includes/Admin/AdminClass.php |
Admin assets and page rendering |
Action_Hook |
includes/Hook/Action_Hook.php |
Admin menu, activation redirect, settings form |
Filter_Hook |
includes/Hook/Filter_Hook.php |
Filter hooks for customization |
API Classes
| Class | File | Purpose |
|---|---|---|
Rest_API |
includes/API/Rest_API.php |
REST API endpoints with namespace v1 |
Ajax_API |
includes/API/Ajax_API.php |
AJAX callbacks for admin operations |
LogsController |
includes/API/LogsController.php |
Logs CRUD operations and statistics |
Settings Management
Settings are stored in the WordPress options table under the key store_addons_for_woocommerce_options. The plugin provides functions for retrieving and managing settings.
REST API Overview
The plugin registers REST API endpoints with the namespace store-addons-for-woocommerce/v1. Most endpoints require the manage_options capability for access.
Base URL: https://yoursite.com/wp-json/store-addons-for-woocommerce/v1
Settings Endpoints
GET /options
Retrieve all plugin settings.
| Method | Permission | Description |
|---|---|---|
| GET | manage_options |
Get all settings |
POST /options
Update plugin settings. Send options in the body as store_addons_for_woocommerce_options.
POST /options/reset-settings
Reset a specific setting to its default value.
POST /options/reset-settings-all
Reset all settings to defaults.
POST /options/import-settings
Import settings from JSON data.
POST /feedback
Submit feedback. Sends email notifications to admin and developer.
| Parameter | Type | Required |
|---|---|---|
subject |
string | Yes |
message |
string | Yes |
email |
string | No |
phone |
string | No |
GET /set-settings-theme
Set admin theme preference (light/dark).
| Parameter | Type | Values |
|---|---|---|
settings_theme |
string | light, dark |
Logs Endpoints
Manage and retrieve activity logs stored in a custom database table.
GET /logs
Retrieve logs with pagination and filters.
| Parameter | Type | Default |
|---|---|---|
page |
integer | 1 |
per_page |
integer | 5 |
search |
string | - |
sort_field |
string | - |
sort_order |
string | - |
filter |
string | - |
date_from |
string | - |
date_to |
string | - |
GET /logs/search
Full-text search in logs.
POST /logs
Create a new log entry.
| Parameter | Type | Required |
|---|---|---|
user_id |
integer | Yes |
ip |
string | Yes |
user_agent |
string | Yes |
title |
string | Yes |
description |
string | Yes |
data |
string | Yes |
GET /logs/{id}
Get a single log entry by ID.
PATCH /logs/{id}
Update a log entry.
DELETE /logs/{id}
Delete a log entry.
DELETE /logs/delete-all
Delete all log entries.
DELETE /logs/bulk-delete
Delete multiple log entries.
Statistics Endpoints
Get log analytics:
| GET /logs/stats/over-time | Logs over time chart data |
| GET /logs/stats/by-category | Logs by category chart data |
| GET /logs/stats/top-users | Top users by log count |
| GET /logs/stats/top-ips | Top IP addresses |
| GET /logs/stats/hourly-activity | Hourly activity chart data |
Product Endpoints
Manage product specifications (WooCommerce compatible).
GET /product/{product_id}/specifications
Get specifications for a product.
POST /product/{product_id}/specifications
Save specifications for a product.
AJAX API
AJAX endpoints for admin operations. All requests require nonce verification.
Available Actions
store_addons_for_woocommerce_reset_settings
Reset a specific setting path to its default value.
store_addons_for_woocommerce_ajax_callback
General AJAX callback for public-facing operations.
Hooks & Filters
The plugin provides various action and filter hooks for customization.
Actions
| Hook | File | Purpose |
|---|---|---|
admin_init |
Action_Hook.php:25 | Activation redirect |
admin_menu |
Action_Hook.php:26 | Add admin menu page |
admin_enqueue_scripts |
AdminClass.php:80 | Enqueue admin assets |
wp_enqueue_scripts |
PublicClass.php:95 | Enqueue public assets |
Filters
Available filters for extending functionality. Check Filter_Hook.php for implementation details.
WP-CLI Commands
Command-line tools for managing plugin data.
Seed Logs
Generate sample log entries for testing.
Clear Logs
Remove all log entries from the database.
Show Logs
Display recent log entries.
Building Assets
The admin interface is built with React and compiled using Webpack. The build process uses Babel for transpilation and various loaders for CSS and SCSS.
Build Scripts
Dependencies
Key frontend dependencies:
Core
react@18.2.0 react-dom@18.2.0 webpack@5.88.2UI Components
@douyinfe/semi-ui @visactor/react-vchart @wordpress/componentsFile Structure
| Path | Description |
|---|---|
includes/ |
Main plugin classes (PSR-4 namespace root) |
includes/Admin/ |
Admin-specific functionality |
includes/Public/ |
Public-facing functionality |
includes/API/ |
REST API and AJAX handlers |
includes/Core/ |
Core classes (Loader, Activator, Deactivator) |
includes/Hook/ |
Action and filter hook handlers |
includes/CLI/ |
WP-CLI commands |
includes/Helpers/ |
Helper utility classes |
assets/ |
Frontend source files |
assets/src/ |
React components and source code |
assets/build/ |
Compiled assets (output) |
admin/ |
Admin-specific assets and templates |
public/ |
Public-facing assets |