DonationSeedCommand.php
5 years ago
DonationStatusCommand.php
5 years ago
DonorSeedCommand.php
5 years ago
FormSeedCommand.php
5 years ago
PageSeedCommand.php
5 years ago
PageSeedCommand.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\TestData\Commands; |
| 4 | |
| 5 | use WP_CLI; |
| 6 | use Give\TestData\Factories\PageFactory; |
| 7 | /** |
| 8 | * Class DonorSeedCommand |
| 9 | * @package Give\TestData\Commands |
| 10 | * |
| 11 | * A WP-CLI command for seeding pages. |
| 12 | */ |
| 13 | class PageSeedCommand { |
| 14 | |
| 15 | /** |
| 16 | * @var PageFactory |
| 17 | */ |
| 18 | private $pageFactory; |
| 19 | |
| 20 | public function __construct( PageFactory $pageFactory ) { |
| 21 | $this->pageFactory = $pageFactory; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Generates GiveWP demonstartion page with all GiveWP shortcodes included |
| 26 | * |
| 27 | * [--preview=<preview>] |
| 28 | * : Preview generated data |
| 29 | * default: false |
| 30 | * |
| 31 | * ## EXAMPLES |
| 32 | * |
| 33 | * wp give test-demonstration-page --preview=true |
| 34 | * |
| 35 | * @when after_wp_load |
| 36 | */ |
| 37 | public function __invoke( $args, $assocArgs ) { |
| 38 | $preview = WP_CLI\Utils\get_flag_value( $assocArgs, 'preview', $default = false ); |
| 39 | |
| 40 | $page = $this->pageFactory->definition(); |
| 41 | |
| 42 | if ( $preview ) { |
| 43 | WP_CLI\Utils\format_items( |
| 44 | 'table', |
| 45 | [ $page ], |
| 46 | array_keys( $page ) |
| 47 | ); |
| 48 | } else { |
| 49 | $progress = WP_CLI\Utils\make_progress_bar( 'Generating demonstration page', 1 ); |
| 50 | |
| 51 | wp_insert_post( $page ); |
| 52 | $progress->finish(); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 |