PluginProbe
PhastPress / 1.82
PhastPress v1.82
3.12 3.11 1.75 1.76 1.77 1.78 1.79 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.90 1.91 1.92 1.93 1.94 1.95 1.96 1.97 All 119 releases
phastpress / classes / Compat / AdThrive.php

AdThrive.php in PhastPress 1.82, at classes/Compat/AdThrive.php

50 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Kibo\PhastPlugins\PhastPress\Compat;
3
4 class AdThrive {
5 public function setup() {
6 add_action('template_redirect', function () {
7 $this->template_redirect();
8 });
9 }
10
11 private function template_redirect() {
12 if (!class_exists(\AdThrive_Ads\Components\Ads\Main::class)) {
13 return;
14 }
15
16 if (!isset($GLOBALS['wp_filter']['wp_head'])) {
17 return;
18 }
19
20 $filter = $GLOBALS['wp_filter']['wp_head'];
21
22 array_walk($filter->callbacks, function (&$callbacks) {
23 array_walk($callbacks, function (&$callback) {
24 $function = $callback['function'];
25 if (is_array($function)
26 && isset($function[0])
27 && $function[0] instanceof \AdThrive_Ads\Components\Ads\Main
28 && isset($function[1])
29 && $function[1] === 'ad_head'
30 ) {
31 $callback['function'] = function (...$args) use ($function) {
32 ob_start(function ($buffer) {
33 return $this->processOutput($buffer);
34 });
35 try {
36 return call_user_func_array($function, $args);
37 } finally {
38 ob_end_flush();
39 }
40 };
41 }
42 });
43 });
44 }
45
46 private function processOutput($output) {
47 return preg_replace('~<script\b~i', '$0 data-phast-no-defer', $output);
48 }
49 }
50