Block doesn't render on frontend
- This topic has 4 replies, 2 voices, and was last updated 5 years, 3 months ago by
Anh Tran.
-
AuthorPosts
-
January 7, 2020 at 9:33 PM #17762
Jackky
ParticipantHi! I'm trying to male my first block and it's working perfect on backend, but on frontend appers nothing. I can't find out why.
Block template:
<?php echo 'test output'; if ( empty( $attributes['data'] ) ) return; $data = to_object($attributes['data']); ?> <?php if ($data->triggers) { ?> <div class="text-trigger"> <?php foreach ($data->triggers as $trigger) { ?> <div class="text-trigger__item"> <div class="text-trigger__item-inner"> <div class="text-trigger__item-icon" style="background-image: url(<?= wp_get_attachment_image_url($trigger->icon, 'icon-0x100'); ?>);"></div> <div class="text-trigger__item-text"> <?= $trigger->text; ?> </div> </div> </div> <?php } ?> </div> <?php } ?>
MetaBox:
<?php $meta_boxes[] = [ 'title' => 'Текстовые триггеры', 'id' => 'text-trigger', //'description' => 'A custom hero content block', 'type' => 'block', 'icon' => 'awards', 'category' => 'layout', 'context' => 'side', 'render_template' => get_template_directory() . '/gutenberg/text-trigger.php', 'supports' => [ 'align' => ['wide', 'full'], ], 'fields' => [ [ 'id' => 'triggers', 'type' => 'group', 'name' => 'Контент', 'clone' => true, 'sort_clone' => true, 'add_button' => '+', 'fields' => [ [ 'id' => 'icon', 'type' => 'single_image', 'name' => 'Иконка', ], [ 'id' => 'text', 'type' => 'text', 'name' => 'Текст', ], ] ], ], ];
January 7, 2020 at 10:04 PM #17763Jackky
ParticipantI have find out the issue. It's because I'm wrapping init of mb in is_admin condition like this:
if (is_admin()) { add_filter( 'rwmb_meta_boxes', 'register_meta_boxes' ); add_filter( 'mb_settings_pages', 'settings_pages' ); }
How can I load render template on frontend with saving this condition?
January 9, 2020 at 3:20 PM #17779Anh Tran
KeymasterHi Jackky,
The condition
is_admin()
should never be used. It prevents the fields/settings available for retrieving the data on the front end.January 9, 2020 at 4:06 PM #17782Jackky
ParticipantYeah, I know, but it's likely for me to disable every functions that I'm not using in frontend for security purposes. So I wanna make a suggestion to make some filters for MB, that allows to load only that functions I need, like rendering block template, not all helpers.
January 9, 2020 at 4:50 PM #17784Anh Tran
KeymasterI'm afraid it's not possible. All meta boxes and fields when registered will be added to a registry. That makes the helper functions to be able to find them to get the field settings and get field value. It's an integral part of the plugin and can't be disabled.
-
AuthorPosts
- You must be logged in to reply to this topic.