buttons
4 years ago
exceptions
4 years ago
notices
4 years ago
pages
4 years ago
single-pages
4 years ago
table-views
4 years ago
tabs-handlers
4 years ago
vui-boxes
4 years ago
admin-page-interface.php
4 years ago
admin-page-trait.php
4 years ago
editor.php
4 years ago
table-advanced-record-prepare-trait.php
4 years ago
table-record-prepare-trait.php
4 years ago
admin-page-trait.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Admin; |
| 5 | |
| 6 | |
| 7 | use Jet_Form_Builder\Plugin; |
| 8 | |
| 9 | trait Admin_Page_Trait { |
| 10 | |
| 11 | protected $config = array(); |
| 12 | |
| 13 | /** |
| 14 | * Page specific assets |
| 15 | */ |
| 16 | public function assets() { |
| 17 | wp_enqueue_script( $this->slug() ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Page render function |
| 22 | */ |
| 23 | public function render_page() { |
| 24 | printf( '<div id="%s"></div>', esc_attr( 'jet-form-builder_page_' . $this->slug() ) ); |
| 25 | } |
| 26 | |
| 27 | public function query_config(): array { |
| 28 | if ( ! empty( $this->config ) ) { |
| 29 | return $this->config; |
| 30 | } |
| 31 | $this->config = apply_filters( |
| 32 | "jet-form-builder/page-config/{$this->slug()}", |
| 33 | $this->page_config(), |
| 34 | $this |
| 35 | ); |
| 36 | |
| 37 | return $this->config; |
| 38 | } |
| 39 | |
| 40 | public function base_script_url(): string { |
| 41 | return Plugin::instance()->plugin_url( "assets/js/admin/pages/{$this->slug()}.js" ); |
| 42 | } |
| 43 | |
| 44 | public function render_config() { |
| 45 | $config = $this->query_config(); |
| 46 | |
| 47 | if ( ! empty( $config ) ) { |
| 48 | wp_localize_script( 'cx-vue', 'JetFBPageConfig', $config ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Returns current page url |
| 54 | * |
| 55 | * @param array $query_args |
| 56 | * |
| 57 | * @return string |
| 58 | */ |
| 59 | public function admin_url( $query_args = array() ): string { |
| 60 | return add_query_arg( |
| 61 | array_merge( |
| 62 | array( |
| 63 | 'post_type' => jet_form_builder()->post_type->slug(), |
| 64 | ), |
| 65 | $query_args |
| 66 | ), |
| 67 | esc_url_raw( admin_url( 'edit.php' ) ) |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | } |