Working with imports or exports can be hard, especially on really large databases. WP CLI is a tool that helps you a lot. It can also help you with running imports or exports. If you expect large imports or exports, you can also create a WP CLI command for batch processing the data. For doing batch imports or exports, you need a method with steps. For this tutorial, I will use the Easy Digital Downloads Batch import as an example.
You can find the code in their repository and you can also find an implementation for importing Downloads.
Creating the Command
Before creating the command, we need to make sure that we have the WP CLI installed.
<?php
/**
* Plugin Name: WP CLI Batch commands.
*/
if( ! defined( ‘WP_CLI’ ) || ! WP_CLI ) { return; }
WP_CLI::add_command( ‘batch’, ‘BATCH_CLI’ );
class EDD_BATCH_CLI extends WP_CLI {
// Code
}
Go ahead and activate the plugin. Now we will create the commands. If you try to run wp help you might be able to find batch there. If the class is without any public functions, that might not show up. So let’s do that now.
Generic Import Method
We will now create a generic import method that we can use for all kind of imports that are based on the
Source: https://managewp.org/articles/18194/how-to-create-a-wp-cli-command-for-batch-imports-or-exports
source https://williechiu40.wordpress.com/2018/12/09/how-to-create-a-wp-cli-command-for-batch-imports-or-exports/
No comments:
Post a Comment