Skip to content

WP-CLI commands

XFtoWP 1.7.2 adds wp xfwp commands to WP-CLI. Use them to check the connection, look up posts, threads and members, and run Bulk actions over SSH without keeping a browser open.

You need WP-CLI on the server where WordPress runs, and SSH access to it. Many hosts include WP-CLI. Run wp help xfwp to see every command, or wp help xfwp <command> for one.

Commands run with shell access, so they don’t check WordPress roles. Anyone who can run WP-CLI on your server can already read and change your whole site.

Check the connection

wp xfwp status

Shows whether XFtoWP is connected, the forum, the API key type, any missing API permissions and what they’re needed for, active features and integrations, and when forum data last refreshed. It never prints the API key.

wp xfwp status output showing the forum, API key type, features and last sync
wp xfwp refresh

Refreshes forum data now: the board, stats, forums and threads. It’s the same as Refresh data on XenForo → Settings.

Look things up

These commands only read what XFtoWP has saved. They don’t contact the forum.

CommandShows
wp xfwp forum statsForum totals, newest member, who’s online
wp xfwp forum listThe forums chosen in settings
wp xfwp forum threadsThe latest threads. --forum=<ID> works for forums shown in a Forum widget
wp xfwp forum featuredThreads featured in Forum widgets
wp xfwp thread get <post ID>A post’s thread and the replies shown on it
wp xfwp thread find <thread ID or URL>The post a thread is connected to
wp xfwp thread listPosts with threads. --orderby=replies for the most discussed
wp xfwp thread unconnectedPublished posts without a thread
wp xfwp thread problemsPosts whose thread failed, or that visitors can no longer read
wp xfwp user get <user>A user’s linked forum accounts
wp xfwp user find <forum user ID or username>The WordPress user linked to a forum account
wp xfwp user post-asAuthors and the forum account their threads post as
wp xfwp member get <user>One person for support: accounts, purchase groups, posts with threads
wp xfwp member unlinkedCustomers whose purchases give forum groups but who have no forum account
wp xfwp member auditLinked users whose purchase groups don’t match what they’ve paid for
wp xfwp logs threadsThe newest thread connections. Also logs users and logs webhooks

<user> can be a user ID, login or email.

Lists print as a table. Add --format=csv, json, yaml or count. Single results print as YAML, or JSON with --format=json.

The three member commands read purchases from WooCommerce, MemberPress, SureCart and DigiMember. They need forum groups set for purchases.

Commands that look through many users or posts check 500 at a time. When there’s more, they say so: run the command again with the --offset they print.

Run Bulk actions

wp xfwp bulk run runs the same actions as XenForo → Bulk actions, with the same rules, through every batch. For what each action does, see How to use Bulk Actions.

wp xfwp bulk list

Lists the actions: import, refresh, connect and disconnect, plus any added by other plugins.

A run looks like this:

wp xfwp bulk run import --source=wp --wp-role=customer --user=admin

Required

  • The action: import, refresh, connect or disconnect.
  • **--source:** *wp* to start from WordPress users, *xf* to start from forum users.
  • Which users: --wp-role=<role> with --source=wp, or --xf-group=<group ID> with --source=xf. To run on every user of the source, use --all instead. A filter that doesn’t match the source is refused, so a mistake can’t widen a run to everyone.
  • **--user=<administrator login>:** bulk actions run as an administrator, the same as on the screen.

Changes

Only where the action offers them. Anything else is refused:

  • **--groups=5,7:** forum secondary groups to add. Add --remove-groups to remove them instead, where the action allows it. Only groups listed under XenForo → Settings → Site setup → User groups can be used.
  • **--role=<role>:** a WordPress role, for actions starting from forum users. Roles that can manage the site or its users can’t be given, and administrators keep their role.
  • **--notify:** notify newly linked forum accounts. On a large forum that can be thousands of messages.
Group IDs under Site setup → User groups, the IDs to use with --groups and --xf-group

Pace

  • **--batch-size:** WordPress users per batch, up to 100, which is the default. Runs from forum users follow the forum’s pages.
  • **--sleep=<seconds>:** wait between batches. Use it if your forum host or a firewall limits API requests.
  • **--yes:** skip the confirmation question, for scripts.

Results

A progress bar shows while it runs. When it finishes, it lists only the users that weren’t changed successfully, each with a message, then a summary:

A bulk run asking to confirm, showing its progress bar, then the summary

The results mean the same as on the screen. If any user failed, the command exits with code 1, so scripts and cron jobs can tell.

If a run stops

Only one bulk run can work at a time. While a WP-CLI run is working, the Bulk actions screen and a second WP-CLI run show a message and don’t start.

If you press Ctrl-C, or the SSH session closes, the run stops and prints how to continue:

Error: Stopped after 300 users. Resume with --start-batch=3 --batch-size=100.

Run the same command again with those options. Users already processed stay changed. Running Import, Connect or Refresh again on them only skips or updates them.

This needs PHP’s pcntl extension on the command line. Without it, a stopped run prints nothing, and other bulk runs can’t start for up to 10 minutes. Running the whole action again is safe for the same reason as above.

How long it takes

Most of the time is spent waiting on your forum. Each user takes two or three API requests, so the forum’s speed and the distance between the two servers matter far more than WordPress.

These are WP-CLI times with WordPress and the forum on the same machine. The 1,000-user times were measured. Import and Refresh took the same time per user at 100 users as at 1,000, and memory use didn’t grow, so the 10,000-user times scale from the 1,000-user runs:

Action1,000 users10,000 users
Import users, from WordPressabout 7.5 minutesabout 1¼ hours
Refresh users, adding a forum groupabout 3.5 minutesabout 35 minutes
Connect existing usersabout 3.5 minutesabout 35 minutes
Disconnect usersabout 3.5 minutesabout 35 minutes

Import takes longest because the forum creates each account and stores its password. The Bulk actions screen took 10 to 20% longer than WP-CLI for the same users.

Treat these as the fastest case. When WordPress and the forum are on separate hosts, every request also travels between the two servers, so expect runs to take two to three times as long: around 2 to 4 hours to import 10,000 users. A slow forum host, or one that limits API requests, adds more.

Memory use stays flat for the whole run, so a large run won’t run out of memory partway through. For thousands of users, start the run in a screen or tmux session so it keeps going if your connection drops.

Before you run on a live site

  • Make a database backup.
  • Try a small role or group first.
  • Registration sync and User actions don’t run during a bulk action, so no welcome messages or purchase actions are sent.

The bulk commands are only there when Bulk Actions are available. They need the API key’s user:read and user:write permissions.

Alex Mangini

Hi, I’m Alex! I started writing about web design and blogging at 13 years old, which turned into client work, which led to building my own software. 15 years later I’m still at it, and XFtoWP is the plugin I always wanted to connect my two favorite software together.

Get sneak peaks, release note, success stories, and other interesting WordPress and XenForo content sent to your inbox.

Unsubscribe anytime.