| @@ -1,0 +1,65 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace Metricool\Controllers; | |
| 6 | + | |
| 7 | +if (!defined('ABSPATH')) { | |
| 8 | + exit; | |
| 9 | +} | |
| 10 | + | |
| 11 | +use Metricool\Traits\HasViews; | |
| 12 | +use Metricool\Traits\HasAllowlistControl; | |
| 13 | +use Metricool\Interfaces\ControllerInterface; | |
| 14 | +use Metricool\Support\Helpers\Storages\EnvironmentConfig; | |
| 15 | + | |
| 16 | +class AdminController implements ControllerInterface | |
| 17 | +{ | |
| 18 | + use HasAllowlistControl; | |
| 19 | + use HasViews; | |
| 20 | + | |
| 21 | + private EnvironmentConfig $env; | |
| 22 | + | |
| 23 | + public function __construct(EnvironmentConfig $env) | |
| 24 | + { | |
| 25 | + $this->env = $env; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public function register(): void | |
| 29 | + { | |
| 30 | + add_action('admin_enqueue_scripts', [$this, 'enqueueGeneralAdminStyles']); | |
| 31 | + add_filter('plugin_action_links_' . $this->env->getString('plugin.base_file'), [$this, 'addPluginSettingsAction']); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Method enqueues the css for general admin styles. | |
| 36 | + */ | |
| 37 | + public function enqueueGeneralAdminStyles(): void | |
| 38 | + { | |
| 39 | + wp_enqueue_style( | |
| 40 | + 'metricool-admin-general-styles', | |
| 41 | + $this->env->getUrl('plugin.url') . 'assets/css/admin.css', | |
| 42 | + [], | |
| 43 | + $this->env->getString('plugin.version') | |
| 44 | + ); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Adds settings and support link to the plugin page | |
| 49 | + */ | |
| 50 | + public function addPluginSettingsAction(array $links): array | |
| 51 | + { | |
| 52 | + if ($this->userCanManage() === false) { | |
| 53 | + return $links; | |
| 54 | + } | |
| 55 | + | |
| 56 | + $settings_link = '<a href="' . $this->env->getUrl('plugin.dashboard_url') . '">' . esc_html__('Settings', 'metricool') . '</a>'; | |
| 57 | + array_unshift($links, $settings_link); | |
| 58 | + | |
| 59 | + //support | |
| 60 | + $support = '<a rel="noopener noreferrer" target="_blank" href="' . esc_attr($this->env->getUrl('plugin.support_url')) . '">' . esc_html__('Support', 'metricool') . '</a>'; | |
| 61 | + array_unshift($links, $support); | |
| 62 | + | |
| 63 | + return $links; | |
| 64 | + } | |
| 65 | +} | |