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

122 lines 3.6 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 // WPBakery
40 || (
41 defined('WPB_VC_VERSION')
42 && isset($_GET['vc_editable'])
43 && $_GET['vc_editable'] === 'true'
44 )
45 ) {
46 return;
47 }
48
49 // Support phast_no_defer script attribute.
50 add_filter('script_loader_tag', function ($tag, $handle) {
51 if (!wp_scripts()->get_data($handle, 'phast_no_defer')) {
52 return $tag;
53 }
54
55 return preg_replace('~<script\b~i', '$0 data-phast-no-defer', $tag);
56 }, 10, 2);
57
58 add_filter('wp_print_scripts', function () {
59 foreach (wp_scripts()->registered as $handle => $item) {
60 if (empty($item->extra['phast_no_defer'])
61 || empty($item->extra['data'])
62 ) {
63 continue;
64 }
65 $item->extra['data'] = "'phast-no-defer';\n" . $item->extra['data'];
66 }
67 });
68
69 foreach ([
70 Compat\MonsterInsights::class,
71 Compat\Slimstat::class,
72 Compat\GoogleSiteKit::class,
73 Compat\GAGoogleAnalytics::class,
74 Compat\AdThrive::class,
75 ] as $class) {
76 (new $class())->setup();
77 }
78
79 $sdk = phastpress_get_plugin_sdk();
80 $handler = $sdk->getPhastAPI()->deployOutputBufferForDocument();
81
82 // Allow disabling PhastPress with hook.
83 add_action('template_redirect', function () use ($handler) {
84 if (apply_filters('phastpress_disable', false)) {
85 $handler->cancel();
86 }
87 }, 100);
88
89 $plugin_config = $sdk->getPluginConfiguration();
90 $display_footer = $plugin_config->shouldDisplayFooter();
91 if ($display_footer) {
92 add_action('wp_head', 'phastpress_render_footer_css', 0, 2);
93 add_action('wp_footer', 'phastpress_render_footer');
94 }
95 }
96
97 function phastpress_render_footer_css() {
98 echo <<<STYLE
99 <style>
100 .phast-footer a:link,
101 .phast-footer a:visited,
102 .phast-footer a:hover {
103 display: block;
104 font-size: 12px;
105 text-align: center;
106 height: 20px;
107 background: black;
108 color: white;
109 position: relative;
110 top: 0;
111 z-index: 1000;
112 }
113 </style>
114 STYLE;
115 }
116
117 function phastpress_render_footer() {
118 echo '<div class="phast-footer">'
119 . '<a href="https://wordpress.org/plugins/phastpress/" target="_blank">'
120 . __('Optimized by PhastPress', 'phastpress') . '</a></div>';
121 }
122