export-page.php
2 years ago
gateways-pages-trait.php
2 years ago
payments-page.php
2 years ago
print-page.php
2 years ago
single-payment-page.php
2 years ago
single-payment-print-page.php
2 years ago
export-page.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Gateways\Pages; |
| 5 | |
| 6 | use JFB_Components\Admin\Page\Interfaces\Action_Page_It; |
| 7 | use JFB_Components\Admin\Page\Traits\Action_Page_Trait; |
| 8 | use JFB_Components\Export\Export_Tools; |
| 9 | use JFB_Components\Wp_Nonce\Wp_Nonce; |
| 10 | use JFB_Components\Wp_Nonce\Wp_Nonce_It; |
| 11 | use JFB_Components\Wp_Nonce\Wp_Nonce_Trait; |
| 12 | use JFB_Modules\Gateways\Export; |
| 13 | |
| 14 | // If this file is called directly, abort. |
| 15 | if ( ! defined( 'WPINC' ) ) { |
| 16 | die; |
| 17 | } |
| 18 | |
| 19 | class Export_Page implements Action_Page_It, Wp_Nonce_It { |
| 20 | |
| 21 | use Action_Page_Trait; |
| 22 | use Wp_Nonce_Trait; |
| 23 | |
| 24 | public function __construct() { |
| 25 | $nonce = new Wp_Nonce( 'jfb-action-admin-' . $this->slug() ); |
| 26 | $this->set_wp_nonce( $nonce ); |
| 27 | } |
| 28 | |
| 29 | public function slug(): string { |
| 30 | return 'payments-export'; |
| 31 | } |
| 32 | |
| 33 | public function check_permission(): bool { |
| 34 | return $this->get_wp_nonce()->verify() && current_user_can( 'manage_options' ); |
| 35 | } |
| 36 | |
| 37 | public function render_page() { |
| 38 | $exporter = Export_Tools::get_exporter_by_format(); |
| 39 | |
| 40 | //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 41 | $controller = array_key_exists( 'id', $_GET ) |
| 42 | ? new Export\Single_Controller() |
| 43 | : new Export\Multiple_Controller(); |
| 44 | |
| 45 | $controller->set_exporter( $exporter ); |
| 46 | |
| 47 | try { |
| 48 | $controller->do_export(); |
| 49 | } catch ( \Exception $exception ) { |
| 50 | // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 51 | wp_die( |
| 52 | $exception->getMessage(), |
| 53 | __( 'Error', 'jet-form-builder' ) |
| 54 | ); |
| 55 | // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | public function get_url( $query_args = array() ): string { |
| 60 | return $this->admin_url( |
| 61 | array_merge( |
| 62 | array( |
| 63 | 'slug' => $this->slug(), |
| 64 | $this->get_wp_nonce()->get_name() => $this->get_wp_nonce()->create(), |
| 65 | ), |
| 66 | $query_args |
| 67 | ) |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | } |
| 72 |