Bug with images in MB Settings Page after upgrading Meta Box plugin
Support › MB Settings Page › Bug with images in MB Settings Page after upgrading Meta Box pluginResolved
- This topic has 10 replies, 3 voices, and was last updated 5 years, 2 months ago by
ambrdigital.
-
AuthorPosts
-
February 4, 2020 at 4:29 AM #18120
ambrdigital
ParticipantHi there,
I noticed a new bug that appears after upgrading the meta box plugin.
Any image being output that's been uploaded under MB Settings Page now triggers some warnings and errors.
I'm using this code snippet from the docs
$settings = get_option( 'option_name' ); $image_ids = $settings['images']; foreach ( $image_ids as $image_id ) { $image = RWMB_Image_Field::file_info( $image_id, array( 'size' => 'thumbnail' ) ); echo '<img src="' . $image['url'] . '">'; }
Now triggers this error:
Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/theme-name/wp-content/plugins/meta-box/inc/fields/image.php on line 166
Could you please advise? Thank you
February 5, 2020 at 2:32 PM #18139Anh Tran
KeymasterHi,
Do you have any plugin for media settings? That lines just loop through all image sizes to get correct URL for all sizes.
February 5, 2020 at 8:20 PM #18148rikmulder
ParticipantI got the same error. Used to run smush.it but now have ShortPixel Image Optimizer. Hundreds of error lines each minute.
"PHP message: PHP Warning: Invalid argument supplied for foreach() in /var/www/XXX_COMMENTED-OUT-XXX/plugins/meta-box/inc/fields/image.php on line 166"
Also custom fields are not showing any more in back end after saving or adding. On front end they're still there. Anywhere to download the previous version?
February 5, 2020 at 8:45 PM #18149rikmulder
ParticipantPlease ignore my last post. I have the problem on another place. Will open a new topic.
February 6, 2020 at 5:00 AM #18154ambrdigital
ParticipantHi Anh,
I don't have a plugin for media settings. I set one extra image size elsewhere with add_image_size() but that's it.
The warning seems dependent on the line
$image = RWMB_Image_Field::file_info( $image_id, array( 'size' => 'thumbnail' ) );
When that is removed, it goes away.I discovered that it isn't just limited to MB Settings Page fields, but anywhere RWMB_Image_Field::file_info() function is called. It's occurred on 4 of my websites after the latest plugin update.
In another area the error being output is as follows:
Warning : Illegal string offset 'sizes' in /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-content/plugins/meta-box/inc/fields/image.php on line 166 Fatal error : Uncaught Error: Cannot iterate on string offsets by reference in /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-content/plugins/meta-box/inc/fields/image.php:166 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-content/plugins/meta-box/inc/fields/image.php(147): RWMB_Image_Field::get_image_meta_data('58') #1 /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-content/themes/site-partners/inc/content-blocks/views/logos-block.php(27): RWMB_Image_Field::file_info('58', Array) #2 /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-content/themes/site-partners/inc/content-blocks/page-layout-blocks.php(42): logos_block('_layout_blocks_', Array, 7) #3 /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-content/themes/site-partners/template-parts/content-page.php(18): layout_blocks() #4 /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-includes/template.php(724): require('/Applications/X...') #5 /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-includes/t in /Applications/XAMPP/xamppfiles/htdocs/sitepartners.ca/wp-content/plugins/meta-box/inc/fields/image.php
Please let me know if you have any ideas! Thanks
February 6, 2020 at 5:16 AM #18155ambrdigital
ParticipantJust an update,
I found that substituting
wp_get_attachment_image_src()
for the
Meta Box RWMB_Image_Field::file_info()
function solved problems across various websites. May want to still look into that function as it consistently broke across various websites for us after the latest update.
Hope that helps anyone else,
Cheers
February 6, 2020 at 8:33 AM #18158Anh Tran
KeymasterHi, I've tried to replicate the bug, but I couldn't. Please my video:
https://www.loom.com/share/a6e82008e3ff4074aecdb7a47a86ce22
I setup a settings page with
image_advanced
field, and try to get the value using the helper function or using the code from Ambr above. Both works without showing any error. I also installed Smush plugin and ran it, but no errors.Can you please check if there's something I missed? If possible, please send me a temporary admin account to check.
February 6, 2020 at 5:12 PM #18172rikmulder
ParticipantHi Anh Tran,
I have the problem with a custom field which is a single image upload. When I call the field this way
$promo_visual = rwmb_meta( 'promotion_visual' )
I get the error as mentioned above.I solved it for now by calling the field another way:
$promo_visual_id = get_post_meta( get_the_ID(), 'promotion_visual', true ); $promo_visual = wp_get_attachment_image_src($promo_visual_id);
This is working as long as I don't use the rwmb_meta call. Still worth looking for it I think because now I use both get_post_meta and rwmb_meta throughout my site.
February 6, 2020 at 5:32 PM #18175Anh Tran
KeymasterHi guys, I've just push a fix for this. Can you check if that works for you? Thanks!
February 6, 2020 at 5:56 PM #18176rikmulder
ParticipantHi, thanks for the fast response. Seems to fix the issue!
February 8, 2020 at 1:01 AM #18192ambrdigital
ParticipantThat works - thank you!
-
AuthorPosts
- You must be logged in to reply to this topic.