Last active
December 15, 2015 05:29
-
-
Save jayseventwo/5208888 to your computer and use it in GitHub Desktop.
Add Bootstrap Twitter shortcodes dropdown to your page/post editor when using Roots Theme. Also adds shortcode ability to widgets. Add this custom.php.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* --------------------------------------------------------------------------------------------------------------------------- Add shortcodes */ | |
add_shortcode('row', 'j72_row' ); | |
add_shortcode('span', 'j72_span' ); | |
add_shortcode('span4', 'j72_span4' ); | |
add_shortcode('span5', 'j72_span5' ); | |
add_shortcode('span6', 'j72_span6' ); | |
add_shortcode('well', 'j72_well' ); | |
add_shortcode('button', 'j72_button'); | |
add_shortcode('carousel', 'j72_carousel'); | |
add_shortcode('carousel_image', 'j72_carousel_img'); | |
add_shortcode('alert', 'j72_alert' ); | |
add_shortcode('code', 'j72_code' ); | |
add_shortcode('label', 'j72_label'); | |
add_shortcode('badge', 'j72_badge' ); | |
add_shortcode('icon', 'j72_icon' ); | |
add_shortcode('icon_white', 'j72_icon_white' ); | |
add_shortcode('table', 'j72_table' ); | |
add_shortcode('accordian', 'j72_collapsibles' ); | |
add_shortcode('accordian_content', 'j72_collapse' ); | |
add_shortcode('tabs', 'j72_tabs' ); | |
add_shortcode('tab', 'j72_tab' ); | |
add_shortcode('paragraph', 'j72_para' ); | |
/*-----j72_span--------------------------------------------------------------------------*/ | |
function j72_span( $atts, $content = null ) { | |
extract(shortcode_atts(array( | |
"size" => 'size' | |
), $atts)); | |
return '<div class="span' . $size . '">' . do_shortcode( $content ) . '</div>'; | |
} | |
/*-----j72_span4-------------------------------------------------------------------------*/ | |
function j72_span4( $atts, $content = null ) { | |
return '<div class="span4">' . do_shortcode( $content ) . '</div>'; | |
} | |
/*-----j72_span4-------------------------------------------------------------------------*/ | |
function j72_span5( $atts, $content = null ) { | |
return '<div class="span5">' . do_shortcode( $content ) . '</div>'; | |
} | |
/*-----j72_span6-------------------------------------------------------------------------*/ | |
function j72_span6( $atts, $content = null ) { | |
return '<div class="span6">' . do_shortcode( $content ) . '</div>'; | |
} | |
/*-----j72_row-------------------------------------------------------------------------*/ | |
function j72_row( $atts, $content = null ) { | |
return '<div class="row-fluid">' . do_shortcode( $content ) . '</div>'; | |
} | |
/*-----j72_well------------------------------------------------------------------------*/ | |
function j72_well( $atts, $content = null ) { | |
extract(shortcode_atts(array( | |
"size" => 'size' | |
), $atts)); | |
return '<div class="well well-' . $size . '">' . do_shortcode( $content ) . '</div>'; | |
} | |
/*-----j72_buttonj---------------------------------------------------------------------*/ | |
function j72_button($atts, $content = null) { | |
extract(shortcode_atts(array( | |
"type" => '', | |
"size" => '', | |
"link" => '' | |
), $atts)); | |
return '<a href="' . $link . '" class="btn btn-' . $type . ' btn-' . $size . '">' . do_shortcode( $content ) . '</a>'; | |
} | |
/*-----j72_carousel--------------------------------------------------------------------*/ | |
function j72_carousel($atts, $content = null) { | |
return '<div id="myCarousel" class="carousel slide"><div class="carousel-inner">' . do_shortcode( $content ) . '</div><a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a><a class="carousel-control right" href="#myCarousel" data-slide="next">›</a></div>'; | |
} | |
/*-----j72_carousel_img----------------------------------------------------------------*/ | |
function j72_carousel_img($atts, $content = null) { | |
extract(shortcode_atts(array( | |
"active" => '', | |
), $atts)); | |
return '<div class="item ' . $active . '">' . do_shortcode( $content ) . '</div>'; | |
} | |
/*-----j72_alert------------------------------------------------------------------------*/ | |
function j72_alert($atts, $content = null) { | |
extract(shortcode_atts(array( | |
"type" => '', | |
"close" => true | |
), $atts)); | |
return '<div class="alert alert-' . $type . '">' . do_shortcode( $content ) . '<button type="button" class="close" data-dismiss="alert">×</button></div>'; | |
} | |
/*-----j72_code-------------------------------------------------------------------------*/ | |
function j72_code($atts, $content = null) { | |
extract(shortcode_atts(array( | |
"type" => '', | |
"size" => '', | |
"link" => '' | |
), $atts)); | |
return '<pre><code>' . do_shortcode( $content ) . '</code></pre>'; | |
} | |
/*-----j72_label------------------------------------------------------------------------*/ | |
function j72_label( $atts, $content = null ) { | |
extract(shortcode_atts(array( | |
"type" => 'type' | |
), $atts)); | |
return '<span class="label label-' . $type . '">' . do_shortcode( $content ) . '</span>'; | |
} | |
/*-----j72_badge------------------------------------------------------------------------*/ | |
function j72_badge( $atts, $content = null ) { | |
extract(shortcode_atts(array( | |
"type" => 'type' | |
), $atts)); | |
return '<span class="badge badge-' . $type . '">' . do_shortcode( $content ) . '</span>'; | |
} | |
/*----j72_icon--------------------------------------------------------------------------*/ | |
function j72_icon( $atts, $content = null ) { | |
extract(shortcode_atts(array( | |
"type" => 'type' | |
), $atts)); | |
return '<i class="icon icon-' . $type . '"></i>'; | |
} | |
/*-----j72_icon_white-------------------------------------------------------------------*/ | |
function j72_icon_white( $atts, $content = null ) { | |
extract(shortcode_atts(array( | |
"type" => 'type' | |
), $atts)); | |
return '<i class="icon icon-' . $type . ' icon-white"></i>'; | |
} | |
/*-----simple_table---------------------------------------------------------------------*/ | |
function j72_table( $atts ) { | |
extract( shortcode_atts( array( | |
'cols' => 'none', | |
'data' => 'none', | |
'type' => 'type' | |
), $atts ) ); | |
$cols = explode(',',$cols); | |
$data = explode(',',$data); | |
$total = count($cols); | |
$output = ''; | |
$output .= '<table class="table table-'. $type .' table-bordered"><tr>'; | |
foreach($cols as $col): | |
$output .= '<th>'.$col.'</th>'; | |
endforeach; | |
$output .= '</tr><tr>'; | |
$counter = 1; | |
foreach($data as $datum): | |
$output .= '<td>'.$datum.'</td>'; | |
if($counter%$total==0): | |
$output .= '</tr>'; | |
endif; | |
$counter++; | |
endforeach; | |
$output .= '</table>'; | |
return $output; | |
} | |
/*-----j72_tabs-------------------------------------------------------------------------*/ | |
function j72_tabs( $atts, $content = null ) { | |
if( isset($GLOBALS['taj72_count']) ) | |
$GLOBALS['taj72_count']++; | |
else | |
$GLOBALS['taj72_count'] = 0; | |
$defaults = array(); | |
extract( shortcode_atts( $defaults, $atts ) ); | |
// Extract the tab titles for use in the tab widget. | |
preg_match_all( '/tab title="([^\"]+)"/i', $content, $matches, PREG_OFFSET_CAPTURE ); | |
$tab_titles = array(); | |
if( isset($matches[1]) ){ $tab_titles = $matches[1]; } | |
$output = ''; | |
if( count($tab_titles) ){ | |
$output .= '<ul class="nav nav-tabs" id="custom-tabs-'. rand(1, 100) .'">'; | |
$i = 0; | |
foreach( $tab_titles as $tab ){ | |
if($i == 0) | |
$output .= '<li class="active">'; | |
else | |
$output .= '<li>'; | |
$output .= '<a href="#custom-tab-' . $GLOBALS['taj72_count'] . '-' . sanitize_title( $tab[0] ) . '" data-toggle="tab">' . $tab[0] . '</a></li>'; | |
$i++; | |
} | |
$output .= '</ul>'; | |
$output .= '<div class="tab-content">'; | |
$output .= do_shortcode( $content ); | |
$output .= '</div>'; | |
} else { | |
$output .= do_shortcode( $content ); | |
} | |
return $output; | |
} | |
/*-----j72_tab------------------------------------------------------------------------*/ | |
function j72_tab( $atts, $content = null ) { | |
if( !isset($GLOBALS['current_tabs']) ) { | |
$GLOBALS['current_tabs'] = $GLOBALS['taj72_count']; | |
$state = 'active'; | |
} else { | |
if( $GLOBALS['current_tabs'] == $GLOBALS['taj72_count'] ) { | |
$state = ''; | |
} else { | |
$GLOBALS['current_tabs'] = $GLOBALS['taj72_count']; | |
$state = 'active'; | |
} | |
} | |
$defaults = array( 'title' => 'Tab'); | |
extract( shortcode_atts( $defaults, $atts ) ); | |
return '<div id="custom-tab-' . $GLOBALS['taj72_count'] . '-'. sanitize_title( $title ) .'" class="tab-pane ' . $state . '">'. do_shortcode( $content ) .'</div>'; | |
} | |
/*-----j72_collapsibles----------------------------------------------------------------*/ | |
function j72_collapsibles( $atts, $content = null ) { | |
if( isset($GLOBALS['collapsibles_count']) ) | |
$GLOBALS['collapsibles_count']++; | |
else | |
$GLOBALS['collapsibles_count'] = 0; | |
$defaults = array(); | |
extract( shortcode_atts( $defaults, $atts ) ); | |
// Extract the tab titles for use in the tab widget. | |
preg_match_all( '/collapse title="([^\"]+)"/i', $content, $matches, PREG_OFFSET_CAPTURE ); | |
$tab_titles = array(); | |
if( isset($matches[1]) ){ $tab_titles = $matches[1]; } | |
$output = ''; | |
if( count($tab_titles) ){ | |
$output .= '<div class="accordion" id="accordion-' . $GLOBALS['collapsibles_count'] . '">'; | |
$output .= do_shortcode( $content ); | |
$output .= '</div>'; | |
} else { | |
$output .= do_shortcode( $content ); | |
} | |
return $output; | |
} | |
/*-----j72_collapse-------------------------------------------------------------------*/ | |
function j72_collapse( $atts, $content = null ) { | |
if( !isset($GLOBALS['current_collapse']) ) | |
$GLOBALS['current_collapse'] = 0; | |
else | |
$GLOBALS['current_collapse']++; | |
$defaults = array( 'title' => 'Tab', 'state' => ''); | |
extract( shortcode_atts( $defaults, $atts ) ); | |
if (!empty($state)) | |
$state = 'in'; | |
return ' | |
<div class="accordion-group"> | |
<div class="accordion-heading"> | |
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion-' . $GLOBALS['collapsibles_count'] . '" href="#collapse_' . $GLOBALS['current_collapse'] . '_'. sanitize_title( $title ) .'"> | |
' . $title . ' | |
</a> | |
</div> | |
<div id="collapse_' . $GLOBALS['current_collapse'] . '_'. sanitize_title( $title ) .'" class="accordion-body collapse ' . $state . '"> | |
<div class="accordion-inner"> | |
' . $content . ' | |
</div> | |
</div> | |
</div> | |
'; | |
} | |
/*-----j72_row--------------------------------------------------------------------------*/ | |
function j72_para( $atts, $content = null ) { | |
return '<p>' . do_shortcode( $content ) . '</p>'; | |
} | |
// -------------------------------------------------------add shortcode ability for widgets | |
add_filter('widget_text', 'do_shortcode'); | |
// -----------------------------------------------------------add dropdown menu to page/post editor | |
add_action('media_buttons','add_sc_select',11); | |
function add_sc_select(){ | |
global $shortcode_tags; | |
/* ------------------------------------- */ | |
/* enter names of any shortcodes to exclude below */ | |
/* ------------------------------------- */ | |
$exclude = array("wp_caption", "embed", "caption", 'gallery'); | |
echo ' <select id="sc_select"><option>Shortcode</option>'; | |
foreach ($shortcode_tags as $key => $val){ | |
if(!in_array($key,$exclude)){ | |
$shortcodes_list .= '<option value="['.$key.'][/'.$key.']">'.$key.'</option>'; | |
} | |
} | |
echo $shortcodes_list; | |
echo '</select>'; | |
} | |
add_action('admin_head', 'button_js'); | |
function button_js() { | |
echo '<script type="text/javascript"> | |
jQuery(document).ready(function(){ | |
jQuery("#sc_select").change(function() { | |
send_to_editor(jQuery("#sc_select :selected").val()); | |
return false; | |
}); | |
}); | |
</script>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment