<?php namespace MailPoet\Config; if (!defined('ABSPATH')) exit; use MailPoet\Util\Helpers; use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Notice as WPNotice; class RequirementsChecker { const TEST_FOLDER_PERMISSIONS = 'TempAndCacheFolderCreation'; const TEST_PDO_EXTENSION = 'PDOExtension'; const TEST_XML_EXTENSION = 'XmlExtension'; const TEST_VENDOR_SOURCE = 'VendorSource'; public $displayErrorNotice; public $vendorClasses = [ '\pQuery', '\Cron\CronExpression', '\Html2Text\Html2Text', ]; public function __construct( $displayErrorNotice = true ) { $this->displayErrorNotice = $displayErrorNotice; } public function checkAllRequirements() { $availableTests = [ self::TEST_PDO_EXTENSION, 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 checkTempAndCacheFolderCreation() { $paths = [ 'temp_path' => Env::$tempPath, 'cache_path' => Env::$cachePath, ]; if (!is_dir($paths['cache_path']) && !wp_mkdir_p($paths['cache_path'])) { $error = Helpers::replaceLinkTags( WPFunctions::get()->__('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 checkPDOExtension() { if (extension_loaded('pdo') && extension_loaded('pdo_mysql')) return true; $error = Helpers::replaceLinkTags( WPFunctions::get()->__('MailPoet requires a PDO_MYSQL 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 checkXmlExtension() { if (extension_loaded('xml')) return true; $error = Helpers::replaceLinkTags( WPFunctions::get()->__('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( WPFunctions::get()->__('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( WPFunctions::get()->__('MailPoet has detected a dependency conflict (%s) with another plugin (%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.23 KB | 0644 |
|
Activator.php | File | 2.22 KB | 0644 |
|
AssetsLoader.php | File | 801 B | 0644 |
|
Capabilities.php | File | 2.8 KB | 0644 |
|
Changelog.php | File | 3.9 KB | 0644 |
|
Database.php | File | 2.78 KB | 0644 |
|
DatabaseInitializer.php | File | 601 B | 0644 |
|
DeferredAdminNotices.php | File | 1.07 KB | 0644 |
|
Env.php | File | 3.93 KB | 0644 |
|
Hooks.php | File | 10.32 KB | 0644 |
|
HooksWooCommerce.php | File | 3.97 KB | 0644 |
|
Initializer.php | File | 9.92 KB | 0644 |
|
Installer.php | File | 2.69 KB | 0644 |
|
Localizer.php | File | 1.15 KB | 0644 |
|
MP2Migrator.php | File | 35.34 KB | 0644 |
|
Menu.php | File | 14.04 KB | 0644 |
|
Migrator.php | File | 25.73 KB | 0644 |
|
PersonalDataErasers.php | File | 622 B | 0644 |
|
PersonalDataExporters.php | File | 2.64 KB | 0644 |
|
PluginActivatedHook.php | File | 682 B | 0644 |
|
Populator.php | File | 29.67 KB | 0644 |
|
PrivacyPolicy.php | File | 3.37 KB | 0644 |
|
Renderer.php | File | 3.95 KB | 0644 |
|
RendererFactory.php | File | 474 B | 0644 |
|
RequirementsChecker.php | File | 4.3 KB | 0644 |
|
Router.php | File | 846 B | 0644 |
|
ServicesChecker.php | File | 4.93 KB | 0644 |
|
Shortcodes.php | File | 6.22 KB | 0644 |
|
Updater.php | File | 1.71 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|