WP-CLI - Creative Commands

AffiliateWP 1.9+ brings creatives management to the command-line with the introduction of wp affwp creative WP-CLI commands.

Usage: wp affwp creative <command>

There are five creative sub-commands to choose from:

  • create – Creates a creative account.
  • delete – Deletes a creative.
  • get – Retrieves a creative object or field(s) by ID.
  • list – Displays a list of creatives.
  • update – Updates an existing creative.

Clicking any of the sub-command listed above will take you to more comprehensive documentation about the arguments they require and options available.

Be careful!

Sub-commands like delete or update have the very real possibility of wreaking havoc on your AffiliateWP data when not used with caution. Make sure you know what you're changing or removing, and heed confirmation messages when executing sub-commands.


create

The affwp creative create command is used to create new creatives.

Usage: wp affwp creative create [--name=<name>] [--description=<description>] [--link=<URL>] [--text=<text>] [--image=<URL>] [--status=<status>]

Options

All options are optional unless noted otherwise.

  • --name
    Required. Name identifier for the creative.
  • --description
    Description for the creative.
  • --link
    URL the creative should link to.
  • --text
    Text for the creative.
  • --image
    Image URL (local or external) to use for the creative.
  • --status
    Status for the creative. Accepts 'active' or 'inactive'. Default 'active'.

Examples

# Creates a creative linking to http://affiliatewp.com
wp affwp creative create --name=AffiliateWP --link=http://affiliatewp.com

# Creates a creative using a locally-hosted image.
wp affwp creative create --name='Special Case' --image=https://example.org/my-image.jpg

# Create a creative with a status of 'inactive'
wp affwp creative create --name='My Creative' --status=inactive

delete

The affwp creative delete sub-command is used to delete creatives.

wp affwp creative delete <creative_id>

Options

All options are optional unless noted otherwise.

  • <creative_id> (required)
    Creative ID.

Examples

# Deletes the creative with ID 20
wp affwp creative delete 20

get

The affwp creative get sub-command is used to retrieve a single creative.

Usage: wp affwp creative get <id> [--field=<field>] [--fields=<fields>] [--format=<format>]

Options

All options are optional unless noted otherwise.

  • <id>(required)
    The creative ID to retrieve.
  • --field
    Instead of returning the whole creative object, returns the value of a single field.
  • --fields
    Limit the output to specific fields. Defaults to all fields.
  • --format
    Accepted values: table, json, csv, yaml. Default: table

Examples

# Retrieve creative ID 12.
wp affwp creative get 12

list

The affwp creative list sub-command is used to list out affiliates based on given criteria.

Usage: wp affwp creative list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]

Options

All options are optional unless noted otherwise.

  • --field
    One or more args to pass to get_creatives().
  • --field
    Prints the value of a single field for each creative.
  • --fields
    Limit the output to specific creative fields.
  • --format
    Accepted values: table, csv, json, count, ids, yaml. Default: table
Available Fields

These fields will be displayed by default for each creative:

  • ID (alias for creative_id)
  • name
  • url
  • image
  • status
  • date

Optionally Available Fields

  • description
  • text

Examples

# List all creatives by name.
wp affwp creative list --field=name

# List all creative IDs with an 'inactive' status.
wp affwp creative list --status=inactive --format=ids

# List all creatives and display only the ID and image fields.
wp affwp creative list --fields=ID,image

update

The affwp creative update sub-command is used to update a single affiliate based on given criteria.

Usage: wp affwp creative update [--name=<name>] [--description=<description>] [--link=<URL>] [--text=<text>] [--image=<URL>] [--status=<status>]

Options

All options are optional unless noted otherwise.

  • --name
    Name identifier for the creative.
  • --description
    Description for the creative.
  • --link
    URL the creative should link to.
  • --text
    Text for the creative.
  • --image
    Image URL (local or external) to use for the creative.
  • --status
    Status for the creative. Accepts 'active' or 'inactive'. Default 'active'.

Examples

# Updates creative ID 300 with a new name 'New Name'
wp affwp creative update 300 --name='New Name'

# Updates creative ID 53 with a new image.
wp affwp creative update 53 --image=https://example.org/my-other-image.jpg

# Updates creative ID 199's status to inactive
wp affwp creative update 199 --status=inactive