| @@ -1,0 +1,53 @@ | ||
| 1 | +<?php | |
| 2 | +/* | |
| 3 | + * License: GPLv3 | |
| 4 | + * License URI: https://www.gnu.org/licenses/gpl.txt | |
| 5 | + * Copyright 2024-2026 Jean-Sebastien Morisset (https://wpsso.com/) | |
| 6 | + */ | |
| 7 | + | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + | |
| 10 | + die( 'These aren\'t the droids you\'re looking for.' ); | |
| 11 | +} | |
| 12 | + | |
| 13 | +if ( ! class_exists( 'WpssoIntegUtilJetpackBoost' ) ) { | |
| 14 | + | |
| 15 | + class WpssoIntegUtilJetpackBoost { | |
| 16 | + | |
| 17 | + private $p; // Wpsso class object. | |
| 18 | + | |
| 19 | + public function __construct( &$plugin ) { | |
| 20 | + | |
| 21 | + $this->p =& $plugin; | |
| 22 | + | |
| 23 | + if ( $this->p->debug->enabled ) { | |
| 24 | + | |
| 25 | + $this->p->debug->mark(); | |
| 26 | + } | |
| 27 | + | |
| 28 | + if ( ! is_admin() ) { | |
| 29 | + | |
| 30 | + /* | |
| 31 | + * Exclude the WPSSO schema markup from the Jetpack Boost "Defer Non-Essential JavaScript" function. | |
| 32 | + */ | |
| 33 | + add_filter( 'jetpack_boost_render_blocking_js_exclude_scripts', array( $this, 'cleanup_defer_scripts' ), 1000, 1 ); | |
| 34 | + } | |
| 35 | + } | |
| 36 | + | |
| 37 | + public function cleanup_defer_scripts( array $script_tags ) { | |
| 38 | + | |
| 39 | + foreach ( $script_tags as $num => $match ) { | |
| 40 | + | |
| 41 | + if ( isset( $match[ 0 ] ) ) { // Just in case. | |
| 42 | + | |
| 43 | + if ( false !== strpos( $match[ 0 ], '<script type="application/ld+json" id="wpsso-' ) ) { | |
| 44 | + | |
| 45 | + unset( $script_tags[ $num ] ); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + } | |
| 49 | + | |
| 50 | + return $script_tags; | |
| 51 | + } | |
| 52 | + } | |
| 53 | +} | |