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
base-page.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Jet_Form_Builder\Admin\Pages; |
| 4 | |
| 5 | use Jet_Form_Builder\Plugin; |
| 6 | |
| 7 | /** |
| 8 | * Base dashboard page |
| 9 | */ |
| 10 | abstract class Base_Page { |
| 11 | |
| 12 | /** |
| 13 | * Page slug |
| 14 | */ |
| 15 | abstract public function slug(): string; |
| 16 | |
| 17 | /** |
| 18 | * Page title |
| 19 | */ |
| 20 | abstract public function title(): string; |
| 21 | |
| 22 | /** |
| 23 | * Page render function |
| 24 | */ |
| 25 | public function render() { |
| 26 | printf( '<div id="%s"></div>', esc_attr( 'jet-form-builder_page_' . $this->slug() ) ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Return page config array |
| 31 | */ |
| 32 | abstract public function page_config(): array; |
| 33 | |
| 34 | /** |
| 35 | * Page specific assets |
| 36 | */ |
| 37 | public function assets() { |
| 38 | wp_enqueue_script( |
| 39 | $this->slug(), |
| 40 | Plugin::instance()->plugin_url( 'assets/js/admin.js' ), |
| 41 | array(), |
| 42 | Plugin::instance()->get_version(), |
| 43 | true |
| 44 | ); |
| 45 | |
| 46 | wp_set_script_translations( |
| 47 | $this->slug(), |
| 48 | 'jet-form-builder', |
| 49 | Plugin::instance()->plugin_dir( 'languages' ) |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Enqueue script |
| 56 | * |
| 57 | * @param $handle string |
| 58 | * @param $file_path string |
| 59 | */ |
| 60 | public function enqueue_script( string $handle, string $file_path ) { |
| 61 | wp_enqueue_script( |
| 62 | $handle, |
| 63 | Plugin::instance()->plugin_url( "assets/js/$file_path" ), |
| 64 | array( 'wp-api-fetch' ), |
| 65 | Plugin::instance()->get_version(), |
| 66 | true |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Enqueue style |
| 72 | * |
| 73 | * @param string $handle |
| 74 | * @param string $file_path |
| 75 | */ |
| 76 | public function enqueue_style( string $handle, string $file_path ) { |
| 77 | wp_enqueue_style( |
| 78 | $handle, |
| 79 | Plugin::instance()->plugin_url( "assets/css/$file_path" ), |
| 80 | array(), |
| 81 | Plugin::instance()->get_version() |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | /** |
| 87 | * Returns current page url |
| 88 | */ |
| 89 | public function get_url(): string { |
| 90 | return add_query_arg( |
| 91 | array( 'page' => $this->slug() ), |
| 92 | esc_url_raw( admin_url( 'admin.php' ) ) |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | } |