Forum Replies Created
-
AuthorPosts
-
gretch
ParticipantHello again,
Since I have to update to PHP8 I have a strange behavior with my Metabox code.
Everything is fine if all my fields are filled but if not my website crash with every empty fields returning this error : PHP Warning: Undefined array key "[name of the field]"Here is a sample of the code:
add_filter( 'mb_settings_pages', function ( $settings_pages ) { $settings_pages[] = [ 'menu_title' => __( 'Map settings', 'Map settings' ), 'option_name' => 'map', 'position' => 80, 'id' => 'map_settings', 'class' => 'map_settings', 'style' => 'no-boxes', 'columns' => 1, 'network' => true, 'icon_url' => 'dashicons-admin-site', ]; return $settings_pages; } ); add_filter( 'rwmb_meta_boxes', 'webedia_map_countries' ); function webedia_map_countries( $meta_boxes ) { $prefix = ''; $meta_boxes[] = [ 'title' => __( 'Countries', 'map-countries' ), 'id' => 'countries', 'settings_pages' => ['map_settings'], 'tabs' => [ 'global_tab' => [ 'label' => 'International', 'icon' => '', ], 'africa_tab' => [ 'label' => 'Africa', 'icon' => '', ], 'asia_tab' => [ 'label' => 'Asia', 'icon' => '', ], 'brazil_tab' => [ 'label' => 'Brazil', 'icon' => '', ], 'france_tab' => [ 'label' => 'France', 'icon' => '', ], 'germany_tab' => [ 'label' => 'Germany', 'icon' => '', ], 'mexico_latin_america_tab' => [ 'label' => 'Mexico / Latin America', 'icon' => '', ], 'middle_east_tab' => [ 'label' => 'Middle East', 'icon' => '', ], 'poland_tab' => [ 'label' => 'Poland', 'icon' => '', ], 'spain_tab' => [ 'label' => 'Spain', 'icon' => '', ], 'turkey_tab' => [ 'label' => 'Turkey', 'icon' => '', ], 'uk_tab' => [ 'label' => 'UK', 'icon' => '', ], 'usa_tab' => [ 'label' => 'USA', 'icon' => '', ], ], 'fields' => [ [ 'name' => __( 'Media network', 'map-countries' ), 'id' => $prefix . 'global_media_network', 'type' => 'group', 'class' => 'main-group', 'fields' => [ [ 'name' => __( 'Description group', 'map-countries' ), 'id' => $prefix . 'global_media_network_description_group', 'type' => 'group', 'class' => 'sub-group', 'fields' => [ [ 'name' => __( 'Descriptionsss', 'map-countries' ), 'id' => $prefix . 'global_media_network_description', 'type' => 'text', ], ], ], [ 'name' => __( 'Logos', 'map-countries' ), 'id' => $prefix . 'global_media_network_images_group', 'type' => 'group', 'class' => 'sub-group', 'fields' => [ [ 'id' => $prefix . 'global_media_network_group_images', 'type' => 'image_advanced', 'max_file_uploads' => 4, 'class' => 'media_network_gallery', ], ], ], [ 'name' => __( 'CTA', 'map-countries' ), 'id' => $prefix . 'global_media_network_cta', 'type' => 'group', 'class' => 'sub-group', 'fields' => [ [ 'name' => __( 'CTA wording', 'map-countries' ), 'id' => $prefix . 'global_media_network_cta_wording', 'type' => 'text', 'columns' => 6, ], [ 'name' => __( 'CTA link', 'map-countries' ), 'id' => $prefix . 'global_media_network_cta_link', 'type' => 'url', 'columns' => 6, ], ], ], ], 'tab' => 'global_tab', ], [ 'name' => __( 'Creators', 'map-countries' ), 'id' => $prefix . 'global_creators', 'type' => 'group', 'class' => 'main-group', 'fields' => [ [ 'name' => __( 'Description', 'map-countries' ), 'id' => $prefix . 'global_creators_description', 'type' => 'textarea', 'columns' => 7, ], [ 'name' => __( 'Logos', 'map-countries' ), 'id' => $prefix . 'global_creators_images_group', 'type' => 'group', 'class' => 'sub-group', 'fields' => [ [ 'id' => $prefix . 'global_creators_group_images', 'type' => 'image_advanced', 'max_file_uploads' => 4, 'class' => 'media_network_gallery', ], ], ], [ 'name' => __( 'CTA', 'map-countries' ), 'id' => $prefix . 'global_creators_cta', 'type' => 'group', 'class' => 'sub-group', 'fields' => [ [ 'name' => __( 'CTA wording', 'map-countries' ), 'id' => $prefix . 'global_creators_cta_wording', 'type' => 'text', 'columns' => 6, ], [ 'name' => __( 'CTA link', 'map-countries' ), 'id' => $prefix . 'global_creators_cta_link', 'type' => 'url', 'columns' => 6, ], ], ], ], 'tab' => 'global_tab', ], [ 'name' => __( 'Studios', 'map-countries' ), 'id' => $prefix . 'global_studios', 'type' => 'group', 'class' => 'main-group', 'fields' => [ [ 'name' => __( 'Description', 'map-countries' ), 'id' => $prefix . 'global_studios_description', 'type' => 'textarea', 'columns' => 7, ], [ 'name' => __( 'Logos', 'map-countries' ), 'id' => $prefix . 'global_studios_images_group', 'type' => 'group', 'class' => 'sub-group', 'fields' => [ [ 'id' => $prefix . 'global_studios_group_images', 'type' => 'image_advanced', 'max_file_uploads' => 4, 'class' => 'media_network_gallery', ], ], ], [ 'name' => __( 'CTA', 'map-countries' ), 'id' => $prefix . 'global_studios_cta', 'type' => 'group', 'class' => 'sub-group', 'fields' => [ [ 'name' => __( 'CTA wording', 'map-countries' ), 'id' => $prefix . 'global_studios_cta_wording', 'type' => 'text', 'columns' => 6, ], [ 'name' => __( 'CTA link', 'map-countries' ), 'id' => $prefix . 'global_studios_cta_link', 'type' => 'url', 'columns' => 6, ], ], ], ], 'tab' => 'global_tab', ], ETC.....<?php $global_media_network = rwmb_meta( 'global_media_network', ['object_type' => 'network_setting'], 'map'); ?> <?php $global_creators = rwmb_meta( 'global_creators', ['object_type' => 'network_setting'], 'map'); ?> <?php $global_studios = rwmb_meta( 'global_studios', ['object_type' => 'network_setting'], 'map'); ?> <div class="country-content international"> <div class="country-title">International</div> <div class="media-network"> <?php $global_media_network_group_images = $global_media_network['global_media_network_images_group']['global_media_network_group_images']; $global_media_network_description = $global_media_network['global_media_network_description_group']['global_media_network_description']; if ($global_media_network_group_images || $global_media_network_description) { echo '<div class="media-network-title">Networks</div>'; }; ?> <?php echo '<p>' . $global_media_network_description . '</p>'; ?> <div class="media-network-content"> <?php $id = get_main_site_id(); switch_to_blog( $id ); $global_media_network_group_images = $global_media_network['global_media_network_images_group']['global_media_network_group_images']; foreach ( $global_media_network_group_images as $image_id ) { $image_url = wp_get_attachment_image_url( $image_id, 'thumbnail' ); echo '<img src="' . $image_url . '">'; } restore_current_blog(); ?> </div> <div class="country-content-cta"> <!-- CTA --> <a href="<?php $global_media_network_cta_link = $global_media_network['global_media_network_cta']['global_media_network_cta_link']; echo $global_media_network_cta_link;?>"><?php $global_media_network_cta_wording = $global_media_network['global_media_network_cta']['global_media_network_cta_wording']; echo $global_media_network_cta_wording;?></a> </div> </div> <div class="creators"> <?php $global_creators_group_images = $global_creators['global_creators_images_group']['global_creators_group_images']; $global_creators_description = $global_creators['global_creators_description_group']['global_creators_description']; if ($global_creators_group_images || $global_creators_description) { echo '<div class="creators-title">Creators</div>'; }; ?> <?php echo '<p>' . $global_creators_description . '</p>'; ?> <div class="creators-content"> <?php $id = get_main_site_id(); switch_to_blog( $id ); $global_creators_group_images = $global_creators['global_creators_images_group']['global_creators_group_images']; foreach ( $global_creators_group_images as $image_id ) { $image_url = wp_get_attachment_image_url( $image_id, 'thumbnail' ); echo '<img src="' . $image_url . '">'; } restore_current_blog(); ?> </div> <div class="country-content-cta"> <a href="<?php $global_creators_cta_link = $global_creators['global_creators_cta']['global_creators_cta_link']; echo $global_creators_cta_link;?>"><?php $global_creators_cta_wording = $global_creators['global_creators_cta']['global_creators_cta_wording']; echo $global_creators_cta_wording;?></a> </div> </div> <div class="studios"> <?php $global_studios_group_images = $global_studios['global_studios_images_group']['global_studios_group_images']; $global_studios_description = $global_studios['global_studios_description']; if ($global_studios_group_images || $global_studios_description) { echo '<div class="studios-title">Studios</div>'; }; ?> <?php echo '<p>' . $global_studios_description . '</p>'; ?> <div class="studios-content"> <?php $id = get_main_site_id(); switch_to_blog( $id ); $global_studios_group_images = $global_studios['global_studios_images_group']['global_studios_group_images']; foreach ( $global_studios_group_images as $image_id ) { $image_url = wp_get_attachment_image_url( $image_id, 'thumbnail' ); echo '<img src="' . $image_url . '">'; } restore_current_blog(); ?> </div> <div class="country-content-cta"> <a href="<?php $global_studios_cta_link = $global_studios['global_studios_cta']['global_studios_cta_link']; echo $global_studios_cta_link;?>"><?php $global_studios_cta_wording = $global_studios['global_studios_cta']['global_studios_cta_wording']; echo $global_studios_cta_wording;?></a> </div> </div> </div>How can I update the code to work with PHP8+ ?
Do you need the full code to figure out the issue ?I really tried everything I could but I can't solve it :/
Thanks you very much
gretch
ParticipantPerfect !
Thank you very much for your help.gretch
ParticipantHi Long,
Thank you. The code works fine but compared to the first one, it display the original file instead of the thumbnail size.
Is it possible to adjust the last code to display thumbnails ?Thank you a lot
gretch
ParticipantHi !
More than a month later, any news about my issue ?
I bought this plugin for this specific feature so I really need to make it work 🙏(btw the topic is tagged as "resolved" but it's not)
Thanks a lot for your help
gretch
ParticipantHi,
I guess that means you get the same result on your side.
I look forward to your return.Thank you very much
gretch
ParticipantHi,
Still on the same settings, the code above works very well but the image advanced field only works on the main site.
On the others the image source is "unknow" as you can see :

How can I fix that and display the field across the network ?
Thank you for your precious help
gretch
ParticipantMaybe my configuration wasn't the easiest one to start with. Thanks to you I think I have now a good base for the following.
Thank you very much ! -
AuthorPosts