$def ) { if ( substr( $name, - $len ) == $method ) { if ( is_array( $def['function'] ) ) { if ( is_string( $def['function'][0] ) !== false ) { $def_class = $def['function'][0]; } else { $def_class = get_class( $def['function'][0] ); } if ( $def_class == $class ) { if ( is_object( $wp_filter[ $action ] ) && isset( $wp_filter[ $action ]->callbacks ) ) { $wp_filter[ $action ]->remove_filter( $action, $name, $priority ); $deleted = true; } else { unset( $wp_filter[ $action ][ $priority ][ $name ] ); $deleted = true; } } } } } } return $deleted; } /** * Custom manipulation of the script * * @param $buffer * @param $keywords * @param $cookie_type * * @return mixed|null|string|string[] * * @version 2.0.4 * @since 1.2.0 */ function cookiebot_addons_manipulate_script( $buffer, $keywords ) { /** * normalize potential self-closing script tags */ $normalized_buffer = preg_replace( '/()/is', '', $buffer ); if ( $normalized_buffer !== null ) { $buffer = $normalized_buffer; } /** * Pattern to get all scripts * * @version 2.0.4 * @since 1.2.0 */ $pattern = '/()(.*?)(<\/script>)/is'; /** * Get all scripts and add cookieconsent if it does match with the criterion */ $updated_scripts = preg_replace_callback( $pattern, function ( $matches ) use ( $keywords ) { $script = $matches[0]; // the full script html $script_tag_open = $matches[1]; // only the script open tag with all attributes $script_tag_inner = $matches[2]; // only the script's innerText $script_tag_close = $matches[3]; // only the script closing tag /** * Check if the script contains the keywords, checks keywords one by one * * If one match, then the rest of the keywords will be skipped. **/ foreach ( $keywords as $needle => $cookie_type ) { /** * The script contains the needle **/ if ( strpos( $script, $needle ) !== false ) { /** * replace all single quotes with double quotes in the open tag * remove previously set data-cookieconsent attribute * remove type attribute */ $script_tag_open = preg_replace( '/\'/', '"', $script_tag_open ); $script_tag_open = preg_replace( '/\sdata-cookieconsent=\"(?:.*?)\"/', '', $script_tag_open ); $script_tag_open = preg_replace( '/\stype=\"(?:.*?)\"/', '', $script_tag_open ); /** * set the type attribute to text/plain to prevent javascript execution * add data-cookieconsent attribute */ $cookie_types = cookiebot_addons_output_cookie_types( $cookie_type ); $replacement = '