PHPackages                             puleeno/rake-wordpress-adapter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. puleeno/rake-wordpress-adapter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

puleeno/rake-wordpress-adapter
==============================

WordPress adapter for Rake 2.0

1.3.5(10mo ago)0192[2 issues](https://github.com/puleeno/rake-wordpress-adapter/issues)2MITPHPCI passing

Since Jan 29Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/puleeno/rake-wordpress-adapter)[ Packagist](https://packagist.org/packages/puleeno/rake-wordpress-adapter)[ RSS](/packages/puleeno-rake-wordpress-adapter/feed)WikiDiscussions v2 Synced today

READMEChangelog (8)Dependencies (3)Versions (10)Used By (2)

RAKE WORDPRESS ADAPTER
======================

[](#rake-wordpress-adapter)

**Phiên bản:** 1.0 **Ngày tạo:** 2025 **Tác giả:** Development Team

---

📋 MỤC LỤC
---------

[](#-mục-lục)

1. [Tổng quan WordPress Adapter](#t%E1%BB%95ng-quan-wordpress-adapter)
2. [Mối quan hệ với Rake Core](#m%E1%BB%91i-quan-h%E1%BB%87-v%E1%BB%9Bi-rake-core)
3. [Kiến trúc Adapter](#ki%E1%BA%BFn-tr%C3%BAc-adapter)
4. [Database Integration](#database-integration)
5. [WordPress Integration](#wordpress-integration)
6. [Cách sử dụng](#c%C3%A1ch-s%E1%BB%AD-d%E1%BB%A5ng)
7. [Tài liệu kỹ thuật](#t%C3%A0i-li%E1%BB%87u-k%E1%BB%B9-thu%E1%BA%ADt)
8. [Development Guidelines](#development-guidelines)

---

🎯 TỔNG QUAN WORDPRESS ADAPTER
-----------------------------

[](#-tổng-quan-wordpress-adapter)

### Mục tiêu

[](#mục-tiêu)

Rake WordPress Adapter là bridge giữa Rake Core Framework và WordPress, cung cấp:

- **WordPress Database Integration**: Adapter cho WordPress database operations
- **WordPress Hooks Integration**: Tích hợp với WordPress hooks system
- **WordPress Admin Integration**: Tích hợp với WordPress admin interface
- **Security Layer**: WordPress security functions integration
- **Cache Integration**: WordPress cache system integration

### Vai trò trong hệ thống

[](#vai-trò-trong-hệ-thống)

```
┌─────────────────────────────────────────────────────────────┐
│                RAKE WORDPRESS ADAPTER                      │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────┐ │
│  │   DATABASE      │  │     HOOKS       │  │    ADMIN    │ │
│  │   ADAPTER       │  │   INTEGRATION   │  │ INTEGRATION │ │
│  │                 │  │                 │  │             │ │
│  │ • WP Database   │  │ • add_action    │  │ • Menu      │ │
│  │ • Query Builder │  │ • add_filter    │  │ • Pages     │ │
│  │ • Prefix Handle │  │ • do_action     │  │ • Scripts   │ │
│  │ • wpdb Wrapper  │  │ • apply_filters │  │ • Styles    │ │
│  └─────────────────┘  └─────────────────┘  └─────────────┘ │
│                                                             │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────┐ │
│  │    SECURITY     │  │      CACHE      │  │   CONFIG    │ │
│  │     LAYER       │  │   INTEGRATION   │  │ INTEGRATION │ │
│  │                 │  │                 │  │             │ │
│  │ • Nonce Check   │  │ • WP Cache      │  │ • WP Config │ │
│  │ • Capability    │  │ • Transients    │  │ • Options   │ │
│  │ • Sanitization  │  │ • Object Cache  │  │ • Settings  │ │
│  │ • Validation    │  │ • Query Cache   │  │ • Constants │ │
│  └─────────────────┘  └─────────────────┘  └─────────────┘ │
└─────────────────────────────────────────────────────────────┘

```

---

🔗 MỐI QUAN HỆ VỚI RAKE CORE
---------------------------

[](#-mối-quan-hệ-với-rake-core)

### Dependency Chain

[](#dependency-chain)

```
┌─────────────────┐    depends on    ┌─────────────────┐
│   CRAWFLOW      │ ────────────────▶ │ RAKE WORDPRESS  │
│   PLUGIN        │                  │    ADAPTER      │
└─────────────────┘                  └─────────────────┘
                                              │
                                              │ depends on
                                              ▼
                                    ┌─────────────────┐
                                    │   RAKE CORE     │
                                    │   FRAMEWORK     │
                                    └─────────────────┘

```

### Interface Implementation

[](#interface-implementation)

WordPress Adapter implements các interfaces từ Rake Core:

```
// Database Adapter Interface từ Rake Core
interface DatabaseAdapterInterface
{
    public function query(string $sql): bool;
    public function getResults(string $sql): array;
    public function getRow(string $sql): ?array;
    public function getVar(string $sql): mixed;
    public function insert(string $table, array $data): int;
    public function update(string $table, array $data, array $where): int;
    public function delete(string $table, array $where): int;
    public function getPrefix(): string;
    public function escape(string $value): string;
}

// WordPress Adapter Implementation
class WordPressDatabaseAdapter implements DatabaseAdapterInterface
{
    // Implementation cho WordPress
}
```

### Service Registration

[](#service-registration)

```
// Trong Rake Container
$container->bind(DatabaseAdapterInterface::class, WordPressDatabaseAdapter::class);
$container->bind(WordPressHooksInterface::class, WordPressHooksAdapter::class);
$container->bind(WordPressAdminInterface::class, WordPressAdminAdapter::class);
```

---

🏗️ KIẾN TRÚC ADAPTER
--------------------

[](#️-kiến-trúc-adapter)

### Package Structure

[](#package-structure)

```
rake-wordpress-adapter/
├── src/
│   ├── Database/              # WordPress Database Integration
│   │   ├── WordPressDatabaseAdapter.php
│   │   ├── WordPressQueryBuilder.php
│   │   └── WordPressPrefixHandler.php
│   ├── Hooks/                 # WordPress Hooks Integration
│   │   ├── WordPressHooksAdapter.php
│   │   └── WordPressHooksInterface.php
│   ├── Admin/                 # WordPress Admin Integration
│   │   ├── WordPressAdminAdapter.php
│   │   ├── WordPressMenuBuilder.php
│   │   └── WordPressScriptManager.php
│   ├── Security/              # WordPress Security Layer
│   │   ├── WordPressSecurityAdapter.php
│   │   ├── WordPressNonceHandler.php
│   │   └── WordPressCapabilityChecker.php
│   ├── Cache/                 # WordPress Cache Integration
│   │   ├── WordPressCacheAdapter.php
│   │   ├── WordPressTransientHandler.php
│   │   └── WordPressObjectCache.php
│   └── Config/                # WordPress Config Integration
│       ├── WordPressConfigAdapter.php
│       └── WordPressOptionsHandler.php
├── composer.json
└── README.md

```

### Package Dependencies

[](#package-dependencies)

```
{
    "name": "puleeno/rake-wordpress-adapter",
    "require": {
        "php": ">=8.1",
        "ramphor/rake": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "Rake\\WordPress\\": "src/"
        }
    }
}
```

---

🗄️ DATABASE INTEGRATION
-----------------------

[](#️-database-integration)

### WordPress Database Adapter

[](#wordpress-database-adapter)

```
use Rake\WordPress\Database\WordPressDatabaseAdapter;

$adapter = new WordPressDatabaseAdapter();

// Basic operations
$adapter->insert('posts', [
    'post_title' => 'Test Post',
    'post_content' => 'Test content',
    'post_status' => 'publish'
]);

$posts = $adapter->getResults("SELECT * FROM {$adapter->getPrefix()}posts WHERE post_type = 'post'");

$adapter->update('posts',
    ['post_status' => 'draft'],
    ['ID' => 1]
);

$adapter->delete('posts', ['ID' => 1]);
```

### WordPress Query Builder

[](#wordpress-query-builder)

```
use Rake\WordPress\Database\WordPressQueryBuilder;

$query = new WordPressQueryBuilder($adapter);

$posts = $query->select(['ID', 'post_title', 'post_content'])
    ->from('posts')
    ->where('post_type', '=', 'post')
    ->where('post_status', '=', 'publish')
    ->orderBy('post_date', 'DESC')
    ->limit(10)
    ->get();
```

### Prefix Handling

[](#prefix-handling)

```
// Tự động xử lý WordPress table prefix
$adapter = new WordPressDatabaseAdapter();
echo $adapter->getPrefix(); // wp_

// Tự động thêm prefix khi cần
$table = $adapter->addPrefix('posts'); // wp_posts
```

---

🔧 WORDPRESS INTEGRATION
-----------------------

[](#-wordpress-integration)

### WordPress Hooks Integration

[](#wordpress-hooks-integration)

```
use Rake\WordPress\Hooks\WordPressHooksAdapter;

$hooks = new WordPressHooksAdapter();

// Add actions
$hooks->addAction('init', [$this, 'initialize']);
$hooks->addAction('wp_loaded', [$this, 'onWpLoaded']);

// Add filters
$hooks->addFilter('the_content', [$this, 'modifyContent']);

// Do actions
$hooks->doAction('custom_action', $data);

// Apply filters
$modified = $hooks->applyFilters('custom_filter', $value);
```

### WordPress Admin Integration

[](#wordpress-admin-integration)

```
use Rake\WordPress\Admin\WordPressAdminAdapter;

$admin = new WordPressAdminAdapter();

// Add menu pages
$admin->addMenuPage(
    'My Plugin',
    'My Plugin',
    'manage_options',
    'my-plugin',
    [$this, 'renderPage']
);

// Enqueue scripts
$admin->enqueueScript('my-script', '/path/to/script.js');

// Enqueue styles
$admin->enqueueStyle('my-style', '/path/to/style.css');
```

### WordPress Security Layer

[](#wordpress-security-layer)

```
use Rake\WordPress\Security\WordPressSecurityAdapter;

$security = new WordPressSecurityAdapter();

// Nonce verification
if ($security->verifyNonce($_POST['nonce'], 'my_action')) {
    // Process form
}

// Capability checking
if ($security->currentUserCan('manage_options')) {
    // Admin action
}

// Data sanitization
$clean = $security->sanitizeTextField($_POST['data']);
```

---

🚀 CÁCH SỬ DỤNG
--------------

[](#-cách-sử-dụng)

### 1. Cài đặt

[](#1-cài-đặt)

#### Composer Installation

[](#composer-installation)

```
composer require puleeno/rake-wordpress-adapter
```

#### Manual Installation

[](#manual-installation)

```
git clone https://github.com/puleeno/rake-wordpress-adapter.git
cd rake-wordpress-adapter
composer install
```

### 2. Khởi tạo với Rake Core

[](#2-khởi-tạo-với-rake-core)

```
use Rake\Rake;
use Rake\WordPress\Database\WordPressDatabaseAdapter;
use Rake\WordPress\Hooks\WordPressHooksAdapter;
use Rake\WordPress\Admin\WordPressAdminAdapter;

// Tạo Rake container
$app = new Rake();

// Register WordPress adapters
$app->singleton(DatabaseAdapterInterface::class, WordPressDatabaseAdapter::class);
$app->singleton(WordPressHooksInterface::class, WordPressHooksAdapter::class);
$app->singleton(WordPressAdminInterface::class, WordPressAdminAdapter::class);

// Bootstrap
$app->make(WordPressHooksInterface::class);
```

### 3. Sử dụng Database Adapter

[](#3-sử-dụng-database-adapter)

```
// Basic CRUD operations
$adapter = new WordPressDatabaseAdapter();

// Insert
$postId = $adapter->insert('posts', [
    'post_title' => 'New Post',
    'post_content' => 'Post content',
    'post_status' => 'publish',
    'post_type' => 'post'
]);

// Select
$posts = $adapter->getResults("
    SELECT * FROM {$adapter->getPrefix()}posts
    WHERE post_type = 'post'
    ORDER BY post_date DESC
    LIMIT 10
");

// Update
$affected = $adapter->update('posts',
    ['post_status' => 'draft'],
    ['ID' => $postId]
);

// Delete
$deleted = $adapter->delete('posts', ['ID' => $postId]);
```

### 4. Sử dụng Hooks Adapter

[](#4-sử-dụng-hooks-adapter)

```
$hooks = new WordPressHooksAdapter();

// Register plugin hooks
$hooks->addAction('plugins_loaded', function() {
    // Plugin initialization
});

$hooks->addAction('admin_menu', function() {
    // Add admin menu
});

$hooks->addFilter('the_title', function($title) {
    return 'Modified: ' . $title;
});
```

### 5. Sử dụng Admin Adapter

[](#5-sử-dụng-admin-adapter)

```
$admin = new WordPressAdminAdapter();

// Add admin menu
$admin->addMenuPage(
    'My Plugin',
    'My Plugin',
    'manage_options',
    'my-plugin',
    function() {
        echo 'My Plugin';
    }
);

// Enqueue admin assets
$admin->enqueueScript('my-admin-script', '/js/admin.js');
$admin->enqueueStyle('my-admin-style', '/css/admin.css');
```

### 6. Sử dụng Security Adapter

[](#6-sử-dụng-security-adapter)

```
$security = new WordPressSecurityAdapter();

// Form processing
if ($_POST && $security->verifyNonce($_POST['nonce'], 'save_data')) {
    if ($security->currentUserCan('manage_options')) {
        $cleanData = $security->sanitizeTextField($_POST['data']);
        // Process data
    }
}
```

### 7. Sử dụng Cache Adapter

[](#7-sử-dụng-cache-adapter)

```
$cache = new WordPressCacheAdapter();

// Set cache
$cache->set('my_key', $data, 3600); // 1 hour

// Get cache
$data = $cache->get('my_key');

// Delete cache
$cache->delete('my_key');
```

---

📚 TÀI LIỆU KỸ THUẬT
-------------------

[](#-tài-liệu-kỹ-thuật)

### Tài liệu chi tiết

[](#tài-liệu-chi-tiết)

📖 [`docs/technical-documentation.md`](docs/technical-documentation.md)

**Nội dung:**

- WordPress Database Integration
- WordPress Hooks Integration
- WordPress Admin Integration
- Security Layer
- Cache Integration
- Development Guidelines

### Code Examples

[](#code-examples)

#### Database Operations

[](#database-operations)

```
// Transaction handling
$adapter->beginTransaction();
try {
    $adapter->insert('posts', $postData);
    $adapter->insert('postmeta', $metaData);
    $adapter->commit();
} catch (Exception $e) {
    $adapter->rollback();
    throw $e;
}
```

#### Hook Integration

[](#hook-integration)

```
// Custom hooks
$hooks->addAction('my_custom_hook', function($data) {
    // Process data
});

$hooks->doAction('my_custom_hook', $data);
```

#### Admin Integration

[](#admin-integration)

```
// Submenu pages
$admin->addSubmenuPage(
    'my-plugin',
    'Settings',
    'Settings',
    'manage_options',
    'my-plugin-settings',
    [$this, 'renderSettings']
);
```

---

🛠️ DEVELOPMENT GUIDELINES
-------------------------

[](#️-development-guidelines)

### Coding Standards

[](#coding-standards)

#### WordPress Integration Best Practices

[](#wordpress-integration-best-practices)

```
// Always use WordPress functions with backslash prefix
$result = \wp_verify_nonce($nonce, $action);

// Use WordPress security functions
$sanitized = \sanitize_text_field($input);

// Check capabilities before actions
if (\current_user_can('manage_options')) {
    // Perform admin action
}

// Use WordPress hooks properly
\add_action('init', [$this, 'initialize']);
```

#### PSR-12 Compliance

[](#psr-12-compliance)

```
