action-page-trait.php
2 years ago
admin-dashboard-page-trait.php
1 year ago
table-advanced-record-prepare-trait.php
2 years ago
table-record-prepare-trait.php
2 years ago
admin-dashboard-page-trait.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Components\Admin\Page\Traits; |
| 5 | |
| 6 | use Jet_Form_Builder\Admin\Pages\Actions\Base_Page_Action; |
| 7 | use Jet_Form_Builder\Plugin; |
| 8 | |
| 9 | // If this file is called directly, abort. |
| 10 | if ( ! defined( 'WPINC' ) ) { |
| 11 | die; |
| 12 | } |
| 13 | |
| 14 | trait Admin_Dashboard_Page_Trait { |
| 15 | |
| 16 | protected $config = array(); |
| 17 | |
| 18 | /** |
| 19 | * Page specific assets |
| 20 | */ |
| 21 | public function assets() { |
| 22 | wp_enqueue_script( $this->slug() ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Page render function |
| 27 | */ |
| 28 | public function render_page() { |
| 29 | printf( '<div id="%s"></div>', esc_attr( 'jet-form-builder_page_' . $this->slug() ) ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @return Base_Page_Action[] |
| 34 | */ |
| 35 | public function get_actions(): array { |
| 36 | return array(); |
| 37 | } |
| 38 | |
| 39 | public function query_config(): array { |
| 40 | if ( ! empty( $this->config ) ) { |
| 41 | return $this->config; |
| 42 | } |
| 43 | $this->config = apply_filters( |
| 44 | "jet-form-builder/page-config/{$this->slug()}", |
| 45 | $this->page_config(), |
| 46 | $this |
| 47 | ); |
| 48 | |
| 49 | return $this->config; |
| 50 | } |
| 51 | |
| 52 | public function base_script_url(): string { |
| 53 | return Plugin::instance()->plugin_url( "assets/build/admin/pages/{$this->slug()}.js" ); |
| 54 | } |
| 55 | |
| 56 | public function render_config() { |
| 57 | $config = $this->query_config(); |
| 58 | |
| 59 | if ( ! empty( $config ) ) { |
| 60 | wp_localize_script( 'cx-vue', 'JetFBPageConfig', $config ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns current page url |
| 66 | * |
| 67 | * @param array $query_args |
| 68 | * |
| 69 | * @return string |
| 70 | */ |
| 71 | public function admin_url( $query_args = array() ): string { |
| 72 | return add_query_arg( |
| 73 | array_merge( |
| 74 | array( |
| 75 | 'post_type' => jet_form_builder()->post_type->slug(), |
| 76 | ), |
| 77 | $query_args |
| 78 | ), |
| 79 | esc_url_raw( admin_url( 'edit.php' ) ) |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | } |
| 84 |