PopulatorData
2 months ago
AccessControl.php
2 years ago
Activator.php
2 months ago
AssetsLoader.php
2 weeks ago
Capabilities.php
2 months ago
Changelog.php
2 months ago
DeactivationPoll.php
3 years ago
DeferredAdminNotices.php
2 months ago
Env.php
6 months ago
Hooks.php
1 month ago
HooksWooCommerce.php
1 month ago
Initializer.php
1 month ago
Installer.php
10 months ago
Localizer.php
3 years ago
Menu.php
1 month ago
PersonalDataErasers.php
1 month ago
PersonalDataExporters.php
1 month ago
PluginActivatedHook.php
3 years ago
Populator.php
2 weeks ago
PrivacyPolicy.php
1 month ago
Renderer.php
1 year ago
RendererFactory.php
3 years ago
RequirementsChecker.php
2 months ago
Router.php
2 months ago
ServicesChecker.php
3 years ago
Shortcodes.php
1 month ago
SilentUpgraderSkin.php
3 years ago
SubscriberChangesNotifier.php
2 months ago
TranslationUpdater.php
3 months ago
TwigEnvironment.php
1 year ago
TwigFileSystemCache.php
3 years ago
Updater.php
4 days ago
index.php
3 years ago
DeactivationPoll.php
66 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Config; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | |
| 10 | class DeactivationPoll { |
| 11 | |
| 12 | /** @var WPFunctions */ |
| 13 | private $wp; |
| 14 | |
| 15 | /** @var Renderer */ |
| 16 | private $renderer; |
| 17 | |
| 18 | public function __construct( |
| 19 | WPFunctions $wp, |
| 20 | Renderer $renderer |
| 21 | ) { |
| 22 | $this->wp = $wp; |
| 23 | $this->renderer = $renderer; |
| 24 | } |
| 25 | |
| 26 | public function init() { |
| 27 | $this->wp->addAction('admin_print_scripts', [$this, 'css']); |
| 28 | $this->wp->addAction('admin_footer', [$this, 'modal']); |
| 29 | } |
| 30 | |
| 31 | private function shouldShow(): bool { |
| 32 | if (!function_exists('get_current_screen')) { |
| 33 | return false; |
| 34 | } |
| 35 | $screen = $this->wp->getCurrentScreen(); |
| 36 | if (is_null($screen)) { |
| 37 | return false; |
| 38 | } |
| 39 | return in_array($screen->id, ['plugins', 'plugins-network'], true); |
| 40 | } |
| 41 | |
| 42 | public function css(): void { |
| 43 | if (!$this->shouldShow()) { |
| 44 | return; |
| 45 | } |
| 46 | $this->render('deactivationPoll/css.html'); |
| 47 | } |
| 48 | |
| 49 | public function modal(): void { |
| 50 | if (!$this->shouldShow()) { |
| 51 | return; |
| 52 | } |
| 53 | $this->render('deactivationPoll/index.html'); |
| 54 | } |
| 55 | |
| 56 | private function render($template): void { |
| 57 | try { |
| 58 | // phpcs:disable -- because we use echo here, WordPress sniffs reported a warning |
| 59 | echo $this->renderer->render($template); |
| 60 | // phpcs:enable |
| 61 | } catch (\Exception $e) { |
| 62 | // if the website fails to render we have other places to catch and display the error |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 |