* @since 1.47.0 */ namespace AdvancedAds\Abstracts; use AdvancedAds\Framework\Utilities\Str; use AdvancedAds\Framework\Utilities\Params; defined( 'ABSPATH' ) || exit; /** * Abstracts Screen. */ abstract class Screen { /** * The hook assigned to the screen. * * @var string */ private $hook = ''; /** * List of tabs for the screen. * * @var array */ private $tabs = []; /* Page Hook Api --------------- */ /** * Get the hook. * * @return string */ public function get_hook(): string { return $this->hook; } /** * Set the hook. * * @param string $hook Hook to set. * * @return void */ public function set_hook( string $hook ): void { $this->hook = $hook; } /* Screen API ------------------ */ /** * Screen unique id. * * @return string */ abstract public function get_id(): string; /** * Register screen into WordPress admin area. * * @return void */ abstract public function register_screen(): void; /** * Enqueue assets * * @return void */ public function enqueue_assets(): void {} /** * Display screen content. * * @return void */ public function display(): void {} /** * Get the order value. * * @return int The order value, which is 10. */ public function get_order(): int { return 10; } /* Tabs API -------------------- */ /** * Get the tabs. * * @return array */ public function get_tabs(): array { return $this->tabs; } /** * Set the tabs. * * @param array $tabs Array of screen tabs. * * @return void */ public function set_tabs( array $tabs ): void { $this->tabs = apply_filters( 'advanced-ads-screen-tabs-' . $this->get_id(), $tabs ); } /** * Get current tab id. * * @return string */ public function get_current_tab_id(): string { $first = current( array_keys( $this->tabs ) ); return Params::get( 'sub_page', $first ); } /** * Render tabs menu * * @param array $args Arguments to be used in the template. * * @return void */ public function get_tabs_menu( array $args = [] ): void { // phpcs:ignore $tabs = $this->tabs; $active = $this->get_current_tab_id(); include ADVADS_ABSPATH . 'views/admin/header-tabs.php'; } /** * Render tabs content * * @param array $args Arguments to be used in the template. * * @return void */ public function get_tab_content( array $args = [] ): void { // phpcs:ignore $active = $this->get_current_tab_id(); $tab = $this->tabs[ $active ] ?? null; if ( ! $tab ) { return; } echo '