[20] Add wp_get_attachment_url & some regex for extended functionality#21
[20] Add wp_get_attachment_url & some regex for extended functionality#21Lorti merged 2 commits intoLorti:masterfrom emanueljacob:#20-add-functionality-for-all-wp-images
Conversation
|
Thank you, @ecksite. That looks very promising! 🙂 Also, please help me understand: This also adds the lazy-loading functionality for images that don't have an |
Sure, im trying to find time for it.
If you refer to my post in the wp support forum:
Well, so far as i can tell is woocommerce using the native wordpress media uploader. So everytime someone adds a image by hand, the add_attachment actions should be called and the colors should be generated and saved, right? |
|
Let me paraphrase that, so I know I understand it correctly… WordPress, by default, outputs the attachment ID in its HTML classes (
Yes, it should, if WooCommerce isn't doing anything out of the ordinary. |
Correct, if you insert the image using the media uploader in posts/pages etc.
The WooCommerce Output could be proceed using your filter and the 'post_thumbnail_html' filter, something like that: function filter_woocommerce_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if (preg_match('/((?s).*)(<img [^>]+>)((?s).*)/', $html, $image)) {
return $image[1] . apply_filters( 'dominant_colors', $image[2], $post_thumbnail_id) . $image[3];
}
return $html;
};
add_filter( 'post_thumbnail_html', 'filter_woocommerce_post_thumbnail_html', 10, 5 );
Correct. This even enables lazy loading with dominant colors for all those images, that couldn't addressed because of the missing "wp-image-[id]" class (img tags created by hand, or img tags from shortcode output for example). Because this hook looks more expensive, I added it only as fallback in your "else" statement. Edit: |
|
Awesome, and thank you for explaining! |
|
I managed to get my VVV running again (didn't touch it in a year so I had to update Virtual Box and Vagrant first), but couldn't get PHPUnit to run. I have manually tested your changes, though, and it seems to work perfectly. Blog Post Dominant Colors Lazy-Loading I will write a changelog entry and prepare a new release. Hopefully my SVN client still works … 😅 |


closes #20