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

Wp Admin Bundle Laravel Package

djvue/wp-admin-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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,
    
  2. 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.).

  3. 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]);
    

Implementation Patterns

Common Workflows

  1. CRUD Operations

    • Create/Update Posts:
      $this->wpClient->createPost(['title' => 'Hello', 'content' => 'World']);
      $this->wpClient->updatePost(123, ['status' => 'publish']);
      
    • Delete Posts:
      $this->wpClient->deletePost(123);
      
  2. Media Handling

    • Upload files:
      $this->wpClient->uploadMedia('/path/to/file.jpg', ['alt_text' => 'Image']);
      
  3. User Management

    • Fetch users:
      $users = $this->wpClient->getUsers(['role' => 'author']);
      
    • Create users:
      $this->wpClient->createUser(['user_login' => 'john', 'user_email' => 'john@example.com']);
      

Integration Tips

  • Laravel Eloquent Sync: Use the bundle to sync WordPress data with Laravel models via observers or events.
  • API Caching: Cache frequent WP API calls using Laravel’s cache system:
    $posts = Cache::remember('wp_posts', now()->addHours(1), function () {
        return $this->wpClient->getPosts();
    });
    
  • Queue Delayed Tasks: Offload heavy WP operations (e.g., media uploads) to queues:
    UploadMediaJob::dispatch($filePath, $metadata)->delay(now()->addMinutes(5));
    

Gotchas and Tips

Pitfalls

  1. Authentication Issues

    • Ensure wp-admin-bundle.php has correct credentials (API key, username/password, or OAuth tokens).
    • If using REST API, verify the WordPress site has the REST API plugin enabled.
  2. Rate Limiting

    • WordPress REST API may throttle requests. Implement exponential backoff in your client:
      try {
          $response = $this->wpClient->getPosts();
      } catch (RateLimitException $e) {
          sleep($e->retryAfter);
          retry();
      }
      
  3. Data Mismatches

    • WordPress and Laravel data structures differ (e.g., created_at vs. date). Normalize responses:
      $post = $this->wpClient->getPost(123);
      $post['created_at'] = Carbon::parse($post['date'])->toDateTimeString();
      

Debugging

  • 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.

Extension Points

  1. Custom Endpoints Extend the client to support non-standard WP REST routes:

    $this->wpClient->customRequest('GET', '/wp-json/custom/v1/data');
    
  2. Middleware Add request/response middleware for logging or transformation:

    $this->wpClient->getMiddleware()->push(function ($request) {
        $request->headers->set('X-Custom-Header', 'value');
    });
    
  3. Event Listeners Listen to WP data changes (e.g., post updates) via Laravel events:

    event(new WordPressPostUpdated($postId, $data));
    
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours