Install the Bundle Add the bundle to your Laravel project via Composer:
composer require djvue/wp-admin-bundle
Register it in config/app.php under providers:
Djvue\WordPressBundle\WordPressServiceProvider::class,
Configure the Bundle Publish the config file:
php artisan vendor:publish --provider="Djvue\WordPressBundle\WordPressServiceProvider"
Update config/wp-admin-bundle.php with your WordPress site details (URL, credentials, etc.).
First Use Case: Fetching WordPress Data
Inject the WordPressClient into a controller or service:
use Djvue\WordPressBundle\Client\WordPressClient;
public function __construct(WordPressClient $wpClient) {
$this->wpClient = $wpClient;
}
Fetch posts:
$posts = $this->wpClient->getPosts(['per_page' => 5]);
CRUD Operations
$this->wpClient->createPost(['title' => 'Hello', 'content' => 'World']);
$this->wpClient->updatePost(123, ['status' => 'publish']);
$this->wpClient->deletePost(123);
Media Handling
$this->wpClient->uploadMedia('/path/to/file.jpg', ['alt_text' => 'Image']);
User Management
$users = $this->wpClient->getUsers(['role' => 'author']);
$this->wpClient->createUser(['user_login' => 'john', 'user_email' => 'john@example.com']);
$posts = Cache::remember('wp_posts', now()->addHours(1), function () {
return $this->wpClient->getPosts();
});
UploadMediaJob::dispatch($filePath, $metadata)->delay(now()->addMinutes(5));
Authentication Issues
wp-admin-bundle.php has correct credentials (API key, username/password, or OAuth tokens).Rate Limiting
try {
$response = $this->wpClient->getPosts();
} catch (RateLimitException $e) {
sleep($e->retryAfter);
retry();
}
Data Mismatches
created_at vs. date). Normalize responses:
$post = $this->wpClient->getPost(123);
$post['created_at'] = Carbon::parse($post['date'])->toDateTimeString();
Enable Guzzle Debugging: Add to wp-admin-bundle.php:
'debug' => env('WP_DEBUG', false),
Check logs in storage/logs/laravel.log for HTTP errors.
Validate Endpoints: Use Postman or cURL to test WordPress REST endpoints directly before debugging the bundle.
Custom Endpoints Extend the client to support non-standard WP REST routes:
$this->wpClient->customRequest('GET', '/wp-json/custom/v1/data');
Middleware Add request/response middleware for logging or transformation:
$this->wpClient->getMiddleware()->push(function ($request) {
$request->headers->set('X-Custom-Header', 'value');
});
Event Listeners Listen to WP data changes (e.g., post updates) via Laravel events:
event(new WordPressPostUpdated($postId, $data));
How can I help you explore Laravel packages today?