Last active
August 29, 2015 14:07
-
-
Save chrisblakley/3dfa2f302fd8d42ddc5d to your computer and use it in GitHub Desktop.
Embed a Gumby grid into the Wordpress WYSIWYG editor
This file contains hidden or 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
/*========================== | |
Gumby Framework Shortcodes | |
By Chris Blakley | |
gearside.com | |
Documentation: http://gearside.com/wordpress-shortcodes-gumby-framework/ | |
===========================*/ | |
function get_flags($atts) { | |
$flags = array(); | |
if (is_array($atts)) { | |
foreach ($atts as $key => $value) { | |
if ($value != '' && is_numeric($key)) { | |
array_push($flags, $value); | |
} | |
} | |
} | |
return $flags; | |
} | |
//Colgrid | |
add_shortcode('gumby_colgrid', 'colgrid_shortcode'); | |
function colgrid_shortcode($atts, $content=''){ | |
extract( shortcode_atts( array('grid' => '', 'class' => '', 'style' => ''), $atts) ); | |
$flags = get_flags($atts); | |
$grid = array_values($flags); | |
return '<section class="' . $grid[0] . ' colgrid ' . $class . '" style="' . $style . '">' . do_shortcode($content) . '</section><!--/' . $grid[0] . ' colgrid-->'; | |
} | |
//Container | |
add_shortcode('gumby_container', 'container_shortcode'); | |
function container_shortcode($atts, $content=''){ | |
extract( shortcode_atts( array('class' => '', 'style' => ''), $atts) ); | |
return '<div class="container ' . $class . '" style="' . $style . '">' . do_shortcode($content) . '</div><!--/container-->'; | |
} | |
//Rows | |
add_shortcode('gumby_row', 'row_shortcode'); | |
function row_shortcode($atts, $content=''){ | |
extract( shortcode_atts( array('class' => '', 'style' => ''), $atts) ); | |
$GLOBALS['col_counter'] = 0; | |
return '<div class="row ' . $class . '" style="' . $style . '">' . do_shortcode($content) . '</div><!--/row-->'; | |
} | |
//Columns | |
add_shortcode('gumby_column', 'column_shortcode'); | |
add_shortcode('gumby_columns', 'column_shortcode'); | |
add_shortcode('gumby_col', 'column_shortcode'); | |
add_shortcode('gumby_cols', 'column_shortcode'); | |
function column_shortcode($atts, $content=''){ | |
extract( shortcode_atts( array('columns' => '', 'push' => '', 'centered' => '', 'class' => '', 'style' => ''), $atts) ); | |
$flags = get_flags($atts); | |
if ( in_array('centered', $flags) ) { | |
$centered = 'centered'; | |
$key = array_search('centered', $flags); | |
unset($flags[$key]); | |
} elseif ( $GLOBALS['col_counter'] == 0 ) { | |
$GLOBALS['col_counter'] = 1; | |
$first = 'margin-left: 0;'; | |
} else { | |
$GLOBALS['col_counter']++; | |
} | |
$columns = array_values($flags); | |
if ( $push ) { | |
$push = 'push_' . $push; | |
} | |
return '<div class="' . $columns[0] . ' columns ' . $push . ' ' . $centered . ' ' . $class . '" style="' . $style . ' ' . $first . '">' . do_shortcode($content) . '</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment