Một package framework-agnostic để tích hợp các option frameworks khác nhau vào WordPress themes.
Option Adapter cung cấp một interface thống nhất để làm việc với các option frameworks khác nhau (Redux, Kirki, WordPress Settings API, Customizer) mà không cần hardcode framework-specific logic vào theme.
graph TD
A[Theme] --> B[Option Adapter]
B --> C[Framework Detection]
C --> D[Adapter Selection]
D --> E[Redux Adapter]
D --> F[Kirki Adapter]
D --> G[WordPress Settings API Adapter]
D --> H[Customizer Adapter]
D --> I[Jankx Dashboard Adapter]
E --> J[Redux Transformer]
F --> K[Kirki Transformer]
G --> L[WordPress Transformer]
H --> M[Customizer Transformer]
I --> N[Native Transformer]
J --> O[Redux Framework]
K --> P[Kirki Framework]
L --> Q[WordPress Settings API]
M --> R[WordPress Customizer]
N --> S[Jankx Dashboard]
src/
├── Abstracts/
│ └── Adapter.php # Interface cho tất cả adapters
├── Frameworks/
│ ├── ReduxFramework.php # Adapter cho Redux Framework
│ ├── KirkiFramework.php # Adapter cho Kirki Framework
│ ├── WordPressSettingAPI.php # Adapter cho WordPress Settings API
│ ├── CustomizeFramework.php # Adapter cho WordPress Customizer
│ └── JankxOptionFramework.php # Native adapter cho Jankx Dashboard
├── Transformers/
│ ├── ReduxTransformer.php # Transformer cho Redux
│ ├── KirkiTransformer.php # Transformer cho Kirki
│ ├── WordPressTransformer.php # Transformer cho WordPress Settings API
│ └── CustomizeTransformer.php # Transformer cho Customizer
├── Repositories/
│ └── ConfigRepository.php # Repository để load config
├── Specs/
│ ├── Page.php # Page specification
│ ├── Section.php # Section specification
│ └── Field.php # Field specification
├── Framework.php # Core framework detection & loading
└── OptionsReader.php # Reader cho options data
Core class để detect và load option framework phù hợp.
Methods:
detectFramework()- Detect framework có sẵngetFrameworkFromConfig()- Lấy framework từ configsetFrameworkFromExternal()- Set framework từ bên ngoàigetAdapter()- Lấy adapter instance
Đọc và parse options data từ files.
Methods:
getPages()- Lấy danh sách pagesgetSections($pageTitle)- Lấy sections của pagegetFields($sectionTitle)- Lấy fields của sectionsetOptionsDirectoryPath($path)- Set path cho options directory
Interface chung cho tất cả adapters.
Methods:
createSections($optionsReader)- Tạo sections cho frameworktransformIcon($dashicon)- Transform icon cho framework
- Adapter:
ReduxFramework - Transformer:
ReduxTransformer - Icon Mapping:
dashicons→elusiveicons
- Adapter:
KirkiFramework - Transformer:
KirkiTransformer - Icon Mapping:
dashicons(direct)
- Adapter:
WordPressSettingAPI - Transformer:
WordPressTransformer - Icon Mapping:
dashicons(direct)
- Adapter:
CustomizeFramework - Transformer:
CustomizeTransformer - Icon Mapping:
dashicons(direct)
- Adapter:
JankxOptionFramework - Transformer: Native (không cần transformer)
- Icon Mapping:
dashicons(direct)
use Jankx\Adapter\Options\Framework as OptionFramework;
// Initialize framework
$framework = OptionFramework::getInstance();
// Get adapter
$adapter = $framework->getAdapter();
// Create sections
$optionsReader = OptionsReader::getInstance();
$optionsReader->setOptionsDirectoryPath('resources/options');
$adapter->createSections($optionsReader);// Trong config/app.php
'options' => [
'framework' => 'redux', // hoặc 'kirki', 'wordpress', 'customize', 'jankx'
'display_name' => 'Theme Options',
'menu_title' => 'Theme Options',
'page_slug' => 'theme-options',
'dev_mode' => true,
],resources/options/
├── pages.php # Pages configuration
├── general/ # Page directory
│ ├── sections.php # Sections cho page
│ ├── site-information/ # Section directory
│ │ └── fields.php # Fields cho section
│ └── social-media/ # Section directory
│ └── fields.php # Fields cho section
└── typography/ # Page directory
├── sections.php
└── body-typography/
└── fields.php
return [
'general' => [
'title' => 'General Settings',
'icon' => 'dashicons-admin-generic',
'priority' => 30,
],
'typography' => [
'title' => 'Typography',
'icon' => 'dashicons-editor-textcolor',
'priority' => 30,
],
];return [
'site-information' => [
'title' => 'Site Information',
'description' => 'Basic site settings',
],
'social-media' => [
'title' => 'Social Media',
'description' => 'Social media links',
],
];return [
'site_title' => [
'type' => 'text',
'title' => 'Site Title',
'subtitle' => 'Main site title',
'description' => 'Enter your site title',
'default' => 'Bookix - Book Store',
],
'site_logo' => [
'type' => 'image',
'title' => 'Site Logo',
'subtitle' => 'Upload logo',
'description' => 'Upload your site logo',
],
];text- Text inputtextarea- Textareaimage- Media uploadcolor- Color pickerselect- Select dropdownradio- Radio buttonscheckbox- Checkboxswitch- Toggle switch
slider- Range slidertypography- Typography settingsbackground- Background settingsspacing- Spacing controlsimage_select- Image selectgallery- Gallery uploadrepeater- Repeater fieldsorter- Sortable list
Mỗi framework có cách xử lý icons khác nhau:
// dashicons → elusiveicons
'dashicons-admin-generic' => 'el el-cog'
'dashicons-editor-textcolor' => 'el el-font'
'dashicons-art' => 'el el-picture'// Sử dụng dashicons trực tiếp
'dashicons-admin-generic' => 'dashicons-admin-generic'Option Adapter tự động hỗ trợ child theme overrides:
- Child theme priority - Đọc từ child theme trước
- Parent theme fallback - Fallback về parent theme
- Deep merge - Merge arrays một cách thông minh
- External configuration -
setFrameworkFromExternal() - Config file -
Config::get('app.options.framework') - WordPress options - Database stored preference
- Auto detection - Detect available frameworks
- Graceful degradation - Fallback khi framework không có sẵn
- Debug logging - Log chi tiết cho development
- Exception handling - Catch và handle exceptions
- Lazy loading - Chỉ load khi cần
- Caching - Cache configuration và data
- Memory efficient - Tối ưu memory usage
- Create Adapter:
class NewFrameworkAdapter implements Adapter
{
public function createSections($optionsReader) { /* ... */ }
public function transformIcon($dashicon) { /* ... */ }
}- Create Transformer:
class NewFrameworkTransformer
{
public static function transformPage($page) { /* ... */ }
public static function transformField($field) { /* ... */ }
}- Register in Framework:
// Trong Framework.php
protected $supportedFrameworks = [
'newframework' => NewFrameworkAdapter::class,
];// Test framework detection
$framework = OptionFramework::getInstance();
$adapter = $framework->getAdapter();
assert($adapter instanceof ExpectedAdapter);
// Test icon transformation
$icon = $adapter->transformIcon('dashicons-admin-generic');
assert($icon === 'expected-icon');MIT License - Xem file LICENSE để biết thêm chi tiết.