Created
September 29, 2022 00:43
-
-
Save peterjohnhunt/ac15299b3e915d957e707970938cbd55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Import Specs CLI | |
| * | |
| * @subcommand specs | |
| * | |
| * ## EXAMPLES | |
| * | |
| * wp import file | |
| * | |
| * @when after_wp_load | |
| */ | |
| function file( $args, $assoc_args ) { | |
| list( $filename ) = $args; | |
| $fields = $assoc_args['fields'] ?? 'ID'; | |
| $format = $assoc_args['format'] ?? 'table'; | |
| $test_run = $assoc_args['test-run'] ?? false; | |
| $dry_run = $assoc_args['dry-run'] ?? false; | |
| if ( ! file_exists( $filename ) ) { | |
| \WP_CLI::error( "Missing file: {$filename}" ); | |
| } | |
| $rows = new \WP_CLI\Iterators\CSV($filename); | |
| $items = []; | |
| foreach ($rows as $index => $row) { | |
| $items[] = [ | |
| 'ID' => $row['ID'] | |
| ]; | |
| if ( $test_run ) break; | |
| } | |
| \WP_CLI\Utils\format_items( $format, $items, $fields ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment