PopulatorData
3 months ago
AccessControl.php
2 years ago
Activator.php
2 months ago
AssetsLoader.php
1 day ago
Capabilities.php
3 months ago
Changelog.php
3 months ago
DeactivationPoll.php
3 years ago
DeferredAdminNotices.php
3 months ago
Env.php
7 months ago
Hooks.php
1 week ago
HooksWooCommerce.php
1 month ago
Initializer.php
1 month ago
Installer.php
11 months ago
Localizer.php
2 weeks ago
Menu.php
1 month ago
PersonalDataErasers.php
1 month ago
PersonalDataExporters.php
1 month ago
PluginActivatedHook.php
3 years ago
Populator.php
1 month ago
PrivacyPolicy.php
1 month ago
Renderer.php
1 year ago
RendererFactory.php
3 years ago
RequirementsChecker.php
2 months ago
Router.php
3 months ago
ServicesChecker.php
3 years ago
Shortcodes.php
2 weeks ago
SilentUpgraderSkin.php
3 years ago
SubscriberChangesNotifier.php
3 months ago
TranslationUpdater.php
3 months ago
TwigEnvironment.php
1 year ago
TwigFileSystemCache.php
3 years ago
Updater.php
3 weeks ago
index.php
3 years ago
AssetsLoader.php
73 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Config; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WP\Functions as WPFunctions; |
| 9 | |
| 10 | class AssetsLoader { |
| 11 | private const FORM_EDITOR_WORDPRESS_STYLE_DEPENDENCIES = [ |
| 12 | 'wp-components', |
| 13 | 'wp-block-library', |
| 14 | 'wp-block-library-theme', |
| 15 | 'wp-block-editor', |
| 16 | 'wp-edit-blocks', |
| 17 | 'wp-editor', |
| 18 | 'wp-edit-post', |
| 19 | 'wp-format-library', |
| 20 | ]; |
| 21 | |
| 22 | /** @var Renderer */ |
| 23 | private $renderer; |
| 24 | |
| 25 | /** @var WPFunctions */ |
| 26 | private $wp; |
| 27 | |
| 28 | public function __construct( |
| 29 | RendererFactory $rendererFactory, |
| 30 | WPFunctions $wp |
| 31 | ) { |
| 32 | $this->renderer = $rendererFactory->getRenderer(); |
| 33 | $this->wp = $wp; |
| 34 | } |
| 35 | |
| 36 | public function loadStyles(): void { |
| 37 | // MailPoet plugin style should be loaded on all mailpoet sites |
| 38 | $page = isset($_GET['page']) && is_string($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : null; |
| 39 | if ($page && strpos($page, 'mailpoet-') === 0) { |
| 40 | $this->enqueueStyle('mailpoet-plugin', [ |
| 41 | 'forms', // To prevent conflict in CSS with WP forms we need to add dependency |
| 42 | 'buttons', |
| 43 | // @wordpress/components styles come from the core `wp-components` handle and must |
| 44 | // load before MailPoet overrides. WordPress 7.1+ prints them on every admin screen |
| 45 | // (command palette), so a bundled copy would apply the same styles twice. |
| 46 | 'wp-components', |
| 47 | ]); |
| 48 | } |
| 49 | if ($page === 'mailpoet-form-editor') { |
| 50 | $this->enqueueStyle( |
| 51 | 'mailpoet-form-editor', |
| 52 | array_merge(['mailpoet-plugin'], self::FORM_EDITOR_WORDPRESS_STYLE_DEPENDENCIES) |
| 53 | ); |
| 54 | $this->enqueueStyle('mailpoet-public'); |
| 55 | } |
| 56 | if ($page === 'mailpoet-form-editor-template-selection') { |
| 57 | $this->enqueueStyle('mailpoet-form-editor', ['mailpoet-plugin', 'wp-components']); |
| 58 | } |
| 59 | // We reuse a part of CSS in the newsletter editor |
| 60 | if ($page === 'mailpoet-newsletter-editor') { |
| 61 | $this->enqueueStyle('mailpoet-form-editor', ['mailpoet-plugin']); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | private function enqueueStyle(string $name, array $deps = []): void { |
| 66 | $this->wp->wpEnqueueStyle( |
| 67 | $name, |
| 68 | Env::$assetsUrl . '/dist/css/' . $this->renderer->getCssAsset("{$name}.css"), |
| 69 | $deps |
| 70 | ); |
| 71 | } |
| 72 | } |
| 73 |