WP-CLI Commands

AffiliateWP 1.9 and later offers a variety of WP-CLI commands for managing affiliate, creative, payout, referral, visit, and system data from the command-line on the fly.

Getting Started

WP-CLI command support in AffiliateWP is broken up into two main groups:

  1. System commands, executed via wp affwp
  2. Object commands, executed via wp affwp [object] .

To list all system and object command groups, execute
wp help affwp. It will output documentation similar to this:


System-level Commands

System-level commands can be accessed via the top-level command namespace,
wp affwp. They include:

  • wp affwp details
    Prints out main AffiliateWP configuration details, including the AffiliateWP version, license status, active integrations, key settings, and more.

    – Execute
    wp help affwp details to find out more.
  • wp affwp stats
    Prints out the total number of affiliates, creatives, payouts, referrals, and visits for the current site. An optional
    –global parameter pulls global stats for every site in a multisite network.
    – Execute
    wp help affwp stats to find out more.
  • wp affwp debug
    Prints out the contents of the
    affwp-debug.log file generated when Debug Mode is enabled in the AffiliateWP settings. An optional –clear parameter makes clearing the debug log a snap.
    – Execute
    wp help affwp debug to find out more.
  • wp affwp info
    Similar to the
    wp affwp details and wp affwp debug commands, this command prints out the contents of the System Info log used primarily for troubleshooting purposes when you contact support.
    – Execute
    wp help affwp info to find out more.

Object-level Commands

Object-level WP-CLI commands allow for robust management of affiliates, creatives, payouts, referrals, and visits from the command line. Sub-commands are grouped by object, accessed via wp affwp [object] . They include:

  • wp affwp affiliate
    Commands:
    create, delete, get, list, update

    Documentation
  • wp affwp creative
    Commands:
    create, delete, get, list, update

    Documentation
  • wp affwp payout
    Commands:
    create, delete, get, list, update

    Documentation
  • wp affwp referral
    Commands:
    create, delete, get, list, update

    Documentation
  • wp affwp visit
    Commands:
    create, delete, get, list, update

    Documentation

Click the links in the list above to navigate to pages containing much more comprehensive documentation on accepted options and available sub-commands. 


Additional Help

To preview help documentation for any core- or system-level commands,
try prefixing the command chain with help. For instance:

wp help affwp stats

The above will output the help page for the wp affwp stats command. Like so:

Affiliate Commands

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

Usage: wp affwp affiliate 
 <sub-command>

 </sub-command>

There are five affiliate sub-commands to choose from:

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

Clicking any of the commands 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 affiliate create sub-command is used to create new affiliate accounts.

Usage: wp affwp affiliate create 
 <username|user_id>
   [--payment_email=
  <email>
   ] [--rate=
   <float>
    ] [--rate_type=
    <type>
     ] [--status=
     <status>
      ] [--earnings=
      <number>
       ] [--referrals=
       <number>
        ] [--visits=
        <number>
         ] 
        </number>
       </number>
      </number>
     </status>
    </type>
   </float>
  </email>
 </username|user_id>

Note: create assumes you already added a user account and have a user ID or username to pass as the first argument, which is required.

Options

All options are optional unless noted otherwise.

  • username|user_id (required)
    Username or ID for an existing user.
  • –payment_email
    Affiliate payment email. If not specified, the user account email will be used.
  • –rate
    Referral rate. If not specified, the default rate will be used.
  • –rate_type
    Referral rate type. Accepts ‘percentage’, ‘flat’, or any custom rate type. If not specified, the default rate type will be used.
  • –status
    Affiliate status. Accepts ‘active’, ‘inactive’, or ‘pending’. If not specified, and new affiliates require approval per global settings, ‘pending’ will used. Otherwise, the default status of ‘active’ will be used.
  • –earnings
    Affiliate earnings. If not specified, 0 will be used.
  • –referrals
    Number of referrals. If not specified, 0 will be used.
  • –visits
    Number of visits. If not specified, 0 will be used.

Examples

# Creates an affiliate with a 20% referral rate.
wp affwp affiliate create edduser1 --rate=0.2 --rate_type=percentage


# Creates an affiliate with the default referral rate, rate type,
#specified payment email, and 20 visits.
wp affwp affiliate create woouser1 [email protected] --visits=20


# Creates an affiliate for user ID 142 with a status of 'pending'.
wp affwp affiliate create 142 --status=pending

delete

The affwp affiliate delete sub-command is used to delete affiliate accounts.

Usage: wp affwp affiliate delete 
 <username|affiliate_id>
   [--delete_data] [--delete_user] [--network]

 </username|affiliate_id>

Options

All options are optional unless noted otherwise.

  • (required)
    Username or affiliate ID.
  • –delete_data
    Whether to delete affiliate data, such as referrals, visits, etc. Data will be retained by default.
  • –delete_user
    Whether to delete the user account associated with the affiliate account. Default false.
  • –network
    Whether to delete the user account network-wide (multisite only). Ignored if –delete_user is omitted. Use with caution. Default false.

Examples

# Deletes the affiliateuser03 account, retaining its associated data and user account
wp affwp affiliate delete affiliateuser03

# Deletes the affiliate with ID 636 along with its associated data
wp affwp affiliate delete 636 --delete_data

# Deletes the networkuser25 affiliate and its associated user account
wp affwp affiliate delete networkuser25 --delete_user

get

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

Usage: wp affwp affiliate get 
 <affiliate_id>
   [--field=
  <field>
   ] [--fields=
   <fields>
    ] [--format=
    <format>
     ] 
    </format>
   </fields>
  </field>
 </affiliate_id>

Options

All options are optional unless noted otherwise.

  • (required)
    The affiliate ID to retrieve.
  • –field
    Instead of returning the whole affiliate 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

# save the affiliate field value to a file
wp post get 12 --field=earnings > earnings.txt

list

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

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

Options

All options are optional unless noted otherwise.


One or more args to pass to get_affiliates(). ‘user_login’ and ‘name’ are not affiliate fields and will be ignored.

  • –field
    Prints the value of a single field for each affiliate.
  • –fields
    Limit the output to specific affiliate fields.
  • –format
    Accepted values: table, csv, json, count, ids, yaml. Default: table
Available Fields

These fields will be displayed by default for each affiliate:

  • ID (alias for affiliate_id)
  • name
  • user_login
  • user_id
  • rate
  • rate_type
  • status
  • earnings
  • referrals
  • visits
  • date_registered

Examples

# Lists affiliates by affiliate_id
wp affwp affiliate list --field=affiliate_id

# Outputs a table with affiliate_id, rate, and earnings columns for affiliates set
# as the 'percentage' rate type
wp affwp affiliate list --rate_type=percentage --fields=affiliate_id,rate,earnings

# Outputs a table with standard user_login, affiliate_id, earnings, referrals, and
# visits columns, ordered by status ascending.
affwp affiliate list --orderby=status --order=ASC

update

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

Usage: wp affwp affiliate update 
 <username|id>
   [--account_email=
  <email>
   ] [--payment_email=
   <email>
    ] [--rate=
    <float>
     ] [--rate_type=
     <type>
      ] [--status=
      <status>
       ] 
      </status>
     </type>
    </float>
   </email>
  </email>
 </username|id>

Options

All options are optional unless noted otherwise.


  • Username or affiliate ID.
  • –account_email
    Affiliate account email.
  • –payment_email
    Affiliate payment email.
  • –rate
    Referral rate.
  • –rate_type
    Referral rate type. Accepts ‘percentage’, ‘flat’, or any custom rate type.
  • –status
    Affiliate status. Accepts ‘active’, ‘inactive’, ‘pending’, or ‘rejected’.

Examples

# Updates affiliateuser20 to a 0.05 referral rate
wp affwp affiliate update affiliateuser20 --rate=0.05

# Updates the status for affiliate 64 to 'inactive'
wp affwp affiliate update 64 --status='inactive'

# Updates woouserftw's user account email to [email protected]
wp affwp affiliate update woouserftw [email protected]

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>
       ] 
      </status>
     </url>
    </text>
   </url>
  </description>
 </name>

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 https://affiliatewp.com
wp affwp creative create --name=AffiliateWP --link=https://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>

 </creative_id>

Options

All options are optional unless noted otherwise.

  • (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>
     ] 
    </format>
   </fields>
  </field>
 </id>

Options

All options are optional unless noted otherwise.

  • (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>
      ] 
     </format>
    </fields>
   </field>
  </value>
 </field>

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>
       ] 
      </status>
     </url>
    </text>
   </url>
  </description>
 </name>

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

Payout Commands

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

Usage: wp affwp payout 
 <sub-command>

 </sub-command>

There are five affiliate sub-commands to choose from:

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

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 affiliate create sub-command is used to create new affiliate accounts.

Usage: wp affwp payout create

Note: create assumes you already added a user account and have a user ID or username to pass as the first argument, which is required.

Options

All options are optional unless noted otherwise.

  • username|user_id (required)
    Username or ID for an existing user.
  • –payment_email
    Affiliate payment email. If not specified, the user account email will be used.
  • –rate
    Referral rate. If not specified, the default rate will be used.
  • –rate_type
    Referral rate type. Accepts ‘percentage’, ‘flat’, or any custom rate type. If not specified, the default rate type will be used.
  • –status
    Affiliate status. Accepts ‘active’, ‘inactive’, or ‘pending’. If not specified, and new affiliates require approval per global settings, ‘pending’ will used. Otherwise, the default status of ‘active’ will be used.
  • –earnings
    Affiliate earnings. If not specified, 0 will be used.
  • –referrals
    Number of referrals. If not specified, 0 will be used.
  • –visits
    Number of visits. If not specified, 0 will be used.

Examples

# Creates an affiliate with a 20% referral rate.
wp affwp affiliate create edduser1 --rate=0.2 --rate_type=percentage


# Creates an affiliate with the default referral rate, rate type,
#specified payment email, and 20 visits.
wp affwp affiliate create woouser1 [email protected] --visits=20


# Creates an affiliate for user ID 142 with a status of 'pending'.
wp affwp affiliate create 142 --status=pending

delete

The affwp affiliate delete sub-command is used to delete affiliate accounts.

Usage: wp affwp affiliate delete 
 <username|affiliate_id>
   [--delete_data] [--delete_user] [--network]

 </username|affiliate_id>

Options

All options are optional unless noted otherwise.

  • (required)
    Username or affiliate ID.
  • –delete_data
    Whether to delete affiliate data, such as referrals, visits, etc. Data will be retained by default.
  • –delete_user
    Whether to delete the user account associated with the affiliate account. Default false.
  • –network
    Whether to delete the user account network-wide (multisite only). Ignored if –delete_user is omitted. Use with caution. Default false.

Examples

# Deletes the affiliateuser03 account, retaining its associated data and user account
wp affwp affiliate delete affiliateuser03

# Deletes the affiliate with ID 636 along with its associated data
wp affwp affiliate delete 636 --delete_data

# Deletes the networkuser25 affiliate and its associated user account
wp affwp affiliate delete networkuser25 --delete_user

get

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

Usage: wp affwp affiliate get 
 <affiliate_id>
   [--field=
  <field>
   ] [--fields=
   <fields>
    ] [--format=
    <format>
     ] 
    </format>
   </fields>
  </field>
 </affiliate_id>

Options

All options are optional unless noted otherwise.

  • (required)
    The affiliate ID to retrieve.
  • –field
    Instead of returning the whole affiliate 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

# save the affiliate field value to a file
wp post get 12 --field=earnings > earnings.txt

list

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

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

Options

All options are optional unless noted otherwise.


One or more args to pass to get_affiliates(). ‘user_login’ and ‘name’ are not affiliate fields and will be ignored.

  • –field
    Prints the value of a single field for each affiliate.
  • –fields
    Limit the output to specific affiliate fields.
  • –format
    Accepted values: table, csv, json, count, ids, yaml. Default: table
Available Fields

These fields will be displayed by default for each affiliate:

  • ID (alias for affiliate_id)
  • name
  • user_login
  • user_id
  • rate
  • rate_type
  • status
  • earnings
  • referrals
  • visits
  • date_registered

Examples

# Lists affiliates by affiliate_id
wp affwp affiliate list --field=affiliate_id

# Outputs a table with affiliate_id, rate, and earnings columns for affiliates set
# as the 'percentage' rate type
wp affwp affiliate list --rate_type=percentage --fields=affiliate_id,rate,earnings

# Outputs a table with standard user_login, affiliate_id, earnings, referrals, and
# visits columns, ordered by status ascending.
affwp affiliate list --orderby=status --order=ASC

update

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

Usage: wp affwp affiliate update 
 <username|id>
   [--account_email=
  <email>
   ] [--payment_email=
   <email>
    ] [--rate=
    <float>
     ] [--rate_type=
     <type>
      ] [--status=
      <status>
       ] 
      </status>
     </type>
    </float>
   </email>
  </email>
 </username|id>

Options

All options are optional unless noted otherwise.

Referral Commands

Referral management is available via the command-line with the introduction of the wp affwp referral WP-CLI command.

Usage: wp affwp referral 
 <sub-command>

 </sub-command>

There are five referral sub-commands to choose from:

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

Clicking any of the sub-commands 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 referral create sub-command is used to create new referrals.

Usage: wp affwp referral create 
 <username|id>
   [--amount=
  <number>
   ] [--description=
   <description>
    ] [--reference=
    <reference>
     ] [--context=
     <context>
      ] [--status=
      <status>
       ] 
      </status>
     </context>
    </reference>
   </description>
  </number>
 </username|id>

