s' === $ext ) { $zones[] = 'css'; } if ( 'js' === $ext ) { $zones[] = 'js'; } if ( in_array( $ext, $image_types, true ) ) { $zones[] = 'images'; } return $zones; } /** * Get all files we don't allow to get in CDN. * * @since 2.5 * * @param string $delimiter RegEx delimiter. * @return string A pipe-separated list of excluded files. */ private function get_excluded_files( $delimiter ) { $files = $this->options->get( 'cdn_reject_files', [] ); /** * Filter the excluded files. * * @since 2.5 * * @param array $files List of excluded files. */ $files = (array) apply_filters( 'rocket_cdn_reject_files', $files ); $files = array_filter( $files ); if ( ! $files ) { return ''; } $files = array_flip( array_flip( $files ) ); $files = array_map( function ( $file ) use ( $delimiter ) { return str_replace( $delimiter, '\\' . $delimiter, $file ); }, $files ); return implode( '|', $files ); } /** * Get srcset attributes to rewrite to the CDN. * * @since 3.8.7 * * @return string A pipe-separated list of srcset attributes. */ private function get_srcset_attributes() { /** * Filter the srcset attributes. * * @since 3.8.7 * * @param array $srcset_attributes List of srcset attributes. */ $srcset_attributes = (array) apply_filters( 'rocket_cdn_srcset_attributes', [ 'data-lazy-', 'data-', ] ); return implode( '|', $srcset_attributes ); } /** * Removes inline scripts from the HTML * * @since 3.10.5 * * @param string $html HTML content. * * @return string */ private function remove_inline_scripts( $html ): string { if ( ! preg_match_all( '#]*)>(?[\s\S]*?)#msi', $html, $matches, PREG_SET_ORDER ) ) { return $html; } if ( empty( $matches ) ) { return $html; } foreach ( $matches as $inline_js ) { if ( empty( $inline_js['content'] ) ) { continue; } $html = str_replace( $inline_js[0], '', $html ); } return $html; } }