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

Entity Command Laravel Package

wp-cli/entity-command

WP-CLI commands to manage WordPress entities: comments, menus, options, posts, sites, terms, and users. Create, update, delete, and moderate content from the command line, with support for listing and bulk operations.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require wp-cli/entity-command
    

    Ensure WP-CLI is installed globally (wp --version) and WordPress is accessible via wp commands.

  2. First Use Case: List all comments for a post (e.g., ID 123) in JSON format:

    wp comment list --post_id=123 --format=json
    
  3. Key Files:

    • README.md: Command reference and examples.
    • features/: Behat tests for edge cases.
    • tests/: PHPUnit unit tests for core logic.

Implementation Patterns

Core Workflows

  1. CRUD Operations:

    • Create: Use wp comment create with associative args (e.g., --comment_post_ID=123 --comment_content="Test").
    • Update: Chain wp comment get + wp comment update:
      wp comment get 456 --field=comment_content | xargs -I {} wp comment update 456 --comment_content={}
      
    • Delete: Bulk delete spam comments:
      wp comment delete $(wp comment list --status=spam --format=ids) --force
      
  2. Querying Data:

    • Filter comments by meta (e.g., custom fields):
      wp comment list --meta_key=custom_field --meta_value="value" --fields=comment_ID,comment_author
      
    • Export to CSV for analysis:
      wp comment list --format=csv > comments.csv
      
  3. Meta Management:

    • Add/Update meta for a comment (e.g., track moderation status):
      wp comment meta add 789 moderation_status "pending" --format=json
      
    • Patch nested JSON meta (WordPress 6.9+):
      wp comment meta patch update 789 review_data "feedback" "Thanks for the input"
      
  4. Automation:

    • Generate test data:
      wp comment generate --count=50 --post_id=123 --format=ids | xargs -I % wp comment meta add % user_role "subscriber"
      
    • Pipe IDs to batch operations:
      wp comment list --status=trash --format=ids | xargs -I % wp comment delete %
      
  5. Notes (WordPress 6.9+):

    • Create/resolve block notes:
      wp comment create --comment_post_ID=123 --comment_type=note --comment_content="Needs review" --comment_parent=456
      wp comment meta add 999 _wp_note_status resolved
      

Integration Tips

  • Laravel Artisan Integration: Use exec() or Process facade to call WP-CLI commands from Laravel:
    $output = Artisan::call('wp comment count 123', ['format' => 'json']);
    $comments = json_decode($output, true);
    
  • Custom Commands: Extend the package by creating a custom WP-CLI command that leverages its query system (e.g., wp myplugin sync-comments).

Gotchas and Tips

Pitfalls

  1. Permissions:

    • Commands like wp comment delete --force require admin privileges. Use --user=admin if needed:
      wp comment delete 123 --force --user=admin
      
    • Meta operations may fail if unfiltered_html capability is missing.
  2. Data Serialization:

    • JSON meta values must be properly escaped. Use --format=json for complex data:
      wp comment meta add 456 review_data '{"status": "approved", "notes": ["Great work!"]}' --format=json
      
    • Plucking nested values requires exact key paths:
      wp comment meta pluck 456 review_data "notes.0"  # Fails if path is incorrect
      
  3. WordPress Version Quirks:

    • Notes (comment_type=note) are only supported in WordPress 6.9+. Check version first:
      wp core version | grep -q "6.9" || echo "Notes not supported"
      
    • Multisite: Use --network flag for network-wide operations:
      wp comment list --network --status=spam
      
  4. Performance:

    • Avoid wp comment list without limits on large sites. Use --number=100:
      wp comment list --number=100 --fields=comment_ID,comment_author
      
    • Batch meta updates with xargs to reduce overhead.
  5. Edge Cases:

    • Trashed comments may not appear in queries unless --status=trash is specified.
    • Parent-child relationships (e.g., replies) require --comment_parent=ID.

Debugging Tips

  1. Dry Runs: Use --porcelain to extract raw IDs for scripting:
    wp comment list --status=spam --format=ids --porcelain
    
  2. Logging: Enable WP-CLI debug mode:
    WP_CLI_DEBUG=1 wp comment create --comment_post_ID=123 --comment_content="Test"
    
  3. Validation: Check comment existence before operations:
    wp comment exists 456 || echo "Comment not found"
    

Extension Points

  1. Custom Fields: Extend meta handling by adding a Laravel service:
    // app/Services/WPCommentMeta.php
    public function addCustomMeta(int $commentId, string $key, $value): void
    {
        exec("wp comment meta add {$commentId} {$key} '{$value}' --format=json");
    }
    
  2. Event Hooks: Trigger Laravel events on comment actions (e.g., via wp-cli/entity-command's after_comment_create hook if available).
  3. Testing: Mock WP-CLI commands in Laravel tests:
    $this->artisan('wp comment generate --count=1 --post_id=123')
         ->expectsQuestion('Confirm?', 'yes')
         ->assertExitCode(0);
    

Configuration Quirks

  • Default Formats: Override default output formats in wp-cli.yml:
    formats:
      table: "yaml"  # Force YAML output for all tables
    
  • Aliases: Create shell aliases for frequent commands:
    alias wpcc='wp comment count'
    alias wpcl='wp comment list'
    

```markdown
### Laravel-Specific Tips
1. **Service Provider**:
   Bind WP-CLI commands to Laravel’s container for dependency injection:
   ```php
   // app/Providers/WPCLIServiceProvider.php
   public function register()
   {
       $this->app->singleton('wp-cli', function () {
           return new WPCLICommand();
       });
   }
  1. Task Scheduling: Use Laravel’s scheduler to run WP-CLI commands periodically:
    // app/Console/Kernel.php
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('wp comment delete --status=spam --force')
                 ->dailyAt('03:00');
    }
    
  2. Query Builder Integration: Sync Laravel models with WP-CLI data:
    // app/Models/Comment.php
    public static function syncWithWP()
    {
        $comments = json_decode(exec('wp comment list --format=json'), true);
        foreach ($comments as $data) {
            self::updateOrCreate(['id' => $data['comment_ID']], $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.
andydefer/laravel-cluster
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
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views