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-support.php
118 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Support 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 | |
| 14 | defined( 'ABSPATH' ) || exit; |
| 15 | |
| 16 | /** |
| 17 | * Support. |
| 18 | */ |
| 19 | class Support extends Screen { |
| 20 | |
| 21 | /** |
| 22 | * Screen unique id. |
| 23 | * |
| 24 | * @return string |
| 25 | */ |
| 26 | public function get_id(): string { |
| 27 | return 'support'; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get the order number of the screen. |
| 32 | * |
| 33 | * @return int |
| 34 | */ |
| 35 | public function get_order(): int { |
| 36 | return 50; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Register screen into WordPress admin area. |
| 41 | * |
| 42 | * @return void |
| 43 | */ |
| 44 | public function register_screen(): void { |
| 45 | $hook = add_submenu_page( |
| 46 | ADVADS_SLUG, |
| 47 | __( 'Support', 'advanced-ads' ), |
| 48 | __( 'Support', 'advanced-ads' ), |
| 49 | 'manage_options', |
| 50 | ADVADS_SLUG . '-support', |
| 51 | [ $this, 'display' ] |
| 52 | ); |
| 53 | |
| 54 | $this->set_hook( $hook ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Enqueue assets |
| 59 | * |
| 60 | * @return void |
| 61 | */ |
| 62 | public function enqueue_assets(): void { |
| 63 | wp_advads()->registry->enqueue_style( 'screen-support' ); |
| 64 | wp_advads()->registry->enqueue_script( 'screen-support' ); |
| 65 | remove_all_actions( 'admin_notices' ); |
| 66 | remove_all_actions( 'wpstg.admin_notices' ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Display screen content. |
| 71 | * |
| 72 | * @return void |
| 73 | */ |
| 74 | public function display(): void { |
| 75 | include_once ADVADS_ABSPATH . 'views/admin/support/page.php'; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get links from the endpoint. |
| 80 | * |
| 81 | * @param string $endpoint The endpoint to get the links from. |
| 82 | * @param string $cache_key The cache key to store the links. |
| 83 | * |
| 84 | * @return array The links. |
| 85 | */ |
| 86 | public function get_links( $endpoint, $cache_key ): array { |
| 87 | $cache = get_transient( $cache_key ); |
| 88 | if ( $cache ) { |
| 89 | return $cache; |
| 90 | } |
| 91 | |
| 92 | $endpoint = 'https://wpadvancedads.com/wp-json/wp/v2' . $endpoint; |
| 93 | $response = wp_remote_get( $endpoint ); |
| 94 | if ( is_wp_error( $response ) ) { |
| 95 | return []; |
| 96 | } |
| 97 | |
| 98 | $data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 99 | if ( empty( $data ) ) { |
| 100 | return []; |
| 101 | } |
| 102 | |
| 103 | set_transient( $cache_key, $data, 24 * HOUR_IN_SECONDS ); |
| 104 | return $data; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Render a YouTube video. |
| 109 | * |
| 110 | * @param string $video_id The video ID. |
| 111 | * |
| 112 | * @return void |
| 113 | */ |
| 114 | public function render_youtube_video( $video_id ): void { |
| 115 | echo '<iframe src="https://www.youtube.com/embed/' . $video_id . '?controls=0" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>'; // phpcs:ignore |
| 116 | } |
| 117 | } |
| 118 |