Note: create assumes you already added a user account and have a user ID or username to pass as the first argument, which is required.

Options

All options are optional unless noted otherwise.

  • username|affiliate_id (required)
    Username or affiliate ID for an existing affiliate with whom to associate the created referral.
  • –amount
    Referral amount.
  • –description
    Referral description. 
  • –reference
    Referral reference. Typically this will be a link or other data which points to the originating transaction, such as an order ID.
  • –status
    Referral status. Accepts ‘pending’, ‘rejected’, ‘paid’, or ‘unpaid’. If not specified, the AffiliateWP default of ‘pending’ will be used.
  • –context
    The context of the referral.

Examples

# Creates a referral with a $1.00 referral amount.
wp affwp referral create edduser1 --amount=1.00


# Creates a referral for user ID 5, with an amount of 3.00, a description of 'Big Sale', and a reference of '123'
wp affwp referral create 5 --amount=3 --description='Big Sale' --reference=123


# Creates a referral for user ID 142 with a status of 'rejected'.
wp affwp referral create 142 --status=rejected

delete

The affwp referral delete sub-command is used to delete referrals.

Usage: wp affwp referral delete 
 <username|affiliate_id>
   [--delete_data] [--delete_user] [--network]

 </username|affiliate_id>

Options

  • (required)
    Referral ID.

Examples

# Deletes the referral with an ID of 123
wp affwp referral delete 123

get

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

Usage: wp affwp affiliate get 
 <affiliate_id>
   [--field=
  <field>
   ] [--fields=
   <fields>
    ] [--format=
    <format>
     ] 
    </format>
   </fields>
  </field>
 </affiliate_id>

Options

All options are optional unless noted otherwise.

  • The referral ID to retrieve.
  • –field=   Instead of returning the whole referral 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

Usage: # save the referral field value to a file
wp post get 12 --field=earnings > earnings.txt

list

The affwp referral list sub-command is used to list out referrals based on given criteria.

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

Options

All options are optional unless noted otherwise.


One or more args to pass to get_affiliates(). ‘user_login’ and ‘name’ are not affiliate fields and will be ignored.

  • –field
    Prints the value of a single field for each affiliate.
  • –fields
    Limit the output to specific affiliate fields.
  • –format
    Accepted values: table, csv, json, count, ids, yaml. Default: table
Available Fields

These fields will be displayed by default for each referral:

  • ID (alias for affiliate_id)
  • amount
  • affiliate_name
  • affiliate_id
  • visit_id
  • reference
  • description
  • status
  • date

  These fields are also optionally available:

  • currency
  • custom
  • campaign

Examples

# Lists referrals by the affiliate name
affwp referral list --field=affiliate_name

# List referrals with a percentage rate type, with the affiliate ID, rate, and earnings columns
affwp referral list --rate_type=percentage --fields=affiliate_id,rate,earnings

# List referrals by earnings in json format
affwp referral list --field=earnings --format=json

update

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

Usage: wp affwp referral update 
 <referral_id>
   [--affiliate=
  <username|affiliate_id>
   ] [--amount=
   <number>
    ] [--description=
    <description>
     ] [--reference=
     <reference>
      ] [--context=
      <context>
       ] [--status=
       <status>
        ] 
       </status>
      </context>
     </reference>
    </description>
   </number>
  </username|affiliate_id>
 </referral_id>

Options

All options are optional unless noted otherwise.Referral ID.–affiliate=Affiliate ID or userna me.–amount=Referral amount.–description=Referral description.–reference=Referral reference (usually product information).–context=Referral context (usually related to the integration, e.g. woocommerce)–status=Referral status. Accepts ‘unpaid’, ‘paid’, ‘pending’, or ‘rejected’.

Examples

# Updates referral ID 120 with an amount of $1
wp affwp referral update 120 --amount=1

# Updates referral ID 33 with a status of 'paid'
wp affwp referral update 33 --status=paid

# Updates referral ID 50 to belong to affiliate username woouser1
wp affwp referral update 50 --affiliate=woouser1

Visit Commands

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

Usage: wp affwp affiliate 
 <sub-command>

 </sub-command>

There are five affiliate sub-commands to choose from:

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

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 affiliate create sub-command is used to create new affiliate accounts.

