| 1 |
<?php |
| 2 |
|
| 3 |
/* * class |
| 4 |
* Description of AbstractModernAdminPage |
| 5 |
* |
| 6 |
* @author Ali2Woo Team |
| 7 |
* |
| 8 |
* @position: 2 |
| 9 |
*/ |
| 10 |
namespace AliNext_Lite;; |
| 11 |
|
| 12 |
abstract class AbstractModernAdminPage extends AbstractController |
| 13 |
{ |
| 14 |
protected string $page_title; |
| 15 |
protected string $menu_title; |
| 16 |
protected string $capability; |
| 17 |
protected string $menu_slug; |
| 18 |
|
| 19 |
protected array $styles = []; |
| 20 |
protected array $scripts = []; |
| 21 |
|
| 22 |
public function __construct(string $page_title, string $menu_title, string $capability, string $menu_slug) |
| 23 |
{ |
| 24 |
parent::__construct(A2WL()->plugin_path() . '/view/'); |
| 25 |
|
| 26 |
$this->page_title = $page_title; |
| 27 |
$this->menu_title = $menu_title; |
| 28 |
$this->capability = $capability; |
| 29 |
$this->menu_slug = $menu_slug; |
| 30 |
|
| 31 |
add_action('admin_enqueue_scripts', [$this, 'enqueue_assets']); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
public function getPageTitle(): string |
| 36 |
{ |
| 37 |
return $this->page_title; |
| 38 |
} |
| 39 |
|
| 40 |
public function getMenuTitle(): string |
| 41 |
{ |
| 42 |
return $this->menu_title; |
| 43 |
} |
| 44 |
|
| 45 |
public function getCapability(): string |
| 46 |
{ |
| 47 |
return $this->capability; |
| 48 |
} |
| 49 |
|
| 50 |
public function getSlug(): string |
| 51 |
{ |
| 52 |
return $this->menu_slug; |
| 53 |
} |
| 54 |
|
| 55 |
public function add_style($handle, $src): void |
| 56 |
{ |
| 57 |
$this->styles[$handle] = $src; |
| 58 |
} |
| 59 |
|
| 60 |
public function add_script($handle, $src): void |
| 61 |
{ |
| 62 |
$this->scripts[$handle] = $src; |
| 63 |
} |
| 64 |
|
| 65 |
public function enqueue_assets(): void |
| 66 |
{ |
| 67 |
if (!$this->is_current_page()) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
foreach ($this->styles as $handle => $src) { |
| 72 |
wp_enqueue_style($handle, A2WL()->plugin_url() . $src, [], A2WL()->version); |
| 73 |
} |
| 74 |
|
| 75 |
foreach ($this->scripts as $handle => $src) { |
| 76 |
wp_enqueue_script($handle, A2WL()->plugin_url() . $src, ['jquery'], A2WL()->version, true); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
protected function is_current_page(): bool |
| 81 |
{ |
| 82 |
return isset($_GET['page']) && $_GET['page'] === $this->menu_slug; |
| 83 |
} |
| 84 |
|
| 85 |
abstract public function render(); |
| 86 |
} |
| 87 |
|