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
90 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>', '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 | |
| 47 | |
| 48 | /** |
| 49 | * Enqueue script |
| 50 | * |
| 51 | * @param $handle string |
| 52 | * @param $file_path string |
| 53 | */ |
| 54 | public function enqueue_script( string $handle, string $file_path ) { |
| 55 | wp_enqueue_script( |
| 56 | $handle, |
| 57 | Plugin::instance()->plugin_url( "assets/js/$file_path" ), |
| 58 | array( 'wp-api-fetch' ), |
| 59 | Plugin::instance()->get_version(), |
| 60 | true |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Enqueue style |
| 66 | * |
| 67 | * @param string $handle |
| 68 | * @param string $file_path |
| 69 | */ |
| 70 | public function enqueue_style( string $handle, string $file_path ) { |
| 71 | wp_enqueue_style( |
| 72 | $handle, |
| 73 | Plugin::instance()->plugin_url( "assets/css/$file_path" ), |
| 74 | array(), |
| 75 | Plugin::instance()->get_version() |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * Returns current page url |
| 82 | */ |
| 83 | public function get_url(): string { |
| 84 | return add_query_arg( |
| 85 | array( 'page' => $this->slug() ), |
| 86 | esc_url( admin_url( 'admin.php' ) ) |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | } |