-
Notifications
You must be signed in to change notification settings - Fork 1
bs_column offset-* and pull-* options are not parsed correctly #29
Description
There seems to be an issue with how wordpress handles shortcode attributes which contain a minus sign in them. The entire attribute is passed as a string (e.g key='value' ) as opposed to being split into key/value pairs.
There is a second issue when using the extract() function with array keys that contain a minus sign. php generates a bunch of undefined variable warnings. To get rid of the warnings, Instead of using the extract function, dump the shortcodes_attr result into an assoc array and use them from there.
Here is my cludgy solution, but it seems to work. I hope you can improve on it, or find a more elegant method around these issues. Thanks for a great plugin!
function bs_column( $atts, $content = null ) {
$attrs = array();
/*
* attributes with minus signs are getting passed as strings
* parse the args and split the strngs into actual arrays
*/
foreach($atts as $k => $v){
if(is_integer($k)){
$at = explode('=',$v);
if(count($at)== 2){
$attrs[$at[0]] = str_replace("'", "", str_replace('"', "", $at[1]));
}
}else{
$attrs[$k] = $v;
}
}
/*
* extracting arguments with minus signs cause a bunch of warnings
* save the $atts to an $args array and use assoc array syntax to call the args
*
*/
$args = shortcode_atts(array(
"lg" => false,
"md" => false,
"sm" => false,
"xs" => false,
"offset-lg" => false,
"offset-md" => false,
"offset-sm" => false,
"offset-xs" => false,
"pull-lg" => false,
"pull-md" => false,
"pull-sm" => false,
"pull-xs" => false,
"push-lg" => false,
"push-md" => false,
"push-sm" => false,
"push-xs" => false,
), $attrs);
$return = '<div class="';
$return .= ($args['lg']) ? 'col-lg-' . $args['lg'] . ' ' : '';
$return .= ($args['md']) ? 'col-md-' . $args['md'] . ' ' : '';
$return .= ($args['sm']) ? 'col-sm-' . $args['sm'] . ' ' : '';
$return .= ($args['xs']) ? 'col-xs-' . $args['xs'] . ' ' : '';
$return .= ($args['offset-lg']) ? 'col-lg-offset-' . $args['offset-lg'] . ' ' : '';
$return .= ($args['offset-md']) ? 'col-md-offset-' . $args['offset-md'] . ' ' : '';
$return .= ($args['offset-sm']) ? 'col-sm-offset-' . $args['offset-sm'] . ' ' : '';
$return .= ($args['offset-xs']) ? 'col-xs-offset-' . $args['offset-xs'] . ' ' : '';
$return .= ($args['pull-lg']) ? 'col-lg-pull-' . $args['pull-lg'] . ' ' : '';
$return .= ($args['pull-md']) ? 'col-md-pull-' . $args['pull-md'] . ' ' : '';
$return .= ($args['pull-sm']) ? 'col-sm-pull-' . $args['pull-sm'] . ' ' : '';
$return .= ($args['pull-xs']) ? 'col-xs-pull-' . $args['pull-xs'] . ' ' : '';
$return .= ($args['push-lg']) ? 'col-lg-push-' . $args['push-lg'] . ' ' : '';
$return .= ($args['push-md']) ? 'col-md-push-' . $args['push-md'] . ' ' : '';
$return .= ($args['push-sm']) ? 'col-sm-push-' . $args['push-sm'] . ' ' : '';
$return .= ($args['push-xs']) ? 'col-xs-push-' . $args['push-xs'] . ' ' : '';
$return .= '">' . do_shortcode( $content ) . '</div>';
return $return;
}