WP-CLI Commands

Teams Included on the Teams plan. Not available on the Lite version. Upgrade →

WP-CLI Commands for ABSPLITTEST

ABSPLITTEST includes comprehensive WP-CLI commands for managing A/B tests from the command line. Perfect for automation, CI/CD pipelines, and developer workflows.

Installation

WP-CLI commands are automatically available when the ABSPLITTEST plugin is active. Ensure you have WP-CLI installed.

Available Commands

1. Create Test

wp absplittest create_test --name="Test Name" --type=magic [options]

Required Parameters:

  • --name - Test title/name
  • --type - Test type: magic, ab_test, css_test, or full_page (not needed with --status=idea)

Optional Parameters:

  • --status - Post status: idea, draft, publish, pending, or complete (default: draft). An idea needs --abst_idea_hypothesis instead of --type.
  • --magic_definition - JSON string for magic test configuration
  • --conversion_page - Conversion page ID or trigger type
  • --target_percentage - Traffic percentage (1-100, default: 100)

Examples:

# Create a draft magic test
wp absplittest create_test --name="Homepage Hero" --type=magic --status=draft

# Create with magic definition
wp absplittest create_test 
  --name="Button Test" 
  --type=magic 
  --magic_definition='[{"original":"Buy Now","variations":["Get Started","Try Free"]}]'

# Create published full page test
wp absplittest create_test 
  --name="Landing Page" 
  --type=full_page 
  --status=publish 
  --conversion_page=123

2. List Tests

wp absplittest list_tests [options]

Optional Parameters:

  • --status - Filter by status: idea, publish, draft, pending, complete, or any
  • --type - Filter by test type
  • --format - Output format: table, csv, json, or yaml

Examples:

# List all tests (table format)
wp absplittest list_tests

# List only published tests
wp absplittest list_tests --status=publish

# Export to JSON
wp absplittest list_tests --format=json > tests.json

# Filter by type
wp absplittest list_tests --type=magic --format=csv

3. Get Test Results

wp absplittest get_results <test_id> [--format=<format>]

Examples:

# View results for test #123
wp absplittest get_results 123

# Export results as JSON
wp absplittest get_results 123 --format=json

# Export as YAML
wp absplittest get_results 123 --format=yaml

4. Update Test Status

wp absplittest update_status <test_id> <status>

Valid Statuses: publish, draft, pending, complete

Examples:

# Publish a test
wp absplittest update_status 123 publish

# Set to draft
wp absplittest update_status 123 draft

5. Duplicate Test

wp absplittest duplicate_test <test_id> [--title=<title>] [--status=<status>] [--format=<format>]

Copies a test’s settings, variations, goals, targeting and audiences into a new test. Results are not copied.

Optional Parameters:

  • --title - Title for the copy (default: the original title with “(Copy)” added)
  • --status - Status for the copy: idea, draft, publish, pending, or complete (default: draft)
  • --format - Output format: plain or json

Examples:

# Duplicate test #123 as a draft
wp absplittest duplicate_test 123

# Duplicate with a new name and start it running
wp absplittest duplicate_test 123 --title="Homepage hero, round 2" --status=publish

6. Plugin Settings

# List every site-wide plugin setting (secrets masked)
wp absplittest get_settings

# Update plugin-wide settings (no test ID)
wp absplittest update_settings --heatmaps_enabled=1 --heatmap_retention_days=14

From version 2.6.0 every site-wide plugin setting can be managed from the command line. See Managing Plugin Settings via REST API, WP-CLI and MCP for the full settings reference.

Automation Examples

Bash Script: Create Multiple Tests

#!/bin/bash
# create-tests.sh

tests=(
  "Homepage Hero:magic"
  "CTA Button:magic"
  "Pricing Page:full_page"
)

for test in "${tests[@]}"; do
  IFS=':' read -r name type <<< "$test"
  wp absplittest create_test --name="$name" --type="$type" --status=draft
done

Cron Job: Daily Test Report

# Add to crontab
0 9 * * * cd /var/www/html && wp absplittest list_tests --status=publish --format=csv > /tmp/daily-tests.csv

CI/CD Integration

# .github/workflows/deploy.yml
- name: Publish A/B Tests
  run: |
    wp absplittest update_status 123 publish
    wp absplittest update_status 124 publish

Getting Help

For detailed help on any command:

wp absplittest <command> --help

See Also

Leave a Comment

You must be logged in to post a comment.