Skip to content

Instantly share code, notes, and snippets.

@emohamed
Last active November 7, 2018 10:49
Show Gist options
  • Save emohamed/28782aa3ee48b9c232134a5ac98dcae4 to your computer and use it in GitHub Desktop.
Save emohamed/28782aa3ee48b9c232134a5ac98dcae4 to your computer and use it in GitHub Desktop.
<?php
Container::make( 'block', 'Flight Details' )
->add_fields( [
Field::make( 'text', 'crb_from', 'From' ),
Field::make( 'text', 'crb_to', 'To' ),
Field::make( 'date_time', 'crb_departure_time', 'Departure Time' ),
Field::make( 'date_time', 'crb_arrival_time', 'Arrival Time' ),
Field::make( 'text', 'crb_duration', 'Duration' ),
])
->set_block_render_function(function ($flight) {
$format = 'm d, H:i(Y)';
$departure = date($format, strtotime($flight->departure_time));
$arrival = date($format, strtotime($flight->arrival_time));
?>
<section class="flight">
<h2>Flight from <?php echo esc_html($flight->from) ?> to <?php echo esc_html($flight->to) ?></h2>
<p class="flight__departure">Departure: <?php echo $departure ?></p>
<p class="flight__arrival">Arrival: <?php echo $arrival ?></p>
<p class="flight__duration"><?php echo esc_html($flight->duation) ?></p>
</section>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment