Guest User

Untitled

a guest
Nov 13th, 2019
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.89 KB | None | 0 0
  1. <?php
  2. add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
  3.     $meta_boxes[] = [
  4.         'title'           => 'Hero Content',
  5.         'id'              => 'hero-content',
  6.         'description'     => 'A custom hero content block',
  7.         'type'            => 'block',
  8.         'icon'            => 'awards',
  9.         'category'        => 'layout',
  10.         'context'         => 'side',
  11.         'render_callback' => 'my_hero_callback',
  12.         'supports' => [
  13.             'align' => ['wide', 'full'],
  14.         ],
  15.  
  16.         // Block fields.
  17.         'fields'          => [
  18.             [
  19.                 'type' => 'single_image',
  20.                 'id'   => 'image',
  21.                 'name' => 'Image',
  22.             ],
  23.             [
  24.                 'type' => 'text',
  25.                 'id'   => 'title',
  26.                 'name' => 'Title',
  27.             ],
  28.             [
  29.                 'type' => 'text',
  30.                 'id'   => 'subtitle',
  31.                 'name' => 'Subtitle',
  32.             ],
  33.             [
  34.                 'type' => 'textarea',
  35.                 'id'   => 'content',
  36.                 'name' => 'Content',
  37.             ],
  38.             [
  39.                 'type' => 'single_image',
  40.                 'id'   => 'signature',
  41.                 'name' => 'Signature',
  42.             ],
  43.             [
  44.                 'type' => 'text',
  45.                 'id'   => 'button_text',
  46.                 'name' => 'Button Text',
  47.             ],
  48.             [
  49.                 'type' => 'text',
  50.                 'id'   => 'button_url',
  51.                 'name' => 'Button URL',
  52.             ],
  53.             [
  54.                 'type' => 'color',
  55.                 'id'   => 'background_color',
  56.                 'name' => 'Background Color',
  57.             ],
  58.         ],
  59.     ];
  60.  
  61.     return $meta_boxes;
  62. } );
  63.  
  64. function my_hero_callback( $attributes, $is_preview = false, $post_id = null ) {
  65.     // Fields data.
  66.     if ( empty( $attributes['data'] ) ) {
  67.         return;
  68.     }
  69.  
  70.     // Unique HTML ID if available.
  71.     $id = 'hero-' . ( $attributes['id'] ?? '' );
  72.     if ( ! empty( $attributes['anchor'] ) ) {
  73.         $id = $attributes['anchor'];
  74.     }
  75.  
  76.     // Custom CSS class name.
  77.     $class = 'hero ' . ( $attributes['className'] ?? '' );
  78.     if ( ! empty( $attributes['align'] ) ) {
  79.         $class .= " align{$attributes['align']}";
  80.     }
  81.     ?>
  82.     " class="" style="background-color: ">
  83.        
  84.         <img>">
  85.  
  86.        
  87.            
  88.            
  89.            
  90.            
  91.  
  92.             <?php $signature = mb_get_block_field( 'signature' ); ?>
  93.             <img class="hero__signature" src="<?= $signature['full_url'] ?>">
  94.  
  95.             <?php if ( mb_get_block_field( 'button_url' ) ) : ?>
  96.                 <p><a class="hero__button" href="<?php mb_the_block_field( 'button_url' ) ?>"><?php mb_the_block_field( 'button_text' ) ?></a></p>
  97.             <?php endif ?>
  98.         </div>
  99.     </div>
  100.     <?php
  101. }
Advertisement
Add Comment
Please, Sign In to add comment