Changeset 3491877
- Timestamp:
- 03/26/2026 02:39:23 PM (9 days ago)
- Location:
- onsite-optimizer-installer
- Files:
-
- 5 added
- 2 edited
-
tags/1.3.0 (added)
-
tags/1.3.0/index.php (added)
-
tags/1.3.0/onsite-optimizer-installer.php (added)
-
tags/1.3.0/readme.txt (added)
-
tags/1.3.0/uninstall.php (added)
-
trunk/onsite-optimizer-installer.php (modified) (8 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
onsite-optimizer-installer/trunk/onsite-optimizer-installer.php
r3385947 r3491877 3 3 * Plugin Name: Onsite Optimizer Installer 4 4 * Description: The easiest way to install the Onsite Optimizer on your website. Just enter your Optimizer ID and we’ll do the rest. 5 * Version: 1.0. 25 * Version: 1.0.3 6 6 * Author: SEO Platform 7 7 * License: GPL-2.0-or-later … … 113 113 <div class="wrap"> 114 114 <h1>Onsite Optimizer Installer</h1> 115 <p>Enter your Optimizer ID and press save. We’ll add the code for you on every pageautomatically.</p>115 <p>Enter your Optimizer ID and press save. We’ll add the code for you on compatible frontend HTML pages automatically.</p> 116 116 <form action="options.php" method="post"> 117 117 <?php … … 153 153 154 154 public static function maybe_buffer_early() { 155 // Start buffering as soon as plugins load, to catch early output.156 if ( self:: has_optimizer_id() && ! is_admin() && ! self::is_cli() && ! self::is_head_request() && ! self::is_amp_request() ) {155 // Start buffering as soon as plugins load, but only for requests that can return HTML. 156 if ( self::should_start_buffering() ) { 157 157 ob_start( [ __CLASS__, 'inject_script_into_head' ] ); 158 158 } … … 161 161 public static function maybe_buffer() { 162 162 // Safety net if no buffer is active yet. 163 if ( self:: has_optimizer_id() && ! is_admin() && ! self::is_cli() && ! self::is_head_request() && ! self::is_amp_request() && ob_get_level() === 0 ) {163 if ( self::should_start_buffering() && ob_get_level() === 0 ) { 164 164 ob_start( [ __CLASS__, 'inject_script_into_head' ] ); 165 165 } … … 194 194 } 195 195 196 private static function is_login_request() { 197 $script_name = isset( $_SERVER['SCRIPT_NAME'] ) ? wp_unslash( $_SERVER['SCRIPT_NAME'] ) : ''; 198 $script_name = is_string( $script_name ) ? strtolower( $script_name ) : ''; 199 200 return strpos( $script_name, 'wp-login.php' ) !== false || strpos( $script_name, 'wp-register.php' ) !== false; 201 } 202 203 private static function get_request_uri() { 204 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : ''; 205 206 return is_string( $request_uri ) ? $request_uri : ''; 207 } 208 209 private static function is_excluded_request_path() { 210 $request_uri = self::get_request_uri(); 211 if ( $request_uri === '' ) { 212 return false; 213 } 214 215 $path = wp_parse_url( $request_uri, PHP_URL_PATH ); 216 $query = wp_parse_url( $request_uri, PHP_URL_QUERY ); 217 218 $path = is_string( $path ) ? strtolower( $path ) : ''; 219 $query = is_string( $query ) ? strtolower( $query ) : ''; 220 221 $extension = pathinfo( $path, PATHINFO_EXTENSION ); 222 $extension = is_string( $extension ) ? strtolower( $extension ) : ''; 223 224 $excluded_extensions = [ 225 'xml', 226 'xsl', 227 'xslt', 228 'css', 229 'js', 230 'mjs', 231 'json', 232 'map', 233 'txt', 234 'jpg', 235 'jpeg', 236 'png', 237 'gif', 238 'svg', 239 'webp', 240 'avif', 241 'ico', 242 'bmp', 243 'tif', 244 'tiff', 245 'woff', 246 'woff2', 247 'ttf', 248 'otf', 249 'eot', 250 'webmanifest', 251 'pdf', 252 'zip', 253 ]; 254 255 if ( $extension !== '' && in_array( $extension, $excluded_extensions, true ) ) { 256 return true; 257 } 258 259 if ( $path !== '' && preg_match( '#(?:^|/)[^/]*sitemap[^/]*\.(?:xml|xsl|xslt)$#', $path ) ) { 260 return true; 261 } 262 263 if ( $path !== '' && preg_match( '#(?:^|/)wp-json(?:/|$)#', $path ) ) { 264 return true; 265 } 266 267 return strpos( $query, 'rest_route=' ) !== false || strpos( $query, 'sitemap=' ) !== false || strpos( $query, 'xsl=' ) !== false; 268 } 269 270 private static function has_html_response_content_type() { 271 $content_type = ''; 272 273 foreach ( headers_list() as $header ) { 274 if ( stripos( $header, 'Content-Type:' ) !== 0 ) { 275 continue; 276 } 277 278 $content_type = strtolower( trim( substr( $header, strlen( 'Content-Type:' ) ) ) ); 279 } 280 281 if ( $content_type === '' ) { 282 return true; 283 } 284 285 return strpos( $content_type, 'text/html' ) !== false || strpos( $content_type, 'application/xhtml+xml' ) !== false; 286 } 287 288 private static function should_start_buffering() { 289 if ( ! self::has_optimizer_id() || is_admin() || self::is_cli() || self::is_head_request() || self::is_amp_request() ) { 290 return false; 291 } 292 293 return ! self::is_login_request() && ! self::is_excluded_request_path(); 294 } 295 296 private static function should_skip_injection() { 297 if ( wp_doing_ajax() ) { 298 return true; 299 } 300 301 if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { 302 return true; 303 } 304 305 if ( function_exists( 'wp_is_json_request' ) && wp_is_json_request() ) { 306 return true; 307 } 308 309 if ( is_feed() || is_robots() || is_trackback() ) { 310 return true; 311 } 312 313 if ( self::is_amp_request() || self::is_login_request() || self::is_excluded_request_path() ) { 314 return true; 315 } 316 317 return ! self::has_html_response_content_type(); 318 } 319 196 320 /* --------------------------- 197 321 * Injection … … 207 331 $optimizer_id = self::get_optimizer_id(); 208 332 if ( $optimizer_id === '' ) { 209 return $html;210 }211 212 // Skip contexts that are not real HTML pages or that must be excluded.213 if ( wp_doing_ajax() ) {214 333 return $html; 215 334 } 216 if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { 335 336 if ( self::should_skip_injection() ) { 217 337 return $html; 218 338 } 219 if ( function_exists( 'wp_is_json_request' ) && wp_is_json_request() ) { 220 return $html; 221 } 222 if ( is_feed() || is_robots() || is_trackback() ) { 223 return $html; 224 } 339 225 340 // Exclude AMP pages completely as requested. 226 if ( self::is_amp_request() || self::looks_like_amp_html( $html ) ) { 227 return $html; 228 } 229 230 // Avoid login and register screens. 231 $script_name = isset( $_SERVER['SCRIPT_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_NAME'] ) ) : ''; 232 if ( strpos( $script_name, 'wp-login.php' ) !== false || strpos( $script_name, 'wp-register.php' ) !== false ) { 341 if ( self::looks_like_amp_html( $html ) ) { 233 342 return $html; 234 343 } … … 256 365 */ 257 366 public static function print_tag_fallback() { 258 if ( is_admin() || self::is_amp_request() ) {259 return;260 }261 367 $optimizer_id = self::get_optimizer_id(); 262 368 if ( $optimizer_id === '' ) { 263 369 return; 264 370 } 371 372 if ( is_admin() || self::should_skip_injection() ) { 373 return; 374 } 375 265 376 // Keep it lightweight and avoid duplicate insertion. 266 377 echo self::build_script_tag( $optimizer_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped … … 292 403 // Build attributes safely to avoid passing arrays to core formatting functions. 293 404 $attributes = [ 294 'nowprocket' => true,295 'nitro-exclude' => true,405 'nowprocket' => 'nowprocket', 406 'nitro-exclude' => 'nitro-exclude', 296 407 'seraph-accel-crit' => '1', 297 408 'data-cfasync' => 'false', -
onsite-optimizer-installer/trunk/readme.txt
r3385947 r3491877 4 4 Tested up to: 6.8 5 5 Requires PHP: 7.4 6 Stable tag: 1.0. 26 Stable tag: 1.0.3 7 7 License: GPL-2.0-or-later 8 8 … … 12 12 The Onsite Optimizer Installer helps you quickly set up the Onsite Optimizer on your website — no technical knowledge needed. 13 13 14 Once installed, simply enter your Optimizer ID (found in your Platform account) and the plugin will automatically add the Optimizer code to every pageon your site.14 Once installed, simply enter your Optimizer ID (found in your Platform account) and the plugin will automatically add the Optimizer code to compatible frontend HTML pages on your site. 15 15 16 16 **Key features:** 17 17 - Simple, non-technical setup 18 - Automatically adds the Optimizer code to your site18 - Automatically adds the Optimizer code to compatible frontend HTML pages 19 19 - Works with single and multisite installs 20 20 - Prevents duplicate installations … … 39 39 40 40 == Changelog == 41 = 1.0.3 = 42 * Prevented the Optimizer script from loading on XML sitemaps, XSL files, REST requests, and other non-HTML asset-style requests. 43 41 44 = 1.0.2 = 42 45 * Updated plugin description for clarity and simplicity.
Note: See TracChangeset
for help on using the changeset viewer.