` of the HTML. * * @param mixed $html Thumbnail HTML. * @return mixed */ public static function thumbnail_html( $html ) { if ( ! is_string( $html ) || false === stripos( $html, ']*)>/i', static function ( $found ) { $attrs = $found[1]; if ( false === stripos( $attrs, 'data-no-lazy' ) ) { $attrs = ' data-no-lazy="1" data-skip-lazy="1"' . $attrs; } if ( preg_match( '/\bclass\s*=\s*(["\'])(.*?)\1/i', $attrs ) ) { if ( ! preg_match( '/\bclass\s*=\s*(["\'])[^"\']*\bskip-lazy\b/i', $attrs ) ) { $attrs = (string) preg_replace( '/\bclass\s*=\s*(["\'])/i', 'class=$1' . self::NO_LAZY_CLASSES . ' ', $attrs, 1 ); } } else { $attrs = ' class="' . self::NO_LAZY_CLASSES . '"' . $attrs; } return ''; }, $html ); } /** * WP Rocket: images with our marks are not lazy-loaded. * * @param mixed $attributes Attributes. * @return mixed */ public static function lazy_excluded_attributes( $attributes ) { if ( ! is_array( $attributes ) ) { return $attributes; } $attributes[] = 'data-skip-lazy="1"'; return array_values( array_unique( $attributes ) ); } /** * LiteSpeed: images with our classes are not lazy-loaded. * * @param mixed $classes Classes. * @return mixed */ public static function lazy_excluded_classes( $classes ) { if ( ! is_array( $classes ) ) { return $classes; } $classes[] = 'skip-lazy'; return array_values( array_unique( $classes ) ); } /* ------------------------------------------------------------------ generated CSS */ /** * Markers of generated theme/builder CSS in uploads, and of builder plugins' folders. * * @return array{uploads:string[],plugins:string[]} */ private static function markers(): array { $themes = array_unique( array( (string) get_template(), (string) get_stylesheet() ) ); /** * Filters the markers of generated CSS left off Aiolos Checkout's page with * "Distraction-free page": folders under uploads (`uploads`) and builder plugin folders * (`plugins`). * * @since 1.6.0 * * @param array $markers uploads => string[], plugins => string[]. */ $markers = (array) apply_filters( 'aiolos_generated_css_markers', array( 'uploads' => array_merge( array_filter( $themes ), array( 'porto_styles', 'jupiterx', 'the7', 'dt-the7', 'fusion-styles', 'avada-styles', 'et-cache', 'bb-theme', 'bb-plugin', 'oxygen', 'astra-addon', 'kadence', 'generateblocks', 'uag-plugin', 'wpbakery', 'js_composer' ) ), 'plugins' => array( 'js_composer', 'fusion-builder', 'fusion-core', 'oxygen', 'us-core', 'bb-plugin', 'beaver-builder-lite-version', 'bb-theme-builder', 'divi-builder', 'breakdance', 'kingcomposer', 'csshero', 'css-hero' ), ) ); return array( 'uploads' => array_values( array_filter( (array) ( $markers['uploads'] ?? array() ), 'is_string' ) ), 'plugins' => array_values( array_filter( (array) ( $markers['plugins'] ?? array() ), 'is_string' ) ), ); } /** * Whether a stylesheet URL is generated theme/builder CSS or a builder plugin's CSS. * * @param mixed $src Source URL. * @param array $markers Markers. */ private static function is_generated_css( $src, array $markers ): bool { if ( ! is_string( $src ) || '' === $src ) { return false; } $path = (string) wp_parse_url( $src, PHP_URL_PATH ); $uploads = wp_get_upload_dir(); $base = (string) wp_parse_url( (string) ( $uploads['baseurl'] ?? '' ), PHP_URL_PATH ); if ( '' !== $base && 0 === strpos( $path, trailingslashit( $base ) ) ) { $rest = substr( $path, strlen( trailingslashit( $base ) ) ); foreach ( $markers['uploads'] as $marker ) { if ( '' !== $marker && preg_match( '#(^|/)' . preg_quote( $marker, '#' ) . '([/_.-]|$)#i', $rest ) ) { return true; } } return false; } $plugins = (string) wp_parse_url( plugins_url(), PHP_URL_PATH ); if ( '' !== $plugins && 0 === strpos( $path, trailingslashit( $plugins ) ) ) { $folder = strtok( substr( $path, strlen( trailingslashit( $plugins ) ) ), '/' ); return in_array( $folder, $markers['plugins'], true ); } return false; } /** * Leaves generated theme/builder CSS off our page. */ public static function dequeue_generated_css(): void { if ( ! Checkout::active() || ! Settings::enabled( 'remove_theme_assets' ) ) { return; } /** This filter is documented in src/Compat/Plugins/Elementor.php */ $keep = (array) apply_filters( 'aiolos_kept_builder_assets', array() ); $markers = self::markers(); $styles = wp_styles(); foreach ( (array) $styles->queue as $handle ) { $handle = (string) $handle; if ( in_array( $handle, $keep, true ) || ! isset( $styles->registered[ $handle ] ) ) { continue; } if ( self::is_generated_css( $styles->registered[ $handle ]->src, $markers ) ) { $styles->dequeue( $handle ); } } } /* ------------------------------------------------------------------ notices */ /** * WooCommerce's own notices templates on our page (and in its AJAX), unless a folder is allowed * through `aiolos_template_allowed_paths` or a theme copy through `aiolos_theme_template_allowed`. * * @param mixed $template Located template. * @param string $template_name Template name. * @return mixed */ public static function notices_template( $template, $template_name ) { if ( ! is_string( $template ) || ! is_string( $template_name ) || 0 !== strpos( $template_name, 'notices/' ) || ! Checkout::active() ) { return $template; } $file = wp_normalize_path( $template ); $wc = trailingslashit( wp_normalize_path( WC()->plugin_path() ) ) . 'templates/'; $own = $wc . $template_name; $alive = 0 === strpos( $file, $wc ) || 0 === strpos( $file, trailingslashit( wp_normalize_path( AIOLOS_CHECKOUT_PATH ) ) ); if ( $alive || ! file_exists( $own ) ) { return $template; } /** This filter is documented in src/Checkout/Checkout.php */ $allowed = (array) apply_filters( 'aiolos_template_allowed_paths', array(), $template_name ); foreach ( $allowed as $path ) { if ( is_string( $path ) && '' !== $path && 0 === strpos( $file, trailingslashit( wp_normalize_path( $path ) ) ) ) { return $template; } } if ( Checkout::from_theme_dir( $file ) && apply_filters( 'aiolos_theme_template_allowed', false, $template_name ) ) { // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- documented in Checkout::locate_template(). return $template; } return $own; } }