Guest User

Untitled

a guest
Oct 18th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. function twt_render_menu_block($attr, $is_preview = false, $post_id = null) {
  2.     if ( empty( $attr['data'] ) ) {
  3.         //return;
  4.     }
  5.     if($is_preview) {
  6.         echo '<p>To edit, click on pencil icon.</p>';
  7.         return;
  8.     }
  9.     // Unique HTML ID if available.
  10.     $id = 'twt-menu-block-' . ( $attr['id'] ?? '' );
  11.     if ( ! empty( $attr['anchor'] ) ) {
  12.         $id = $attr['anchor'];
  13.     }
  14.  
  15.     // Custom CSS class name.
  16.     $class = 'twt-menu-block ' . ( $attr['className'] ?? '' ) . (isset($attr['data']['attr']) && in_array('half-width-section', $attr['data']['attr']) ? ' half-width-section' : '');
  17.  
  18.     ?>
  19. <section id="<?php echo esc_attr($id); ?>"<?php echo empty($class) ? '' : 'class="'.esc_attr($class).'"'; ?>>
  20.     <?php if(!empty($attr['data']['featured_photo'])) {
  21.         $image = wp_get_attachment_image($attr['data']['featured_photo'], 'full');
  22.         if(!empty($image)) {
  23.             ?><figure class="featured-menu-photo"><?= $image; ?></figure><?php
  24.         }
  25.         ?>
  26.     <?php } ?>
  27.    
  28.     <?php
  29.     }
  30.     if(!empty($attr['data']['menu_items'])) {
  31. ?>
  32. <ul class="block-menu-items">
  33.     <?php
  34.     foreach($attr['data']['menu_items'] as $menu_item) {
  35.         $classes = array();
  36.         $attr = (array) $menu_item['attr'];
  37.         if(count($attr)) {
  38.             if ( in_array( 'half-width', $menu_item['attr'] ) ) {
  39.                 $classes[] = 'half-width';
  40.             }
  41.             if ( in_array( 'highlight', $menu_item['attr'] ) ) {
  42.                 $classes[] = 'highlight has-blue-background-color';
  43.             }
  44.             if ( in_array( 'no-br', $menu_item['attr'] ) ) {
  45.                 $classes[] = 'no-br';
  46.             }
  47.         }
  48.         ?>
  49. <li<?= empty($classes) ? '' : ' class="'.implode(' ', $classes).'"'; ?>>
  50.             <?php if(!empty($menu_item['name']) || in_array('gf', $attr)) { ?><h3><?= in_array('gf', $attr) ? '<i class="icon-gluten-free" aria-hidden="true"></i><span class="screen-reader-text">Gluten Free</span>' : ''; ?><?= $menu_item['name']; ?></h3><?php }
  51.             echo $menu_item['desc']; ?>
  52. </li><?php
  53.     }
  54.     ?>
  55. </ul>
  56.     </div>
  57. <?php
  58.     }
  59.     if(!empty($attr['data']['content_after'])) {
  60.         ?><?php
  61.     }
  62.     ?>
  63. </section>
  64.     <?php
  65. }
Advertisement
Add Comment
Please, Sign In to add comment