ads
1 week ago
groups
1 week ago
metaboxes
1 year ago
pages
1 day ago
placements
1 day ago
class-action-links.php
1 week ago
class-addon-box.php
1 day ago
class-addon-updater.php
1 day ago
class-admin-menu.php
1 day ago
class-admin-notices.php
1 year ago
class-ajax.php
1 day ago
class-app.php
1 day ago
class-assets.php
1 day ago
class-authors.php
1 year ago
class-edd-updater.php
1 day ago
class-license-admin-post.php
1 day ago
class-list-filters.php
1 week ago
class-marketing.php
1 year ago
class-metabox-ad-settings.php
1 year ago
class-metabox-ad.php
1 year ago
class-misc.php
1 week ago
class-page-quick-edit.php
1 day ago
class-plugin-auto-update.php
1 day ago
class-plugin-installer.php
1 day ago
class-post-list.php
1 year ago
class-post-types.php
1 week ago
class-screen-options.php
3 months ago
class-settings.php
1 day ago
class-shortcode-creator.php
1 year ago
class-system-info.php
1 year ago
class-tinymce.php
2 years ago
class-translation-promo.php
1 year ago
class-upgrades.php
1 year ago
class-version-control.php
3 months ago
class-welcome.php
1 year ago
class-wordpress-dashboard.php
1 year ago
index.php
2 years ago
class-app.php
145 lines
| 1 | <?php |
| 2 | /** |
| 3 | * App screen. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.47.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Admin; |
| 11 | |
| 12 | use AdvancedAds\Abstracts\Screen; |
| 13 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 14 | use AdvancedAds\Framework\Utilities\Params; |
| 15 | use AdvancedAds\Utilities\Conditional; |
| 16 | |
| 17 | defined( 'ABSPATH' ) || exit; |
| 18 | |
| 19 | /** |
| 20 | * App. |
| 21 | * |
| 22 | * phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited |
| 23 | */ |
| 24 | class App extends Screen implements Integration_Interface { |
| 25 | |
| 26 | /** |
| 27 | * Hook into WordPress. |
| 28 | * |
| 29 | * @return void |
| 30 | */ |
| 31 | public function hooks(): void { |
| 32 | add_action( 'admin_menu', [ $this, 'register_screen' ], 99 ); |
| 33 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ], 10, 0 ); |
| 34 | add_action( 'in_admin_header', [ $this, 'remove_notices' ], PHP_INT_MAX ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Screen unique id. |
| 39 | * |
| 40 | * @return string |
| 41 | */ |
| 42 | public function get_id(): string { |
| 43 | return 'app'; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Register screen into WordPress admin area. |
| 48 | * |
| 49 | * @return void |
| 50 | */ |
| 51 | public function register_screen(): void { |
| 52 | $this->register_submenus(); |
| 53 | |
| 54 | $hook = add_submenu_page( |
| 55 | ADVADS_SLUG, |
| 56 | __( 'App', 'advanced-ads' ), |
| 57 | __( 'App', 'advanced-ads' ), |
| 58 | Conditional::user_cap( 'advanced_ads_manage_options' ), |
| 59 | ADVADS_SLUG . '-app', |
| 60 | [ $this, 'display' ], |
| 61 | 999 |
| 62 | ); |
| 63 | |
| 64 | $this->set_hook( $hook ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Enqueue assets |
| 69 | * |
| 70 | * @return void |
| 71 | */ |
| 72 | public function enqueue_assets(): void { |
| 73 | if ( ! $this->is_screen() ) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | wp_advads()->registry->enqueue_style( 'app' ); |
| 78 | wp_advads()->registry->enqueue_script( 'app' ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Remove notices from the app screen. |
| 83 | * |
| 84 | * @return void |
| 85 | */ |
| 86 | public function remove_notices(): void { |
| 87 | echo '<style>li#toplevel_page_advanced-ads .wp-submenu li:last-child {display: none}</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 88 | |
| 89 | if ( ! $this->is_screen() ) { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | remove_all_actions( 'admin_notices' ); |
| 94 | remove_all_actions( 'wpstg.admin_notices' ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Display screen content. |
| 99 | * |
| 100 | * @return void |
| 101 | */ |
| 102 | public function display(): void { |
| 103 | echo '<div id="advads-app"></div>'; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Check if the current screen is the app screen. |
| 108 | * |
| 109 | * @return bool |
| 110 | */ |
| 111 | private function is_screen(): bool { |
| 112 | $wp_screen = get_current_screen(); |
| 113 | return $wp_screen->id === $this->get_hook(); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Register submenus. |
| 118 | * |
| 119 | * @return void |
| 120 | */ |
| 121 | private function register_submenus(): void { |
| 122 | global $submenu; |
| 123 | |
| 124 | $button_class = 'advads-app-link'; |
| 125 | $is_app = 'advanced-ads-app' === Params::get( 'page' ); |
| 126 | $base_url = $is_app ? '' : admin_url( 'admin.php?page=advanced-ads-app&path=' ); |
| 127 | |
| 128 | $submenu['advanced-ads'][] = [ |
| 129 | __( 'Support', 'advanced-ads' ), |
| 130 | Conditional::user_cap( 'advanced_ads_manage_options' ), |
| 131 | $base_url . '/support', |
| 132 | __( 'Support', 'advanced-ads' ), |
| 133 | $button_class, |
| 134 | ]; |
| 135 | |
| 136 | $submenu['advanced-ads'][] = [ |
| 137 | __( 'Licenses', 'advanced-ads' ), |
| 138 | Conditional::user_cap( 'advanced_ads_manage_options' ), |
| 139 | $base_url . '/license', |
| 140 | __( 'Licenses', 'advanced-ads' ), |
| 141 | $button_class, |
| 142 | ]; |
| 143 | } |
| 144 | } |
| 145 |