PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.4.0
JetFormBuilder — Dynamic Blocks Form Builder v1.4.0
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / admin / pages / pages-manager.php
jetformbuilder / includes / admin / pages Last commit date
addons-page.php 4 years ago base-page.php 4 years ago page-config.php 4 years ago pages-manager.php 4 years ago settings-page.php 4 years ago
pages-manager.php
148 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Admin\Pages;
5
6
7 use Jet_Form_Builder\Plugin;
8
9 class Pages_Manager {
10
11 /**
12 * @var Base_Page[]
13 */
14 private $pages = array();
15
16 /**
17 * @var Base_Page
18 */
19 private $current_page;
20
21 /**
22 * [__construct description]
23 *
24 * @param array $pages [description]
25 */
26 public function __construct( $pages = array() ) {
27 $this->register_pages( $pages );
28 add_action( 'admin_menu', array( $this, 'add_pages' ) );
29
30 if ( $this->is_dashboard_page() ) {
31 $this->set_current_page();
32 add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) );
33 }
34 }
35
36 /**
37 * Register admin pages
38 *
39 * @param $pages
40 */
41 public function register_pages( $pages ) {
42 foreach ( $pages as $page ) {
43 $this->pages[ $page->slug() ] = $page;
44 }
45 }
46
47 /**
48 * Check if is dashboard page
49 *
50 * @return boolean [description]
51 */
52 public function is_dashboard_page() {
53 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
54 $page = ! empty( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : false;
55
56 if ( ! $page ) {
57 return false;
58 } else {
59 return isset( $this->pages[ $page ] );
60 }
61
62 }
63
64 /**
65 * Set current admin page
66 */
67 public function set_current_page() {
68 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
69 $slug = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : false;
70
71 if ( $slug ) {
72 $this->current_page = $this->pages[ $slug ];
73 }
74 }
75
76 /**
77 * Dashboard assets
78 */
79 public function assets() {
80 $ui_data = Plugin::instance()->framework->get_included_module_data( 'cherry-x-vue-ui.php' );
81 ( new \CX_Vue_UI( $ui_data ) )->enqueue_assets();
82
83 ( new Page_Config( $this->current_page ) )->render_config();
84
85 wp_enqueue_script(
86 'jet-form-builder-admin-package',
87 Plugin::instance()->plugin_url( 'assets/js/admin-package.js' ),
88 array(),
89 Plugin::instance()->get_version(),
90 true
91 );
92
93 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
94 do_action( "jet-fb/admin-pages/before-assets/{$this->current_page->slug()}", $this );
95
96 $this->current_page->assets();
97 }
98
99 /**
100 * @param $page_slug
101 *
102 * @return string
103 */
104 public function get_url_of( $page_slug ): string {
105
106 if ( ! isset( $this->pages[ $page_slug ] ) ) {
107 return '';
108 }
109
110 return $this->pages[ $page_slug ]->get_url();
111 }
112
113 /**
114 * Check if passed page is currently displayed
115 *
116 * @param Base_Page $page
117 *
118 * @return bool
119 */
120 public function is_page_now( Base_Page $page ): bool {
121
122 if ( ! $this->is_dashboard_page() ) {
123 return false;
124 }
125
126 return ( $page->slug() === $this->current_page->slug() );
127
128 }
129
130 /**
131 * Register appointments
132 */
133 public function add_pages() {
134 $parent = 'edit.php?post_type=' . jet_form_builder()->post_type->slug();
135
136 foreach ( $this->pages as $page ) {
137 add_submenu_page(
138 $parent,
139 $page->title(),
140 $page->title(),
141 'manage_options',
142 $page->slug(),
143 array( $page, 'render' )
144 );
145 }
146 }
147
148 }