Support Forum
Support › MB Settings Page › Bug with images in MB Settings Page after upgrading Meta Box pluginResolved
Hi 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
Hi,
Do you have any plugin for media settings? That lines just loop through all image sizes to get correct URL for all sizes.
I 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?
Please ignore my last post. I have the problem on another place. Will open a new topic.
Hi 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
Just 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
Hi, 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.
Hi 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.
Hi guys, I've just push a fix for this. Can you check if that works for you? Thanks!
Hi, thanks for the fast response. Seems to fix the issue!
That works - thank you!