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