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 / functions / deployment.php

deployment.php in PhastPress 1.82, at functions/deployment.php

116 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 add_filter('wp_print_scripts', function () {
53 foreach (wp_scripts()->registered as $handle => $item) {
54 if (empty($item->extra['phast_no_defer'])
55 || empty($item->extra['data'])
56 ) {
57 continue;
58 }
59 $item->extra['data'] = "'phast-no-defer';\n" . $item->extra['data'];
60 }
61 });
62
63 foreach ([
64 Compat\MonsterInsights::class,
65 Compat\Slimstat::class,
66 Compat\GoogleSiteKit::class,
67 Compat\GAGoogleAnalytics::class,
68 Compat\AdThrive::class,
69 ] as $class) {
70 (new $class())->setup();
71 }
72
73 $sdk = phastpress_get_plugin_sdk();
74 $handler = $sdk->getPhastAPI()->deployOutputBufferForDocument();
75
76 // Allow disabling PhastPress with hook.
77 add_filter('template_redirect', function () use ($handler) {
78 if (apply_filters('phastpress_disable', false)) {
79 $handler->cancel();
80 }
81 }, 100);
82
83 $plugin_config = $sdk->getPluginConfiguration();
84 $display_footer = $plugin_config->shouldDisplayFooter();
85 if ($display_footer) {
86 add_action('wp_head', 'phastpress_render_footer_css', 0, 2);
87 add_action('wp_footer', 'phastpress_render_footer');
88 }
89 }
90
91 function phastpress_render_footer_css() {
92 echo <<<STYLE
93 <style>
94 .phast-footer a:link,
95 .phast-footer a:visited,
96 .phast-footer a:hover {
97 display: block;
98 font-size: 12px;
99 text-align: center;
100 height: 20px;
101 background: black;
102 color: white;
103 position: relative;
104 top: 0;
105 z-index: 1000;
106 }
107 </style>
108 STYLE;
109 }
110
111 function phastpress_render_footer() {
112 echo '<div class="phast-footer">'
113 . '<a href="https://wordpress.org/plugins/phastpress/" target="_blank">'
114 . __('Optimized by PhastPress', 'phastpress') . '</a></div>';
115 }
116