admin管理员组文章数量:1122826
We like to use custom image sizes for custom WP themes. This way, we can provide appropriate images for the custom elements and we can ensure that images don't load too large or too heavy. Now we've encountered a problem; most images are loaded with the 'full' image size, even though the correct image size is present in the uploads folder.
We found that for these images, the generated image sizes are missing from the _wp_attachment_metadata postmeta.
After regenerating the image sizes, the _wp_attachment_metadata for all images contain the "sizes" array correctly. This allows us to display the correct image sizes.
But the "sizes" data disappears after some time and so the "full" image size is displayed again. The period over which this happens seems to be random.
I have found related questions, but none seem to address the core problem. Can anyone explain why this data is missing? Is there a core WordPress functionality that checks the _wp_attachment_metadata for each image in a recurring action? Is something going wrong there?
Related question: Regenerate missing _wp_attachment_metadata
Related question now giving a 404:
Update
Thanks to @TomJNowell I was made aware of the fact that more information is necessary in order to be able to answer my question.
What does the environment look like?
The website is build with a WordPress boilerplate from roots.io: Bedrock
It contains a multisite setup with currently one website. We use a multisite environment to be able to present the website in multiple languages. For the translation of strings we use the plugin Loco Translate. Only one language is necessary for now.
It is a webshop and therefore we use WooCommerce
As said, we made a custom WordPress theme containing WooCommerce templates to override the default WooCommerce themes.
Plugins used: ACF Pro, Bugsnag, Gravity Forms, Loco Translate, Mollie for WooCommerce, Premmerce Permalink Manager for WooCommerce, WooCommerce, WooCommerce EU VAT Number, WooCommerce PDF Invoices, xCore Rest API extension, Yoast SEO.
Beside that we installed "Regenerate thumbnails" to be able to generate the custom image sizes. This plugin is still active because it also fixed the symptoms of our issue. When clicking "regenerate thumbnails" the image sizes were added to the _wp_attachment_metadata again.
There is no cleaner plugin active and there never was one active either.
We do not use custom code in our theme that has impact on the functionality of the _wp_attachment_metadata, aside from the add_image_size function.
More information about the issue
- It affects all images.
- We couldnt detect any "schedule" on which the issue occures. After fixing the symptoms with the plugin "Regenerate Thumbnails" we would get notified by our client that the issue occured again.
- We do not come across any errors, notifications or any logging about the issue. Bugsnag is also not detecting any issues.
- The image sizes do exist in the uploads folder, only the meta data is missing.
We fixed the symptoms
For now we fixed the symptoms by running a cronjob on a WP CLI script. The cronjob fires every 3 hours. We use: wp media regenerate We installed the script and the cronjob after the issue was detected.
The script:
#!/bin/bash
WPPATH="/home/example/domains/example.nl/public_html/web/wp"
for URL in = $(/usr/local/bin/wp site list --fields=url --format=csv --path="$WPPATH")
do
/usr/local/bin/wp media regenerate --only-missing --url="$URL" --path="$WPPATH" --yes --quiet
done
We like to use custom image sizes for custom WP themes. This way, we can provide appropriate images for the custom elements and we can ensure that images don't load too large or too heavy. Now we've encountered a problem; most images are loaded with the 'full' image size, even though the correct image size is present in the uploads folder.
We found that for these images, the generated image sizes are missing from the _wp_attachment_metadata postmeta.
After regenerating the image sizes, the _wp_attachment_metadata for all images contain the "sizes" array correctly. This allows us to display the correct image sizes.
But the "sizes" data disappears after some time and so the "full" image size is displayed again. The period over which this happens seems to be random.
I have found related questions, but none seem to address the core problem. Can anyone explain why this data is missing? Is there a core WordPress functionality that checks the _wp_attachment_metadata for each image in a recurring action? Is something going wrong there?
Related question: Regenerate missing _wp_attachment_metadata
Related question now giving a 404: https://wordpress.stackexchange.com/questions/330267/attachment-metadata-randomly-missing
Update
Thanks to @TomJNowell I was made aware of the fact that more information is necessary in order to be able to answer my question.
What does the environment look like?
The website is build with a WordPress boilerplate from roots.io: Bedrock
It contains a multisite setup with currently one website. We use a multisite environment to be able to present the website in multiple languages. For the translation of strings we use the plugin Loco Translate. Only one language is necessary for now.
It is a webshop and therefore we use WooCommerce
As said, we made a custom WordPress theme containing WooCommerce templates to override the default WooCommerce themes.
Plugins used: ACF Pro, Bugsnag, Gravity Forms, Loco Translate, Mollie for WooCommerce, Premmerce Permalink Manager for WooCommerce, WooCommerce, WooCommerce EU VAT Number, WooCommerce PDF Invoices, xCore Rest API extension, Yoast SEO.
Beside that we installed "Regenerate thumbnails" to be able to generate the custom image sizes. This plugin is still active because it also fixed the symptoms of our issue. When clicking "regenerate thumbnails" the image sizes were added to the _wp_attachment_metadata again.
There is no cleaner plugin active and there never was one active either.
We do not use custom code in our theme that has impact on the functionality of the _wp_attachment_metadata, aside from the add_image_size function.
More information about the issue
- It affects all images.
- We couldnt detect any "schedule" on which the issue occures. After fixing the symptoms with the plugin "Regenerate Thumbnails" we would get notified by our client that the issue occured again.
- We do not come across any errors, notifications or any logging about the issue. Bugsnag is also not detecting any issues.
- The image sizes do exist in the uploads folder, only the meta data is missing.
We fixed the symptoms
For now we fixed the symptoms by running a cronjob on a WP CLI script. The cronjob fires every 3 hours. We use: wp media regenerate We installed the script and the cronjob after the issue was detected.
The script:
#!/bin/bash
WPPATH="/home/example/domains/example.nl/public_html/web/wp"
for URL in = $(/usr/local/bin/wp site list --fields=url --format=csv --path="$WPPATH")
do
/usr/local/bin/wp media regenerate --only-missing --url="$URL" --path="$WPPATH" --yes --quiet
done
Share
Improve this question
edited Dec 2, 2022 at 10:40
braam
asked Nov 30, 2022 at 14:21
braambraam
12 bronze badges
4
|
1 Answer
Reset to default 0After logging the actions add_post_meta
, update_postmeta
& delete_post_meta
we found out that WooCommerce calls the filter woocommerce_resize_images
when the function wp_get_attachment_image_src
was used. We use that function abundantly in our themes.
I'm not sure why this filter is an issue but deactivating it resolved the problem.
For anyone finding this issue. Try adding this to your theme:
add_filter('woocommerce_resize_images', '__return_false');
本文标签: theme developmentAfter a while attachment meta data is missing quotsizesquot data
版权声明:本文标题:theme development - After a while attachment meta data is missing "sizes" data 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298060a1930147.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_post_meta
,update_postmeta
&delete_post_meta
. And only do so when themeta_key
is equal to: "_wp_attachment_metadata". Inside the log functionality I use thewp_debug_backtrace_summary()
function to be able to print a stacktrace. If anything usefull comes up I will update this thread. – braam Commented Dec 8, 2022 at 9:22