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