| 1 |
<?php |
| 2 |
|
| 3 |
use Kibo\PhastPlugins\PhastPress\Compat; |
| 4 |
|
| 5 |
function phastpress_deploy() { |
| 6 |
// We have to deploy on plugins_loaded action so we get wp_get_current_user() to be defined. |
| 7 |
if (is_admin()) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
// This is only defined in the main index.php. |
| 12 |
if (!defined('WP_USE_THEMES') || !WP_USE_THEMES) { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
// Do not optimize when using editor plug-ins. |
| 17 |
if (// Elementor |
| 18 |
isset($_GET['elementor-preview']) |
| 19 |
// YellowPencil |
| 20 |
|| (defined('YP_VERSION') && isset($_GET['yellow_pencil_frame'])) |
| 21 |
// Thrive Architect |
| 22 |
|| (isset($_GET['tve']) && $_GET['tve'] === 'true') |
| 23 |
// Divi Visual Builder |
| 24 |
|| (isset($_GET['PageSpeed']) && $_GET['PageSpeed'] === 'off') |
| 25 |
// Child Theme Configurator |
| 26 |
|| (isset($_GET['ModPagespeed']) && $_GET['ModPagespeed'] === 'off') |
| 27 |
// Nimble Page Builder |
| 28 |
|| ( |
| 29 |
defined('NIMBLE_VERSION') && ( |
| 30 |
!empty($_GET['customize_changeset_uuid']) |
| 31 |
|| !empty($_POST['customize_changeset_uuid']) |
| 32 |
) |
| 33 |
) |
| 34 |
// Asset CleanUp: Page Speed Booster |
| 35 |
|| ( |
| 36 |
defined('WPACU_LOAD_ASSETS_REQ_KEY') |
| 37 |
&& !empty($_REQUEST[WPACU_LOAD_ASSETS_REQ_KEY]) |
| 38 |
) |
| 39 |
) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
// Support phast_no_defer script attribute. |
| 44 |
add_filter('script_loader_tag', function ($tag, $handle) { |
| 45 |
if (!wp_scripts()->get_data($handle, 'phast_no_defer')) { |
| 46 |
return $tag; |
| 47 |
} |
| 48 |
|
| 49 |
return preg_replace('~<script\b~i', '$0 data-phast-no-defer', $tag); |
| 50 |
}, 10, 2); |
| 51 |
|
| 52 |
foreach ([ |
| 53 |
Compat\MonsterInsights::class, |
| 54 |
Compat\Slimstat::class, |
| 55 |
Compat\GoogleSiteKit::class, |
| 56 |
Compat\GAGoogleAnalytics::class, |
| 57 |
Compat\AdThrive::class, |
| 58 |
] as $class) { |
| 59 |
(new $class())->setup(); |
| 60 |
} |
| 61 |
|
| 62 |
$sdk = phastpress_get_plugin_sdk(); |
| 63 |
$handler = $sdk->getPhastAPI()->deployOutputBufferForDocument(); |
| 64 |
|
| 65 |
// Allow disabling PhastPress with hook. |
| 66 |
add_filter('template_redirect', function () use ($handler) { |
| 67 |
if (apply_filters('phastpress_disable', false)) { |
| 68 |
$handler->cancel(); |
| 69 |
} |
| 70 |
}, 100); |
| 71 |
|
| 72 |
$plugin_config = $sdk->getPluginConfiguration(); |
| 73 |
$display_footer = $plugin_config->shouldDisplayFooter(); |
| 74 |
if ($display_footer) { |
| 75 |
add_action('wp_head', 'phastpress_render_footer_css', 0, 2); |
| 76 |
add_action('wp_footer', 'phastpress_render_footer'); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
function phastpress_render_footer_css() { |
| 81 |
echo <<<STYLE |
| 82 |
<style> |
| 83 |
.phast-footer a:link, |
| 84 |
.phast-footer a:visited, |
| 85 |
.phast-footer a:hover { |
| 86 |
display: block; |
| 87 |
font-size: 12px; |
| 88 |
text-align: center; |
| 89 |
height: 20px; |
| 90 |
background: black; |
| 91 |
color: white; |
| 92 |
position: relative; |
| 93 |
top: 0; |
| 94 |
z-index: 1000; |
| 95 |
} |
| 96 |
</style> |
| 97 |
STYLE; |
| 98 |
} |
| 99 |
|
| 100 |
function phastpress_render_footer() { |
| 101 |
echo '<div class="phast-footer">' |
| 102 |
. '<a href="https://wordpress.org/plugins/phastpress/" target="_blank">' |
| 103 |
. __('Optimized by PhastPress', 'phastpress') . '</a></div>'; |
| 104 |
} |
| 105 |
|