class-step.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WBCR\Factory_Templates_759\Pages; |
| 4 | |
| 5 | /** |
| 6 | * Step |
| 7 | * |
| 8 | * @version 1.0 |
| 9 | */ |
| 10 | abstract class Step { |
| 11 | |
| 12 | protected $id; |
| 13 | |
| 14 | protected $prev_id = false; |
| 15 | protected $next_id = false; |
| 16 | |
| 17 | /** |
| 18 | * @var \WBCR\Factory_Templates_759\Pages\Setup |
| 19 | */ |
| 20 | protected $page; |
| 21 | |
| 22 | /** |
| 23 | * @var \Wbcr_Factory600_Plugin |
| 24 | */ |
| 25 | protected $plugin; |
| 26 | |
| 27 | public function __construct( \WBCR\Factory_Templates_759\Pages\Setup $page ) { |
| 28 | $this->page = $page; |
| 29 | $this->plugin = $page->plugin; |
| 30 | // $this->form_handler(); |
| 31 | } |
| 32 | |
| 33 | public function get_id() { |
| 34 | if ( empty( $this->id ) ) { |
| 35 | throw new \Exception( 'Step ID setting is required for the {' . static::class . '} class!' ); |
| 36 | } |
| 37 | |
| 38 | return $this->id; |
| 39 | } |
| 40 | |
| 41 | public function get_next_id() { |
| 42 | return $this->next_id; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Requests assets (js and css) for the page. |
| 47 | * |
| 48 | * @return void |
| 49 | * @since 1.0.0 |
| 50 | * @see FactoryPages600_AdminPage |
| 51 | */ |
| 52 | public function assets( $scripts, $styles ) { |
| 53 | // nothing |
| 54 | } |
| 55 | |
| 56 | protected function continue_step( $skip = false ) { |
| 57 | $next_id = $this->get_next_id(); |
| 58 | if ( ! $next_id ) { |
| 59 | $next_id = $this->get_id(); |
| 60 | } |
| 61 | wp_safe_redirect( $this->page->getActionUrl( $next_id ) ); |
| 62 | die(); |
| 63 | } |
| 64 | |
| 65 | protected function skip_step() { |
| 66 | $this->continue_step( true ); |
| 67 | } |
| 68 | |
| 69 | abstract public function get_title(); |
| 70 | |
| 71 | abstract public function html(); |
| 72 | } |
| 73 |