Error in fix_wp_get_attachment_image_svg() function
-
Currently assessing Kadence Blocks for our site. Added Kadence Blocks 3.1.12 to our website’s local environment.
Home page is not using any blocks by Kadence, but is now throwing a PHP error:
simplexml_load_file(//localhost:3000/wp-content/uploads/2023/07/name-of-asset.svg): Failed to open stream: Connection refused
Error occurs on line 197 of
kadence-blocks/includes/class-kadence-blocks-svg.php
, in thefix_wp_get_attachment_image_svg
function.The asset in question is an SVG that has been uploaded in the Block Editor into a custom block I built with ACF Pro.
Local env is using Docker, with bitnmai/wordpress-nginx as the base image.
- The error does not occur with Kadence Blocks 3.0.41.
- The error does occur with WP 6.2.2 or WP 6.3
- This topic was modified 1 year, 3 months ago by alanbrownca. Reason: typos
-
Hello @alanbrownca
From my understanding, this was a bug that should have received a fix in 3.1.12. Are you saying you still see it in 3.1.12? Other users have told support that 3.1.12 fixed the issue. Could you provide more information on how to recreate the problem as it does not appear on my test site.
Hi @ghernkadence,
Yes, this issue does not exist on 3.0.41 but it does exist on 3.1.12, and 3.1.13.
I’ve narrowed the occurrence of this error down to the use of the Image Field in ACF when the Image Array format is returned and an SVG asset is selected from the Media Library.
I was adding the image to my custom block template in this manner.
I have found that by switching the Return Format in ACF to Image URL, this issue is avoided, presumably because the
fix_wp_get_attachment_image_svg
function is not called.I believe the issue to be around the use of
simplexml_load_file
, as this and thefile_get_contents
functions can return with Connection Refused errors even whenallow_url_fopen
is enabled in some configurations.Alan,
This is Mark with the Kadence dev team. First, thanks for bringing this to our attention.
The warning doesn’t indicate a real problem (as long as your svg is loading and displaying properly that is). This function is just to fix some width / height attributes missing and that only matters in some edge cases anyway. In the case of this warning the function falls back to leaving the image the way it found it. Everything moves on.
Since this is just a warning and the case where the file can’t load is already caught by our code we decided to suppress the warning.
That update will be in the next release, I can’t say when that will be, but keep an eye out.
Worth noting that switching to the image return format might be a good option with your configuration then. Since not getting that warning probably means it’s providing width/height attributes that way. They can be nice to have. (but again, doesn’t matter in a lot of cases)
If you have any questions, just let us know.
Mark
Thanks for the follow up. I do want to clarify that the issue produces a critical error, not a warning. When
WP_DEBUG
isfalse
, the page is not shown, but the following error is instead:There has been a critical error on this website.
This occurs when the Return Format of the Image Field in ACF is Image Array, and then an SVG selected from the Media Library with that field.
Alan,
Okay, another report had it as just a warning so I assumed. I’ll need to look more into the fatal.
Was what you posted originally the full error log message? Was there any more to it, any other errors or warnings at the same time?
simplexml_load_file(//localhost:3000/wp-content/uploads/2023/07/name-of-asset.svg): Failed to open stream: Connection refused
In any case, we’ll try and pin this down and will let you know.
Mark
Sure thing, here is the full printout. I’m using Roots/Sage as a base for my theme.
Illuminate \ View \ ViewException (E_ERROR) simplexml_load_file(//localhost:3000/wp-content/uploads/2023/07/bnpl-icon-NS.svg): Failed to open stream: Connection refused (View: /opt/bitnami/wordpress/wp-content/themes/checkfront-2022/resources/views/partials/content-page.blade.php) (View: /opt/bitnami/wordpress/wp-content/themes/checkfront-2022/resources/views/partials/content-page.blade.php)
Hello,
My team is also experiencing a lot of performance and php warning issues around this exact filter. This has shown to be a huge slow error factor on multiple of our sites, with the below in our slow log. We are experiencing this with the latest version 3.1.13, but have since this filter was first implemented to use the simplexml_load_file() function.
script_filename = /www/index.php [0x00007f05b4216fa0] simplexml_load_file() /www/wp-content/plugins/kadence-blocks/includes/class-kadence-blocks-svg.php:197 [0x00007f05b4216e60] fix_wp_get_attachment_image_svg() /wordpress/wp-includes/class-wp-hook.php:310 [0x00007f05b4216d80] apply_filters() /wordpress/wp-includes/plugin.php:205 [0x00007f05b4216c70] apply_filters() /wordpress/wp-includes/media.php:996 [0x00007f05b4216b60] wp_get_attachment_image_src() /www/wp-content/plugins/advanced-custom-fields-pro/includes/api/api-helpers.php:3136 [0x00007f05b4216a20] acf_get_attachment() /www/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-image.php:383 [0x00007f05b4216950] format_value() /wordpress/wp-includes/class-wp-hook.php:310 [0x00007f05b4216870] apply_filters() /wordpress/wp-includes/plugin.php:256 [0x00007f05b42167a0] apply_filters_ref_array() /www/wp-content/plugins/advanced-custom-fields-pro/includes/acf-hook-functions.php:109 [0x00007f05b4216650] _acf_apply_hook_variations() /wordpress/wp-includes/class-wp-hook.php:310 [0x00007f05b4216570] apply_filters() /wordpress/wp-includes/plugin.php:205 [0x00007f05b4216470] apply_filters() /www/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:172 [0x00007f05b4216390] acf_format_value() /www/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-group.php:150 [0x00007f05b42162a0] format_value() /wordpress/wp-includes/class-wp-hook.php:310 [0x00007f05b42161c0] apply_filters() /wordpress/wp-includes/plugin.php:256 [0x00007f05b42160f0] apply_filters_ref_array() /www/wp-content/plugins/advanced-custom-fields-pro/includes/acf-hook-functions.php:109 [0x00007f05b4215fa0] _acf_apply_hook_variations() /wordpress/wp-includes/class-wp-hook.php:310 [0x00007f05b4215ec0] apply_filters() /wordpress/wp-includes/plugin.php:205 [0x00007f05b4215dc0] apply_filters() /www/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:172 [0x00007f05b4215ce0] acf_format_value() /www/wp-content/plugins/advanced-custom-fields-pro/includes/api/api-template.php:800
We also experience huge slow down in Local by Flywheel with this filter active, to the point that we comment this filter out of our builds. In our local setup, we get a different error than the slow error, constant certificate verification warnings that make sites take minutes to load. When commenting out the filter, sites load as expected. Paths removed for privacy.
error:0A000086:SSL routines::certificate verify failed in ...\app\public\wp-content\plugins\kadence-blocks\includes\class-kadence-blocks-svg.php on line 197 [23-Aug-2023 18:22:14 UTC] PHP Warning: ?simplexml_load_file(): Failed to enable crypto in ...\app\public\wp-content\plugins\kadence-blocks\includes\class-kadence-blocks-svg.php on line 197 [23-Aug-2023 18:22:14 UTC] PHP Warning: ?simplexml_load_file(...\.svg): Failed to open stream: operation failed in ...\app\public\wp-content\plugins\kadence-blocks\includes\class-kadence-blocks-svg.php on line 197 [23-Aug-2023 18:22:14 UTC] PHP Warning: ?simplexml_load_file(): I/O warning : failed to load external entity "...\.svg" in ...\app\public\wp-content\plugins\kadence-blocks\includes\class-kadence-blocks-svg.php on line 197 [23-Aug-2023 18:22:18 UTC] PHP Warning: ?simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages:
As mentioned, commenting out this filter resolves all issues and all sites load as expected in all environments.
We love your plugin, so really hope this can be resolved!
Thank you,
JulianOkay, two things.
First, beyond what were doing to check
allow_url_fopen
it becomes pretty vague what different configurations do and don’t support so It’s difficult for us to make checks for all cases. For whatever reason some configurations just don’t support what simplexml_load_file wants to do. I was hoping to find a solution that would filter out cases like the ones in this thread, but I don’t think that’s viable.Second, When we added this patch we were really expecting it to only trigger for a very small portion of users. Which is why we enabled it by default as it was helping for those small number of cases.
With that as context:
I’ve updated ourfix_wp_get_attachment_image_svg
function to be optional behind a setting found in the Kadence Blocks settings page (off by default). You can filter it too withkadence_blocks_fix_svg_dimensions
This will keep the fix available for those who are finding that their svg’s have no height (don’t appear on the page in some blocks, like icon block). but won’t inadvertently affect users like yourselves.
Keep a look out for this in the next Kadence Blocks release.
Mark
Hi Mark,
Thank you so much for the quick patch. I will watch for the update!
Julian
Hi Mark, my client is experiencing this issue – can you please provide more detail as to how to find the setting you mention as the settings page does not appear to offer anything to modify apart from ‘Manage Lottie Animations’.
@jdrucza
The function is still disabled by default, but we ac walked back the setting about a week ago. So that’s why you don’t see it.
There is still a filter to enable the fix if you want to. It’skadence_blocks_fix_svg_dimensions
Mark
- The topic ‘Error in fix_wp_get_attachment_image_svg() function’ is closed to new replies.