Skip to content

Instantly share code, notes, and snippets.

@whyisjake
Created July 15, 2013 19:44
Show Gist options
  • Save whyisjake/6002819 to your computer and use it in GitHub Desktop.
Save whyisjake/6002819 to your computer and use it in GitHub Desktop.
Modal Window Builder
<?php
/**
* Modal Window Builder
*/
function make_modal_builder( $atts, $content = null ) {
extract( shortcode_atts( array(
'launch' => 'Launch Window',
'title' => 'Modal Title',
'btn_class' => '',
'embed' => ''
), $atts ) );
$number = mt_rand();
$args = array(
'a' => array(
'href' => array(),
'title' => array()
),
'br' => array(),
'em' => array(),
'strong' => array(),
'iframe' => array(
'src' => array(),
'height' => array(),
'border' => array(),
'frameborder' => array(),
'width' => array(),
'allowfullscreen' => array(),
)
);
$output = '<a class="btn ' . esc_attr( $btn_class ) . '" data-toggle="modal" href="#modal-' . $number . '">' . esc_html( $launch ) . '</a>';
$output .= '<div id="modal-' . $number . '" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">';
$output .= ' <div class="modal-header">';
$output .= ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
$output .= ' <h3>' . esc_html( $title ) . '</h3>';
$output .= ' </div>';
$output .= ' <div class="modal-body">';
$output .= ( !empty( $embed ) ) ? wpcom_vip_wp_oembed_get( esc_url( $embed ), array( 'width' => 530 ) ) : '';
$output .= wp_kses( $content, $args );
$output .= ' </div>';
$output .= ' <div class="modal-footer">';
$output .= ' <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>';
$output .= ' </div>';
$output .= '</div>';
return $output;
}
add_shortcode( 'modal', 'make_modal_builder' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment