افزونه اختصاصی سهره
A custom WordPress plugin developed to integrate WordPress with the Sohreh application.
by Artacode · github.com/amirsafaridevs/sohreh-plugin · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/amirsafaridevs/sohreh-plugin/archive/refs/heads/main.zipArta Sohre WordPress Plugin
A professional and powerful WordPress plugin for connecting and synchronizing WordPress and WooCommerce data with the Sohre mobile application. Built with MVC architecture and advanced design patterns, this plugin enables bidirectional communication between the content management system and the mobile application.
📋 Table of Contents
- Features
- Architecture
- Project Structure
- Installation
- API Endpoints
- Authentication
- Configuration
- Development
- Contributing
- License
✨ Features
- 🔄 Automatic Synchronization: Automatic synchronization of products, categories, orders, and users with the mobile application
- 🔐 Secure Authentication: Bearer Token and mobile number-based authentication system
- 🎯 MVC Architecture: Implementation of MVC architectural pattern for code separation and organization
- 🛣️ Advanced Routing: Custom routing system with support for dynamic parameters
- 📡 RESTful API: Complete and standards-compliant RESTful API
- 🎪 Event-Driven: Event-based architecture for automatic synchronization
- 📊 Log Management: Error logging and management system
- ⚙️ Admin Panel: Complete admin panel for settings and configuration
- 🔌 WooCommerce Integration: Full integration with WooCommerce
🏗️ Architecture
This project utilizes MVC (Model-View-Controller) Architecture along with Service Layer and Event-Driven Architecture.
Architectural Patterns Used:
1. MVC Pattern (Model-View-Controller)
- Models: Data access and database operations (
Include/Models/) - Controllers: Request and response logic management (
Include/Controllers/) - Views: In this project, responses are provided as JSON
2. Service Layer Pattern
- Service layer for external API communication (
Include/Services/) - Separation of business logic from controller layer
3. Repository Pattern
- Models act as repositories
- Separation of data access logic from business logic
4. Event-Driven Architecture
- Use of WordPress Hooks for automatic synchronization
- Separation of event logic from core logic
5. Helper Pattern
- Helper classes for common operations (
Include/Helpers/) - Code reusability and reduced duplication
6. Routing Pattern
- Custom routing system with RESTful route support
- Support for dynamic URL parameters
Architecture Diagram:
┌─────────────────────────────────────────────────────────┐
│ WordPress Core │
└────────────────────┬────────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────────┐
│ Arta Sohre Plugin │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Routes │──▶│ Controllers │──▶│ Models │ │
│ │ (api.php) │ │ │ │ │ │
│ └──────────────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │
│ ┌──────────────┐ ┌──────▼───────┐ ┌──────▼───────┐ │
│ │ Auth │ │ Services │ │ Helpers │ │
│ │ │ │ (ApiService) │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Event Handlers (WordPress Hooks) │ │
│ └──────────────────────────────────────────────────┘ │
└────────────────────┬────────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────────┐
│ WooCommerce / WordPress │
└─────────────────────────────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────────┐
│ External API (Sohre App) │
└─────────────────────────────────────────────────────────┘
📁 Project Structure
Arta_sohre/
│
├── Arta_sohre.php # Main plugin file
│
└── Include/ # Main code directory
│
├── main.php # Main loader file
│
├── Config.php # Configuration management class
│
├── Core/ # Core classes
│ ├── Route.php # Routing system
│ └── Auth.php # Authentication system
│
├── Controllers/ # Controllers (Control layer)
│ ├── ProductController.php
│ ├── CategoryController.php
│ ├── AttributeController.php
│ ├── OrderController.php
│ ├── UserController.php
│ └── SettingController.php
│
├── Models/ # Models (Data layer)
│ ├── ProductModel.php
│ ├── CategoryModel.php
│ ├── AttributeModel.php
│ ├── OrderModel.php
│ ├── UserModel.php
│ └── SettingModel.php
│
├── Services/ # Services (Service layer)
│ ├── ApiService.php # External API communication
│ └── EventHandler.php # Event management
│
├── Helpers/ # Helper classes
│ ├── RequestHelper.php
│ ├── ResponseHelper.php
│ ├── LogHelper.php
│ ├── AdminHelper.php
│ └── AdminPages.php
│
├── Routes/ # Route definitions
│ └── api.php
│
├── Events/ # Event management
│ └── hooks.php
│
└── Class/ # Legacy classes
├── ASRoute.php
├── ASProduct.php
├── ASCategory.php
└── ...
Layer Descriptions:
Core Layer
Route.php: Custom routing system with RESTful route supportAuth.php: Bearer Token-based authentication system
Controller Layer
Controllers are responsible for receiving requests, validating data, and sending responses.
Model Layer
Models are responsible for data access and database operations.
Service Layer
Services manage business logic and external API communication.
Helper Layer
Helper classes are used for common and repetitive operations.
🚀 Installation
Prerequisites
- WordPress 5.0 or higher
- WooCommerce 3.0 or higher
- PHP 7.4 or higher
- Access to Sohre application API
Installation Steps
-
Download the Plugin
git clone https://github.com/your-username/Arta_sohre.git -
Copy to WordPress Plugins Directory
cp -r Arta_sohre /wp-content/plugins/ -
Activate the Plugin
- Log in to WordPress admin panel
- Navigate to "Plugins" section
- Activate "Arta Sohre Plugin"
-
Configuration
- Go to plugin settings
- Configure token and mobile number
- Configure synchronization settings
📡 API Endpoints
The plugin provides a complete RESTful API with the prefix /as-api/v1.
Products
| Method | Endpoint | Description |
|---|---|---|
| GET | /as-api/v1/product/get |
Get list of products |
| GET | /as-api/v1/product/get/{id} |
Get a single product |
| POST | /as-api/v1/product/create |
Create new product |
| POST | /as-api/v1/product/update/{id} |
Update product |
Categories
| Method | Endpoint | Description |
|---|---|---|
| GET | /as-api/v1/product/category/get |
Get list of categories |
| GET | /as-api/v1/product/category/get/{id} |
Get a single category |
| POST | /as-api/v1/product/category/create |
Create new category |
| POST | /as-api/v1/product/category/update/{id} |
Update category |
Attributes
| Method | Endpoint | Description |
|---|---|---|
| GET | /as-api/v1/product/attribute/get |
Get list of attributes |
| GET | /as-api/v1/product/attribute/get/{id} |
Get a single attribute |
| POST | /as-api/v1/product/attribute/create |
Create new attribute |
| POST | /as-api/v1/product/attribute/update/{id} |
Update attribute |
Orders
| Method | Endpoint | Description |
|---|---|---|
| GET | /as-api/v1/order/get |
Get list of orders |
| GET | /as-api/v1/order/get/{id} |
Get a single order |
Users
| Method | Endpoint | Description |
|---|---|---|
| GET | /as-api/v1/user/get |
Get list of users |
| GET | /as-api/v1/user/get/{id} |
Get a single user |
Settings
| Method | Endpoint | Description |
|---|---|---|
| GET | /as-api/v1/setting/get |
Get settings |
| POST | /as-api/v1/setting/set |
Update settings |
Usage Examples:
# Get list of products
curl -X GET "https://yoursite.com/as-api/v1/product/get" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "phone: YOUR_PHONE"
# Create new product
curl -X POST "https://yoursite.com/as-api/v1/product/create" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "phone: YOUR_PHONE" \
-H "Content-Type: application/json" \
-d '{
"name": "New Product",
"price": "100000",
"description": "Product description"
}'
🔐 Authentication
The plugin uses Bearer Token and Mobile Number based authentication system.
How to Use:
-
Get Token and Mobile Number
- Token and mobile number must be configured through the admin panel
-
Send Request
- Header
Authorizationwith valueBearer YOUR_TOKEN - Header
phonewith mobile number
- Header
Example:
GET /as-api/v1/product/get HTTP/1.1
Host: yoursite.com
Authorization: Bearer abc123xyz789
phone: 09123456789
⚙️ Configuration
Plugin Settings
The plugin can be configured through WordPress admin panel:
- Mobile Token: Authentication token for API
- Mobile Number: Mobile number associated with token
- Sohre API Address: Sohre application API address
- Synchronization Settings: Enable/disable automatic synchronization for each module
Default Settings
// In Arta_sohre.php file
define("SOHRE_API_ADDRESS", "http://45.149.76.5:9001/api");
define("ARTACODE_LOG_COUNT", 30);
🔧 Development
Adding a New Endpoint
-
Define Route in
Include/Routes/api.php:Route::get($prefix.'/custom/endpoint', 'CustomController@method'); -
Create Controller in
Include/Controllers/:namespace ArtaSohre\Controllers; class CustomController { public function method() { // Your logic } } -
Create Model in
Include/Models/(if needed):namespace ArtaSohre\Models; class CustomModel { public static function getData() { // Data access } }
Adding a New Event Handler
- Create Handler in
Include/Services/EventHandler.php - Register Hook in
Include/Events/hooks.php
Coding Standards
- Use PSR-4 Autoloading
- Use Namespaces for code separation
- Use PHPDoc for documentation
- Follow WordPress Coding Standards
🤝 Contributing
Contributions to this project are welcome! Please:
- Fork the project
- Create a new branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📝 Changelog
Version 1.0.0
- Initial release
- MVC architecture implementation
- Custom routing system
- Complete RESTful API
- Automatic synchronization with Sohre application
- Admin panel
📄 License
This project is licensed under the GPLv2 License.
👥 Developers
- Artacode - https://artacode.net/
📞 Support
For support and bug reports, please create an Issue on GitHub or contact the development team.
Made with ❤️ by Amir Safari