-
Notifications
You must be signed in to change notification settings - Fork 10
[20] Add wp_get_attachment_url & some regex for extended functionality #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[20] Add wp_get_attachment_url & some regex for extended functionality #21
Conversation
β¦y (more images)
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