DataInconsistency
2 weeks ago
License
2 months ago
Notices
2 months ago
pQuery
2 months ago
APIPermissionHelper.php
1 year ago
CdnAssetUrl.php
3 years ago
ConflictResolver.php
1 month ago
Cookies.php
2 months ago
DBCollationChecker.php
2 months ago
DOM.php
2 years ago
DateConverter.php
3 years ago
FreeDomains.php
3 years ago
Headers.php
1 year ago
Helpers.php
1 month ago
Installation.php
1 year ago
LegacyDatabase.php
1 year ago
Request.php
2 months ago
SecondLevelDomainNames.php
3 years ago
Security.php
2 months ago
ThirdPartyOutput.php
1 month ago
Url.php
2 months ago
index.php
3 years ago
ThirdPartyOutput.php
42 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Util; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class ThirdPartyOutput { |
| 9 | /** |
| 10 | * Public email pages (view-in-browser, public share) emit bare, fully-rendered |
| 11 | * email HTML and exit early. They include no wp_head()/wp_footer(), so no |
| 12 | * front-end JS ever loads. Image-optimizer / lazy-load plugins that buffer the |
| 13 | * whole page output and rewrite <img src> into JS-driven <img data-src> |
| 14 | * placeholders therefore break every image: the placeholder is never swapped |
| 15 | * back in because their loader script is absent. |
| 16 | * |
| 17 | * Signal those plugins to skip this response, and discard any output buffers |
| 18 | * they already opened so their flush callbacks never process our HTML. |
| 19 | */ |
| 20 | public static function preventHtmlRewriting(): void { |
| 21 | $bypassConstants = [ |
| 22 | 'DONOTCACHEPAGE', |
| 23 | 'DONOTMINIFY', |
| 24 | 'DONOTLAZYLOAD', |
| 25 | 'DONOTROCKETOPTIMIZE', |
| 26 | ]; |
| 27 | foreach ($bypassConstants as $constant) { |
| 28 | if (!defined($constant)) { |
| 29 | define($constant, true); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // Discard foreign output buffers. Stop if a buffer cannot be removed (e.g. |
| 34 | // zlib.output_compression) to avoid an infinite loop. |
| 35 | while (ob_get_level() > 0) { |
| 36 | if (!ob_end_clean()) { |
| 37 | break; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 |