class-ads-editing.php
3 months ago
class-ads.php
3 months ago
class-dashboard.php
3 months ago
class-groups.php
3 months ago
class-onboarding.php
3 months ago
class-placements.php
3 months ago
class-settings.php
3 months ago
class-support.php
3 months ago
class-tools.php
3 months ago
class-dashboard.php
101 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Dashboard screen. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.47.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Admin\Pages; |
| 11 | |
| 12 | use AdvancedAds\Abstracts\Screen; |
| 13 | use AdvancedAds\Utilities\WordPress; |
| 14 | use AdvancedAds\Utilities\Conditional; |
| 15 | |
| 16 | defined( 'ABSPATH' ) || exit; |
| 17 | |
| 18 | /** |
| 19 | * Dashboard. |
| 20 | */ |
| 21 | class Dashboard extends Screen { |
| 22 | |
| 23 | /** |
| 24 | * Screen unique id. |
| 25 | * |
| 26 | * @return string |
| 27 | */ |
| 28 | public function get_id(): string { |
| 29 | return 'dashboard'; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Register screen into WordPress admin area. |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public function register_screen(): void { |
| 38 | $has_ads = WordPress::get_count_ads(); |
| 39 | |
| 40 | add_menu_page( |
| 41 | __( 'Dashboard', 'advanced-ads' ), |
| 42 | 'Advanced Ads', |
| 43 | Conditional::user_cap( 'advanced_ads_see_interface' ), |
| 44 | ADVADS_SLUG, |
| 45 | [ $this, 'display' ], |
| 46 | $this->get_icon_svg(), |
| 47 | '58.74' |
| 48 | ); |
| 49 | |
| 50 | $hook = add_submenu_page( |
| 51 | ADVADS_SLUG, |
| 52 | __( 'Dashboard', 'advanced-ads' ), |
| 53 | __( 'Dashboard', 'advanced-ads' ), |
| 54 | Conditional::user_cap( $has_ads ? 'advanced_ads_edit_ads' : 'advanced_ads_see_interface' ), |
| 55 | ADVADS_SLUG, |
| 56 | $has_ads ? '' : [ $this, 'display' ] |
| 57 | ); |
| 58 | |
| 59 | $this->set_hook( $hook ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Enqueue assets |
| 64 | * |
| 65 | * @return void |
| 66 | */ |
| 67 | public function enqueue_assets(): void { |
| 68 | wp_advads()->registry->enqueue_style( 'screen-dashboard' ); |
| 69 | wp_advads()->registry->enqueue_script( 'screen-dashboard' ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get page header arguments |
| 74 | * |
| 75 | * @return array |
| 76 | */ |
| 77 | public function define_header_args(): array { |
| 78 | return [ |
| 79 | 'breadcrumb' => false, |
| 80 | ]; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Display screen content. |
| 85 | * |
| 86 | * @return void |
| 87 | */ |
| 88 | public function display(): void { |
| 89 | include ADVADS_ABSPATH . 'views/admin/screens/dashboard.php'; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Return Advanced Ads logo in base64 format for use in WP Admin menu. * Highlights the 'Advanced Ads->Ads' item in the menu when an ad edit page is open |
| 94 | * |
| 95 | * @return string |
| 96 | */ |
| 97 | private function get_icon_svg(): string { |
| 98 | return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE4LjEuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJFYmVuZV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgdmlld0JveD0iMCAwIDY0Ljk5MyA2NS4wMjQiIHN0eWxlPSJlbmFibGUt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