Usage: wp affwp affiliate create 
 <username|user_id>
   [--payment_email=
  <email>
   ] [--rate=
   <float>
    ] [--rate_type=
    <type>
     ] [--status=
     <status>
      ] [--earnings=
      <number>
       ] [--referrals=
       <number>
        ] [--visits=
        <number>
         ] 
        </number>
       </number>
      </number>
     </status>
    </type>
   </float>
  </email>
 </username|user_id>

Note: create assumes you already added a user account and have a user ID or username to pass as the first argument, which is required.

Options

All options are optional unless noted otherwise.

  • username|user_id (required)
    Username or ID for an existing user.
  • –payment_email
    Affiliate payment email. If not specified, the user account email will be used.
  • –rate
    Referral rate. If not specified, the default rate will be used.
  • –rate_type
    Referral rate type. Accepts ‘percentage’, ‘flat’, or any custom rate type. If not specified, the default rate type will be used.
  • –status
    Affiliate status. Accepts ‘active’, ‘inactive’, or ‘pending’. If not specified, and new affiliates require approval per global settings, ‘pending’ will used. Otherwise, the default status of ‘active’ will be used.
  • –earnings
    Affiliate earnings. If not specified, 0 will be used.
  • –referrals
    Number of referrals. If not specified, 0 will be used.
  • –visits
    Number of visits. If not specified, 0 will be used.

Examples

# Creates an affiliate with a 20% referral rate.
wp affwp affiliate create edduser1 --rate=0.2 --rate_type=percentage


# Creates an affiliate with the default referral rate, rate type,
#specified payment email, and 20 visits.
wp affwp affiliate create woouser1 [email protected] --visits=20


# Creates an affiliate for user ID 142 with a status of 'pending'.
wp affwp affiliate create 142 --status=pending

delete

The affwp affiliate delete sub-command is used to delete affiliate accounts.

Usage: wp affwp affiliate delete 
 <username|affiliate_id>
   [--delete_data] [--delete_user] [--network]

 </username|affiliate_id>

Options

All options are optional unless noted otherwise.

  • (required)
    Username or affiliate ID.
  • –delete_data
    Whether to delete affiliate data, such as referrals, visits, etc. Data will be retained by default.
  • –delete_user
    Whether to delete the user account associated with the affiliate account. Default false.
  • –network
    Whether to delete the user account network-wide (multisite only). Ignored if –delete_user is omitted. Use with caution. Default false.

Examples

# Deletes the affiliateuser03 account, retaining its associated data and user account
wp affwp affiliate delete affiliateuser03

# Deletes the affiliate with ID 636 along with its associated data
wp affwp affiliate delete 636 --delete_data

# Deletes the networkuser25 affiliate and its associated user account
wp affwp affiliate delete networkuser25 --delete_user

get

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

Usage: wp affwp affiliate get 
 <affiliate_id>
   [--field=
  <field>
   ] [--fields=
   <fields>
    ] [--format=
    <format>
     ] 
    </format>
   </fields>
  </field>
 </affiliate_id>

Options

All options are optional unless noted otherwise.

  • (required)
    The affiliate ID to retrieve.
  • –field
    Instead of returning the whole affiliate 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

# save the affiliate field value to a file
wp post get 12 --field=earnings > earnings.txt

list

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

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

Options

All options are optional unless noted otherwise.


One or more args to pass to get_affiliates(). ‘user_login’ and ‘name’ are not affiliate fields and will be ignored.

  • –field
    Prints the value of a single field for each affiliate.
  • –fields
    Limit the output to specific affiliate fields.
  • –format
    Accepted values: table, csv, json, count, ids, yaml. Default: table
Available Fields

These fields will be displayed by default for each affiliate:

  • ID (alias for affiliate_id)
  • name
  • user_login
  • user_id
  • rate
  • rate_type
  • status
  • earnings
  • referrals
  • visits
  • date_registered

Examples

# Lists affiliates by affiliate_id
wp affwp affiliate list --field=affiliate_id

# Outputs a table with affiliate_id, rate, and earnings columns for affiliates set
# as the 'percentage' rate type
wp affwp affiliate list --rate_type=percentage --fields=affiliate_id,rate,earnings

# Outputs a table with standard user_login, affiliate_id, earnings, referrals, and
# visits columns, ordered by status ascending.
affwp affiliate list --orderby=status --order=ASC

update

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

Usage: wp affwp affiliate update 
 <username|id>
   [--account_email=
  <email>
   ] [--payment_email=
   <email>
    ] [--rate=
    <float>
     ] [--rate_type=
     <type>
      ] [--status=
      <status>
       ] 
      </status>
     </type>
    </float>
   </email>
  </email>
 </username|id>

Options

All options are optional unless noted otherwise.