The “subscribe” batch type will add all users in your WP-Members user list that are both:
- marked as subscribed (identified by your subscribe field);
- and not already subscribed in Mailchimp.
This is different from the sync command which will synchronize all users in Mailchimp with your WordPress users. All merge field data will be updated based on the user’s data in WordPress (not the data at Mailchimp).
Batch operations can be intensive processes depending on the following:
- the number of users,
- the number of extra data fields, including merge fields and interest categories, or
- a combination of the above.
As a result of the potential for significant load in processing a large batch, batch processing in the browser is run as a background process using asynchronous processing. The plugin uses a common library from Automattic for this purpose. The Action Scheduler library is a part of WooCommerce and several other popular plugins. The WP-Members Mailchimp plugin will piggyback on the Action Scheduler if it is already loaded by another plugin, or it will include it if not already included.
The “sync” batch process is different from the “subscribe” process in that it will synchronize all subscribed users, whether they exist in Mailchimp already or not.
One important element to consider when choosing sync is that the “primary” data in the sync will be the data that is on the WP side.
All subscribed users in WP-Members will be update in Mailchimp based on data held on the WordPress side. (The “subscribe” operation differs in that it only adds users not already in Mailchimp)
To Run a New Batch in the Browser
Start a new batch operation by going to WP-Members > Mailchimp and selecting the Batch tab.
Choose the batch type from the selector:
Once you submit your batch operation, the process will be scheduled for background processing. The Action Scheduler will start the process at its next scheduled run time.
To view the status of a process, go to Tools > Scheduled Actions in your WP admin panel. Note that the Action Scheduler is a tool used by other plugins as well, so if you have other plugins that use it, there will be more actions listed in the table, so you may have to search for the WP-Members Mailchimp actions.
The “hook” name of the batch processing is “wpmem_mc_batch_init”. The “Arguments” column will indicate the type of batch scheduled, either sync or subscribe. Note that these processes are scheduled based on whatever the next available runtime is, so the “Scheduled Date” column will always be “0000-00-00 00:00:00”.
When a batch process is scheduled, it will have a status of “Pending”
Once the process is complete, this will change to “Completed” and the “Log” column will include information on when the action was completed.
Once a batch process is completed, it will be listed in the batch table in the WP-Members > Mailchimp > Batch tab. Data is saved using the batch ID from Mailchimp. If you click the batch ID, you can download the results saved by Mailchimp.
Note that Mailchimp saves batch results as a tarball (compressed format) of a json formatted result. These are saved in an Amazon S3 bucket and they are not held forever. If you need to save this data for comparison or tracking, you need to download it before Mailchimp removes it from the bucket.
You can clear the batch table using the selector.
Running a Batch Process from the Command Line
WP-Members Mailchimp extends WP-CLI to allow batch processing via the command line. This is more efficient than running batches in the browser. You still need to be cognizant of server load, but using the WP-CLI tool, you don’t have to run the process in the background, and you can do it at a scheduled time that suits your need for server availability. Due to its efficiency, this is the recommended way of managing large batch subscribe and sync operations.
To view the available batch commands in WP-CLI, type “wp mem mc batch” at the command line:
To run either a subscribe or sync command, the command is:
wp mem mc batch subscribe
wp mem mc batch sync
When you choose an operation (“sync” in example that follows), the process will give you a prompt to explain the operation and ask you to confirm. Type “y” to confirm and start the batch operation.
Once confirmed, the batch operation will begin. WP-CLI will display a status bar as it ticks through the users in the batch. Once completed, it will give a “success” message (if the batch process was successfully completed) and will provide you the batch ID. (Note that batch ids can be found with other commands so if you don’t make note of this value, don’t worry about it – you can retrieve it later.)
Note that the immediate status of the batch operation is “pending”. You can check the status of the most recent batch by typing following command:
wp mem mc batch status
This command always retrieves the most recent batch ID. It accepts additional arguments of –view-all to view a table of all saved batches, or –id=<batch_id> to retrieve the status of a specific batch ID.
When viewing the status of an individual batch ID (in this case, the most recent), you will get the ID, the operation (subscribe or sync), the status, and data on the results. It will also give you the Amazon S3 bucket URL of the tarball of results from Mailchimp.