PluginProbe
PhastPress / 1.78
PhastPress v1.78
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.78, at functions/deployment.php

135 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function phastpress_deploy() {
4 // We have to deploy on plugins_loaded action so we get wp_get_current_user() to be defined.
5 if (is_admin()) {
6 return;
7 }
8
9 // This is only defined in the main index.php.
10 if (!defined('WP_USE_THEMES') || !WP_USE_THEMES) {
11 return;
12 }
13
14 // Do not optimize when using editor plug-ins.
15 if (// Elementor
16 isset($_GET['elementor-preview'])
17 // YellowPencil
18 || (defined('YP_VERSION') && isset($_GET['yellow_pencil_frame']))
19 // Thrive Architect
20 || (isset($_GET['tve']) && $_GET['tve'] === 'true')
21 // Divi Visual Builder
22 || (isset($_GET['PageSpeed']) && $_GET['PageSpeed'] === 'off')
23 // Child Theme Configurator
24 || (isset($_GET['ModPagespeed']) && $_GET['ModPagespeed'] === 'off')
25 // Nimble Page Builder
26 || (
27 defined('NIMBLE_VERSION') && (
28 !empty($_GET['customize_changeset_uuid'])
29 || !empty($_POST['customize_changeset_uuid'])
30 )
31 )
32 // Asset CleanUp: Page Speed Booster
33 || (
34 defined('WPACU_LOAD_ASSETS_REQ_KEY')
35 && !empty($_REQUEST[WPACU_LOAD_ASSETS_REQ_KEY])
36 )
37 ) {
38 return;
39 }
40
41 // Support phast_no_defer script attribute.
42 add_filter('script_loader_tag', function ($tag, $handle) {
43 if (!wp_scripts()->get_data($handle, 'phast_no_defer')) {
44 return $tag;
45 }
46
47 return preg_replace('~<script\b~i', '$0 data-phast-no-defer', $tag);
48 }, 10, 2);
49
50 // Don't delay Monsterinsights analytics script.
51 add_filter('monsterinsights_tracking_analytics_script_attributes', function ($attrs) {
52 if (is_array($attrs)) {
53 $attrs['data-phast-no-defer'] = '';
54 }
55 return $attrs;
56 });
57
58 // Don't delay Slimstat Analytics.
59 add_filter('wp_print_scripts', function () {
60 if (!wp_script_is('wp_slimstat')) {
61 return;
62 }
63
64 // Don't defer the tracker script.
65 add_filter('script_loader_tag', function ($tag, $handle, $src) {
66 if ($handle !== 'wp_slimstat') {
67 return $tag;
68 }
69 return preg_replace('~<script\b~', '$0 data-phast-no-defer async', $tag);
70 }, 10, 3);
71
72 // Don't defer the inline parameters script.
73 ob_start(function ($chunk) {
74 return preg_replace('~(<script\b)([^>]*>\s*(/\*.*?\*/)?\s*var\s+SlimStatParams\s*=)~', '$1 data-phast-no-defer$2', $chunk);
75 }, 8192);
76 });
77
78 // Don't delay Google Site Kit Analytics.
79 add_filter('wp_print_scripts', function () {
80 wp_scripts()->add_data('google_gtagjs', 'phast_no_defer', true);
81 });
82
83 // Don't delay GA Google Analytics script.
84 add_filter('ga_google_analytics_script_atts_ext', function ($atts) {
85 return $atts . ' data-phast-no-defer';
86 });
87
88 add_filter('ga_google_analytics_script_atts', function ($atts) {
89 return $atts . ' data-phast-no-defer';
90 });
91
92 $sdk = phastpress_get_plugin_sdk();
93 $handler = $sdk->getPhastAPI()->deployOutputBufferForDocument();
94
95 // Allow disabling PhastPress with hook.
96 add_filter('template_redirect', function () use ($handler) {
97 if (apply_filters('phastpress_disable', false)) {
98 $handler->cancel();
99 }
100 }, 100);
101
102 $plugin_config = $sdk->getPluginConfiguration();
103 $display_footer = $plugin_config->shouldDisplayFooter();
104 if ($display_footer) {
105 add_action('wp_head', 'phastpress_render_footer_css', 0, 2);
106 add_action('wp_footer', 'phastpress_render_footer');
107 }
108 }
109
110 function phastpress_render_footer_css() {
111 echo <<<STYLE
112 <style>
113 .phast-footer a:link,
114 .phast-footer a:visited,
115 .phast-footer a:hover {
116 display: block;
117 font-size: 12px;
118 text-align: center;
119 height: 20px;
120 background: black;
121 color: white;
122 position: relative;
123 top: 0;
124 z-index: 1000;
125 }
126 </style>
127 STYLE;
128 }
129
130 function phastpress_render_footer() {
131 echo '<div class="phast-footer">'
132 . '<a href="https://wordpress.org/plugins/phastpress/" target="_blank">'
133 . __('Optimized by PhastPress', 'phastpress') . '</a></div>';
134 }
135