actions
2 years ago
interfaces
2 years ago
settings
2 years ago
action-pages-manager.php
2 years ago
addons-page.php
2 years ago
base-page.php
2 years ago
pages-manager.php
1 year ago
single-pages-manager.php
2 years ago
stable-pages-manager.php
1 year ago
action-pages-manager.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Admin\Pages; |
| 5 | |
| 6 | use Jet_Form_Builder\Admin\Exceptions\Not_Found_Page_Exception; |
| 7 | use Jet_Form_Builder\Classes\Tools; |
| 8 | use Jet_Form_Builder\Exceptions\Repository_Exception; |
| 9 | use JFB_Components\Admin\Page\Interfaces\Action_Page_It; |
| 10 | use JFB_Components\Repository\Repository_Pattern_Trait; |
| 11 | |
| 12 | // If this file is called directly, abort. |
| 13 | if ( ! defined( 'WPINC' ) ) { |
| 14 | die; |
| 15 | } |
| 16 | |
| 17 | class Action_Pages_Manager { |
| 18 | |
| 19 | use Repository_Pattern_Trait; |
| 20 | |
| 21 | public function __construct() { |
| 22 | add_action( |
| 23 | 'admin_action_jfb', |
| 24 | array( $this, 'do_action' ) |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | public function rep_instances(): array { |
| 29 | return apply_filters( |
| 30 | 'jet-form-builder/admin/action-pages', |
| 31 | array() |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @param $item |
| 37 | * |
| 38 | * @throws Repository_Exception |
| 39 | */ |
| 40 | public function rep_before_install_item( $item ) { |
| 41 | if ( $item instanceof Action_Page_It ) { |
| 42 | return; |
| 43 | } |
| 44 | $this->_rep_abort_this(); |
| 45 | } |
| 46 | |
| 47 | public function do_action() { |
| 48 | $slug = Tools::sanitize_get_param( 'slug' ); |
| 49 | |
| 50 | try { |
| 51 | /** @var Action_Page_It $page */ |
| 52 | $page = $this->rep_get_item( $slug ); |
| 53 | } catch ( Repository_Exception $exception ) { |
| 54 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 55 | wp_die( $exception->getMessage() ); |
| 56 | } |
| 57 | |
| 58 | if ( ! $page->check_permission() ) { |
| 59 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 60 | wp_die( __( 'You do not have access to view this page', 'jet-form-builder' ) ); |
| 61 | } |
| 62 | |
| 63 | Pages_Manager::instance()->set_current_page_raw( $page ); |
| 64 | |
| 65 | try { |
| 66 | $page->render_page(); |
| 67 | } catch ( Not_Found_Page_Exception $exception ) { |
| 68 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 69 | wp_die( $exception->getMessage() ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } |
| 74 |