A comprehensive Laravel package that seamlessly integrates WordPress database functionality into Laravel applications with full Filament admin panel support.
- π WordPress Database Integration: Connect to WordPress database with Eloquent models
- π¨ Filament Admin Panel: Complete admin interface for managing WordPress content
- π Dashboard Widgets: Real-time statistics and recent content widgets
- π Advanced Queries: Easy-to-use facade for complex WordPress queries
- π·οΈ Relationships: Full relationship mapping between WordPress entities
- βοΈ Configurable: Publishable config with database connection options
- Install the package via Composer:
composer require mrdulal/laravel-wp-connector
- Publish the configuration file:
php artisan vendor:publish --tag=wp-connector-config
- Configure your WordPress database connection in
config/wordpress.php
:
return [
'enabled' => true,
'host' => env('WP_DB_HOST', '127.0.0.1'),
'port' => env('WP_DB_PORT', '3306'),
'database' => env('WP_DB_DATABASE', 'wordpress'),
'username' => env('WP_DB_USERNAME', 'root'),
'password' => env('WP_DB_PASSWORD', ''),
'prefix' => env('WP_DB_PREFIX', 'wp_'),
];
- Add your WordPress database credentials to your
.env
file:
WP_CONNECTOR_ENABLED=true
WP_DB_HOST=127.0.0.1
WP_DB_PORT=3306
WP_DB_DATABASE=wordpress
WP_DB_USERNAME=root
WP_DB_PASSWORD=your_password
WP_DB_PREFIX=wp_
use MrDulal\WpConnector\Facades\Wp;
// Get recent published posts with authors
$posts = Wp::posts()->published()->with('author')->latest()->take(5)->get();
// Get posts by category
$categoryPosts = Wp::postsByCategory('Technology');
// Get posts by tag
$tagPosts = Wp::postsByTag('Laravel');
// Get user count
$userCount = Wp::userCount();
// Get comment count
$commentCount = Wp::commentCount();
use MrDulal\WpConnector\Models\WpPost;
use MrDulal\WpConnector\Models\WpUser;
use MrDulal\WpConnector\Models\WpComment;
// Get a post with its author and comments
$post = WpPost::with(['author', 'comments'])->find(1);
// Get user's posts
$user = WpUser::find(1);
$userPosts = $user->posts()->published()->get();
// Get post comments
$post = WpPost::find(1);
$comments = $post->comments()->approved()->get();
// Get post terms (categories/tags)
$post = WpPost::find(1);
$categories = $post->terms()->categories()->get();
$tags = $post->terms()->tags()->get();
// Get post meta
$post = WpPost::find(1);
$featuredImage = $post->getMeta('_thumbnail_id');
$customField = $post->getMeta('custom_field', 'default_value');
// Set post meta
$post->setMeta('custom_field', 'custom_value');
// Get user meta
$user = WpUser::find(1);
$firstName = $user->getMeta('first_name');
$lastName = $user->getMeta('last_name');
use MrDulal\WpConnector\Facades\Wp;
// Get WordPress options
$siteName = Wp::option('blogname');
$siteDescription = Wp::option('blogdescription');
// Set WordPress options
Wp::setOption('custom_option', 'custom_value');
The package includes complete Filament resources for managing WordPress content:
- Users: Manage WordPress users with full CRUD operations
- Posts: Create, edit, and manage WordPress posts and pages
- Comments: Moderate and manage comments
- Terms: Manage categories, tags, and custom taxonomies
- Recent Posts Widget: Shows latest published posts
- User Count Widget: Displays user statistics
- Comment Count Widget: Shows comment statistics
The package automatically sets up a WordPress database connection. You can customize the connection settings in the config file.
'filament' => [
'navigation_group' => 'WordPress',
'navigation_sort' => 1,
'enable_widgets' => true,
],
- Primary key:
ID
- Relationships:
posts()
,comments()
,meta()
- Scopes:
published()
- Primary key:
ID
- Relationships:
author()
,comments()
,terms()
,meta()
- Scopes:
published()
,type()
,byAuthor()
- Primary key:
comment_ID
- Relationships:
post()
,user()
,parent()
,children()
,meta()
- Scopes:
approved()
,byPost()
- Primary key:
term_id
- Relationships:
posts()
,taxonomy()
,meta()
- Scopes:
categories()
,tags()
// Get posts with specific meta
$posts = Wp::posts()
->whereHas('meta', function ($query) {
$query->where('meta_key', 'featured')
->where('meta_value', '1');
})
->published()
->get();
// Get users with specific capabilities
$admins = Wp::users()
->whereHas('meta', function ($query) {
$query->where('meta_key', 'wp_capabilities')
->where('meta_value', 'like', '%administrator%');
})
->get();
// Eager load relationships
$posts = Wp::posts()
->with(['author', 'comments', 'terms'])
->published()
->get();
// Load specific relationships
$post = WpPost::with(['author.meta', 'comments.user'])->find(1);
- PHP 8.1+
- Laravel 10.0+
- Filament 3.0+
- WordPress database
This package is open-sourced software licensed under the MIT license.
Please see CONTRIBUTING.md for details.
Please see CHANGELOG.md for more information on what has changed recently.