<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing namespace MailPoet\Config; if (!defined('ABSPATH')) exit; use MailPoet\Util\Helpers; use MailPoet\WP\Notice as WPNotice; class RequirementsChecker { const TEST_FOLDER_PERMISSIONS = 'TempFolderCreation'; const TEST_XML_EXTENSION = 'XmlExtension'; const TEST_VENDOR_SOURCE = 'VendorSource'; public $displayErrorNotice; public $vendorClasses = [ '\Cron\CronExpression', ]; public function __construct( $displayErrorNotice = true ) { $this->displayErrorNotice = $displayErrorNotice; } public function checkAllRequirements() { $availableTests = [ self::TEST_FOLDER_PERMISSIONS, self::TEST_XML_EXTENSION, self::TEST_VENDOR_SOURCE, ]; $results = []; foreach ($availableTests as $test) { $callback = [$this, 'check' . $test]; if (is_callable($callback)) { $results[$test] = call_user_func($callback); } } return $results; } public function checkTempFolderCreation() { $paths = [ 'temp_path' => Env::$tempPath, ]; if (!is_dir($paths['temp_path']) && !wp_mkdir_p($paths['temp_path'])) { $error = Helpers::replaceLinkTags( __('MailPoet requires write permissions inside the /wp-content/uploads folder. Please read our [link]instructions[/link] on how to resolve this issue.', 'mailpoet'), 'https://kb.mailpoet.com/article/152-minimum-requirements-for-mailpoet-3#folder_permissions', ['target' => '_blank'] ); return $this->processError($error); } foreach ($paths as $path) { $indexFile = $path . '/index.php'; if (!file_exists($indexFile)) { file_put_contents( $path . '/index.php', str_replace('\n', PHP_EOL, '<?php\n\n// Silence is golden') ); } } return true; } public function checkXmlExtension() { if (extension_loaded('xml')) return true; $error = Helpers::replaceLinkTags( __('MailPoet requires an XML PHP extension. Please read our [link]instructions[/link] on how to resolve this issue.', 'mailpoet'), 'https://kb.mailpoet.com/article/152-minimum-requirements-for-mailpoet-3#php_extension', ['target' => '_blank'] ); return $this->processError($error); } public function checkVendorSource() { foreach ($this->vendorClasses as $dependency) { $dependencyPath = $this->getDependencyPath($dependency); if (!$dependencyPath) { $error = sprintf( // translators: %s is the dependency. __('A MailPoet dependency (%s) does not appear to be loaded correctly, thus MailPoet will not work correctly. Please reinstall the plugin.', 'mailpoet'), $dependency ); return $this->processError($error); } $pattern = '#' . preg_quote(Env::$path) . '[\\\/]#'; $isLoadedByPlugin = preg_match($pattern, $dependencyPath); if (!$isLoadedByPlugin) { $error = sprintf( // translators: %1$s is the dependency and %2$s the plugin. __('MailPoet has detected a dependency conflict (%1$s) with another plugin (%2$s), which may cause unexpected behavior. Please disable the offending plugin to fix this issue.', 'mailpoet'), $dependency, $dependencyPath ); return $this->processError($error); } } return true; } private function getDependencyPath($namespacedClass) { try { $reflector = new \ReflectionClass($namespacedClass); return $reflector->getFileName(); } catch (\ReflectionException $ex) { return false; } } public function processError($error) { if ($this->displayErrorNotice) { WPNotice::displayError($error); } return false; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
PopulatorData | Folder | 0755 |
|
|
AccessControl.php | File | 3.89 KB | 0644 |
|
Activator.php | File | 4.94 KB | 0644 |
|
AssetsLoader.php | File | 1.68 KB | 0644 |
|
Capabilities.php | File | 2.87 KB | 0644 |
|
Changelog.php | File | 5.04 KB | 0644 |
|
DeactivationPoll.php | File | 1.43 KB | 0644 |
|
DeferredAdminNotices.php | File | 1.16 KB | 0644 |
|
Env.php | File | 4.16 KB | 0644 |
|
Hooks.php | File | 20.06 KB | 0644 |
|
HooksWooCommerce.php | File | 6.76 KB | 0644 |
|
Initializer.php | File | 16.58 KB | 0644 |
|
Installer.php | File | 3.12 KB | 0644 |
|
Localizer.php | File | 2.49 KB | 0644 |
|
Menu.php | File | 23.54 KB | 0644 |
|
PersonalDataErasers.php | File | 769 B | 0644 |
|
PersonalDataExporters.php | File | 3.22 KB | 0644 |
|
PluginActivatedHook.php | File | 776 B | 0644 |
|
Populator.php | File | 23.37 KB | 0644 |
|
PrivacyPolicy.php | File | 4.53 KB | 0644 |
|
Renderer.php | File | 4.34 KB | 0644 |
|
RendererFactory.php | File | 670 B | 0644 |
|
RequirementsChecker.php | File | 3.73 KB | 0644 |
|
Router.php | File | 1006 B | 0644 |
|
ServicesChecker.php | File | 7.04 KB | 0644 |
|
Shortcodes.php | File | 8.63 KB | 0644 |
|
SilentUpgraderSkin.php | File | 570 B | 0644 |
|
SubscriberChangesNotifier.php | File | 5 KB | 0644 |
|
TranslationUpdater.php | File | 7.92 KB | 0644 |
|
TwigEnvironment.php | File | 694 B | 0644 |
|
TwigFileSystemCache.php | File | 853 B | 0644 |
|
Updater.php | File | 1.97 KB | 0644 |
|
index.php | File | 6 B | 0644 |
|