webp support code | WordPress.org

[ad_1]

Hi ulfben,

Thank you for this great plugin. I am replying to my old post with „webp support”.

In wp-jquery-lightbox.php line 176, 183, 199 please add just „|webp” after bmp, gif, jpg, jpeg, png.

//Matt's version to support multiple rel values
//https://projectdmc.org/support/topic/fix-for-auto-lightboxing-links-that-contain-rel-attributes-already?replies=12
function jqlb_do_regexp_multirel($content, $id){
	$id = esc_attr($id);
	$a_tag_img_regex = "/(<a[^>]+href=['\"][^>]+\\.(?:bmp|gif|jpg|jpeg|png|webp)[^>]+)>/i";
	if (preg_match_all($a_tag_img_regex, $content, $a_tag_matches, PREG_SET_ORDER)) {
		foreach ($a_tag_matches as $a_tag) {
			$new_a_tag = $a_tag[0];
			$rel_regex = "/(rel=['\"])(?![^>]*?(?:lightbox|nolb|nobox))([^'\"]+)(['\"])/i";
			$new_a_tag = preg_replace($rel_regex, '$1lightbox['.$id.'] $2$3', $new_a_tag);

			$no_rel_regex = "/(<a(?![^>]*?rel=['\"].+)[^>]+href=['\"][^>]+\\.(?:bmp|gif|jpg|jpeg|png|webp)[^>]+)>/i";
			$new_a_tag = preg_replace($no_rel_regex, '$1 rel="lightbox['.$id.']">', $new_a_tag);

			if ($new_a_tag != $a_tag[0]) $content = str_replace($a_tag[0], $new_a_tag, $content);
		}
	}
	return $content;
}


/* automatically insert rel="lightbox[nameofpost]" to every image with no manual work.
	if there are already rel="lightbox[something]" attributes, they are not clobbered.
	Michael Tyson, you are a regular expressions god! -  */
function jqlb_do_regexp($content, $id){
	$id = esc_attr($id);
	$content = preg_replace('/\s+rel="attachment wp-att-[0-9]+"/i', '', $content); //remove WP 4.4 garbage
	$pattern = "/(<a(?![^>]*?rel=['\"]lightbox.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png|webp)(\?\S{0,}){0,1}['\"][^\>]*)>/i";
	$replacement="$1 rel="lightbox[".$id.']">';
	return preg_replace($pattern, $replacement, $content);
}

Thank you!

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer