mailpoet
Last commit date
assets
2 weeks ago
generated
2 weeks ago
lang
2 weeks ago
lib
2 weeks ago
lib-3rd-party
4 months ago
vendor
2 weeks ago
vendor-prefixed
3 months ago
views
2 weeks ago
.gitleaksignore
1 year ago
index.php
3 years ago
license.txt
4 years ago
mailpoet-cron.php
4 months ago
mailpoet.php
2 weeks ago
mailpoet_initializer.php
3 months ago
readme.txt
2 weeks ago
mailpoet_initializer.php
127 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | |
| 5 | |
| 6 | use Automattic\WooCommerce\EmailEditor\Email_Editor_Container; |
| 7 | use MailPoet\Config\Env; |
| 8 | use MailPoet\Config\RequirementsChecker; |
| 9 | use Tracy\Debugger; |
| 10 | |
| 11 | if (empty($mailpoetPlugin)) exit; |
| 12 | |
| 13 | require_once($mailpoetPlugin['autoloader']); |
| 14 | |
| 15 | if (PHP_VERSION_ID >= 80200) { |
| 16 | $tracyPath = __DIR__ . '/tools/vendor/tracy.phar'; |
| 17 | } else { |
| 18 | $tracyPath = __DIR__ . '/tools/vendor/tracy-legacy.phar'; |
| 19 | } |
| 20 | if (WP_DEBUG && PHP_VERSION_ID >= 70100 && file_exists($tracyPath)) { |
| 21 | require_once $tracyPath; |
| 22 | |
| 23 | if (getenv('MAILPOET_TRACY_PRODUCTION_MODE')) { |
| 24 | $logDir = getenv('MAILPOET_TRACY_LOG_DIR'); |
| 25 | if (!$logDir) { |
| 26 | throw new RuntimeException("Environment variable 'MAILPOET_TRACY_LOG_DIR' was not set."); |
| 27 | } |
| 28 | |
| 29 | if (!is_dir($logDir)) { |
| 30 | @mkdir($logDir, 0777, true); |
| 31 | } |
| 32 | |
| 33 | if (!is_writable($logDir)) { |
| 34 | throw new RuntimeException("Logging directory '$logDir' is not writable.'"); |
| 35 | } |
| 36 | |
| 37 | Debugger::enable(Debugger::PRODUCTION, $logDir); |
| 38 | Debugger::$logSeverity = E_ALL; |
| 39 | } else { |
| 40 | function render_tracy() { |
| 41 | ob_start(); |
| 42 | Debugger::renderLoader(); |
| 43 | $tracyScriptHtml = ob_get_clean(); |
| 44 | |
| 45 | // strip 'async' to ensure all AJAX request are caught |
| 46 | // (even when fired immediately after page starts loading) |
| 47 | // see: https://github.com/nette/tracy/issues/246 |
| 48 | $tracyScriptHtml = str_replace('async', '', $tracyScriptHtml); |
| 49 | |
| 50 | // set higher number of displayed AJAX rows |
| 51 | $maxAjaxRows = 4; |
| 52 | $tracyScriptHtml .= "<script>window.TracyMaxAjaxRows = $maxAjaxRows;</script>\n"; |
| 53 | |
| 54 | // just minor adjustments to Debugger::renderLoader() output |
| 55 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 56 | echo $tracyScriptHtml; |
| 57 | } |
| 58 | |
| 59 | add_action('admin_enqueue_scripts', 'render_tracy', PHP_INT_MAX, 0); |
| 60 | session_start(); |
| 61 | Debugger::enable(Debugger::DEVELOPMENT); |
| 62 | |
| 63 | // Fix Tracy info panel error: when Composer\Autoload\ClassLoader is loaded |
| 64 | // from a plugin without autoload_psr4.php (e.g., Query Monitor), Tracy's |
| 65 | // info panel fails with "Undefined variable $baseDir". Wrap the panel to |
| 66 | // suppress this specific error. |
| 67 | $bar = Debugger::getBar(); |
| 68 | $origInfoPanel = $bar->getPanel('Tracy:info'); |
| 69 | $bar->addPanel(new class($origInfoPanel) implements \Tracy\IBarPanel { |
| 70 | private $inner; |
| 71 | |
| 72 | public function __construct( |
| 73 | \Tracy\IBarPanel $inner |
| 74 | ) { |
| 75 | $this->inner = $inner; |
| 76 | } |
| 77 | |
| 78 | public function getTab(): string { |
| 79 | return $this->inner->getTab(); |
| 80 | } |
| 81 | |
| 82 | public function getPanel(): string { |
| 83 | $prev = set_error_handler(function ($severity, $message, $file) use (&$prev) { |
| 84 | if (strpos($message, 'Undefined variable') !== false && strpos($file, 'info.panel.phtml') !== false) { |
| 85 | return true; |
| 86 | } |
| 87 | return $prev ? $prev($severity, $message, $file, func_get_arg(3)) : false; |
| 88 | }); |
| 89 | try { |
| 90 | return $this->inner->getPanel(); |
| 91 | } finally { |
| 92 | restore_error_handler(); |
| 93 | } |
| 94 | } |
| 95 | }, 'Tracy:info'); |
| 96 | |
| 97 | if (getenv('MAILPOET_DISABLE_TRACY_PANEL')) { |
| 98 | Debugger::$showBar = false; |
| 99 | } |
| 100 | } |
| 101 | define('MAILPOET_DEVELOPMENT', true); |
| 102 | } |
| 103 | |
| 104 | define('MAILPOET_VERSION', $mailpoetPlugin['version']); |
| 105 | |
| 106 | Env::init( |
| 107 | $mailpoetPlugin['filename'], |
| 108 | $mailpoetPlugin['version'] |
| 109 | ); |
| 110 | |
| 111 | $requirements = new RequirementsChecker(); |
| 112 | $requirementsCheckResults = $requirements->checkAllRequirements(); |
| 113 | if ( |
| 114 | !$requirementsCheckResults[RequirementsChecker::TEST_VENDOR_SOURCE] |
| 115 | ) { |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | // Ensure functions like get_plugins, etc. |
| 120 | require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 121 | |
| 122 | // Initialize the Email Editor container to allow getting its instances in MailPoet constructors. |
| 123 | Email_Editor_Container::init(); |
| 124 | |
| 125 | $initializer = MailPoet\DI\ContainerWrapper::getInstance()->get(MailPoet\Config\Initializer::class); |
| 126 | $initializer->init(); |
| 127 |