Plugin Directory

Changeset 3491877


Ignore:
Timestamp:
03/26/2026 02:39:23 PM (9 days ago)
Author:
seoplatform
Message:

Release version 1.3.0

Location:
onsite-optimizer-installer
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • onsite-optimizer-installer/trunk/onsite-optimizer-installer.php

    r3385947 r3491877  
    33 * Plugin Name: Onsite Optimizer Installer
    44 * 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.2
     5 * Version: 1.0.3
    66 * Author: SEO Platform
    77 * License: GPL-2.0-or-later
     
    113113        <div class="wrap">
    114114            <h1>Onsite Optimizer Installer</h1>
    115             <p>Enter your Optimizer ID and press save. We’ll add the code for you on every page automatically.</p>
     115            <p>Enter your Optimizer ID and press save. We’ll add the code for you on compatible frontend HTML pages automatically.</p>
    116116            <form action="options.php" method="post">
    117117                <?php
     
    153153
    154154    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() ) {
    157157            ob_start( [ __CLASS__, 'inject_script_into_head' ] );
    158158        }
     
    161161    public static function maybe_buffer() {
    162162        // 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 ) {
    164164            ob_start( [ __CLASS__, 'inject_script_into_head' ] );
    165165        }
     
    194194    }
    195195
     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
    196320    /* ---------------------------
    197321     * Injection
     
    207331        $optimizer_id = self::get_optimizer_id();
    208332        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() ) {
    214333            return $html;
    215334        }
    216         if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
     335
     336        if ( self::should_skip_injection() ) {
    217337            return $html;
    218338        }
    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
    225340        // 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 ) ) {
    233342            return $html;
    234343        }
     
    256365     */
    257366    public static function print_tag_fallback() {
    258         if ( is_admin() || self::is_amp_request() ) {
    259             return;
    260         }
    261367        $optimizer_id = self::get_optimizer_id();
    262368        if ( $optimizer_id === '' ) {
    263369            return;
    264370        }
     371
     372        if ( is_admin() || self::should_skip_injection() ) {
     373            return;
     374        }
     375
    265376        // Keep it lightweight and avoid duplicate insertion.
    266377        echo self::build_script_tag( $optimizer_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
     
    292403        // Build attributes safely to avoid passing arrays to core formatting functions.
    293404        $attributes = [
    294             'nowprocket'        => true,
    295             'nitro-exclude'     => true,
     405            'nowprocket'        => 'nowprocket',
     406            'nitro-exclude'     => 'nitro-exclude',
    296407            'seraph-accel-crit' => '1',
    297408            'data-cfasync'      => 'false',
  • onsite-optimizer-installer/trunk/readme.txt

    r3385947 r3491877  
    44Tested up to: 6.8
    55Requires PHP: 7.4
    6 Stable tag: 1.0.2
     6Stable tag: 1.0.3
    77License: GPL-2.0-or-later
    88
     
    1212The Onsite Optimizer Installer helps you quickly set up the Onsite Optimizer on your website — no technical knowledge needed.
    1313
    14 Once installed, simply enter your Optimizer ID (found in your Platform account) and the plugin will automatically add the Optimizer code to every page on your site.
     14Once 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.
    1515
    1616**Key features:**
    1717- Simple, non-technical setup 
    18 - Automatically adds the Optimizer code to your site 
     18- Automatically adds the Optimizer code to compatible frontend HTML pages 
    1919- Works with single and multisite installs 
    2020- Prevents duplicate installations 
     
    3939
    4040== 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
    4144= 1.0.2 =
    4245* Updated plugin description for clarity and simplicity.
Note: See TracChangeset for help on using the changeset viewer.