Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Framework Laravel Package

wpstarter/framework

WPStarter Framework is a Laravel-inspired PHP framework for building WordPress apps and plugins with modern patterns. It provides familiar helpers, service container features, and a clean structure to speed development while staying compatible with WordPress.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require wpstarter/framework
    

    Publish the configuration (if needed):

    php artisan vendor:publish --provider="WpStarter\Framework\ServiceProvider"
    
  2. Bootstrapping WordPress Register the WordPress bootstrap in app/Providers/AppServiceProvider.php:

    use WpStarter\Framework\Facades\WordPress;
    
    public function boot()
    {
        WordPress::boot();
    }
    
  3. First Use Case: Accessing WordPress Data Fetch a post by ID in a Laravel controller:

    use WpStarter\Framework\Facades\WordPress;
    
    public function showPost($id)
    {
        $post = WordPress::post()->find($id);
        return response()->json($post);
    }
    
  4. Key Facades

    • WordPress: Core facade for bootstrapping and utilities.
    • WordPress::post(): Interact with posts.
    • WordPress::user(): Manage users.
    • WordPress::option(): Handle options.

Implementation Patterns

1. Hybrid Laravel-WordPress Controllers

Extend Laravel controllers to interact with WordPress:

use WpStarter\Framework\Facades\WordPress;

class PostController extends Controller
{
    public function index()
    {
        $posts = WordPress::post()->all(['posts_per_page' => 10]);
        return view('posts.index', compact('posts'));
    }
}

2. Service Layer Integration

Create a service to abstract WordPress logic:

class PostService
{
    public function __construct(protected $wpPost)
    {
        $this->wpPost = WordPress::post();
    }

    public function getPublishedPosts()
    {
        return $this->wpPost->all(['post_status' => 'publish']);
    }
}

3. Middleware for WordPress Context

Restrict routes to logged-in WordPress users:

use WpStarter\Framework\Facades\WordPress;

class WordPressAuthMiddleware
{
    public function handle($request, Closure $next)
    {
        if (!WordPress::user()->isLoggedIn()) {
            abort(403);
        }
        return $next($request);
    }
}

4. Event Listeners for WordPress Actions

Hook into WordPress events (e.g., wp_loaded):

use WpStarter\Framework\Facades\WordPress;

WordPress::on('wp_loaded', function () {
    // Custom logic after WordPress loads
});

5. Blade Directives for WordPress

Extend Blade to output WordPress data:

Blade::directive('wpPost', function ($expression) {
    return "<?php echo WpStarter\Framework\Facades\WordPress::post()->find({{$expression}})->title; ?>";
});

Usage:

<h1>{{ wpPost(1) }}</h1>

6. API Routes with WordPress Data

Leverage Laravel’s API resources:

Route::get('/posts', function () {
    return PostResource::collection(WordPress::post()->all());
});

Gotchas and Tips

Pitfalls

  1. Bootstrap Timing

    • WordPress must be booted before any WordPress-specific logic runs. Avoid calling WordPress::post() in service providers or before boot() in AppServiceProvider.
    • Fix: Ensure WordPress::boot() is called in boot() (not register()).
  2. Caching Conflicts

    • WordPress and Laravel may use different caching backends. Clear both caches after major changes:
      php artisan cache:clear
      wp cache flush  # If using WP-CLI
      
  3. Query Conflicts

    • Avoid mixing raw WordPress queries ($wpdb) with Eloquent queries in the same request. Use transactions or separate them clearly.
  4. Plugin/Theme Overrides

    • WordPress plugins/themes may override core functions. Test thoroughly in a staging environment.
  5. Multisite Limitations

    • The package may not fully support WordPress Multisite. Check wp-config.php for WP_ALLOW_MULTISITE and test manually.

Debugging Tips

  1. Enable WordPress Debugging Add to wp-config.php:

    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true); // Logs to /wp-content/debug.log
    
  2. Laravel-WordPress Logs Use Laravel’s logging for hybrid issues:

    \Log::info('WordPress post ID:', ['id' => $post->ID]);
    
  3. Check Hooks/Filters Use WordPress::hasAction('hook_name') to verify if a hook exists before adding listeners.


Extension Points

  1. Custom WordPress Facades Extend the package by creating your own facades:

    class CustomWordPress extends \WpStarter\Framework\Facades\WordPress
    {
        public static function customMethod()
        {
            return self::post()->find(1)->custom_field;
        }
    }
    
  2. Override WordPress Classes Use Laravel’s binding system to replace WordPress classes (e.g., WP_Query):

    $this->app->bind('wp_query', function () {
        return new CustomWPQuery();
    });
    
  3. Add Custom WPStarter Services Register additional services in the config:

    'services' => [
        'custom' => \WpStarter\Framework\Services\CustomService::class,
    ],
    

    Then access via:

    WordPress::service('custom')->doSomething();
    
  4. Modify Query Parameters Extend the query builder for custom WordPress queries:

    WordPress::extend('post', function ($query) {
        $query->addParam('custom_param', 'value');
        return $query;
    });
    

Performance Tips

  1. Lazy-Load WordPress Defer WordPress bootstrapping until needed (e.g., in a middleware or route group):

    Route::middleware(['wp.bootstrap'])->group(function () {
        // Routes requiring WordPress
    });
    
  2. Batch Queries Use WordPress::post()->batch() for large datasets to reduce memory usage.

  3. Cache WordPress Data Cache frequent WordPress queries in Laravel’s cache:

    $posts = Cache::remember('wp_posts', now()->addHours(1), function () {
        return WordPress::post()->all();
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity