Skip to content

Instantly share code, notes, and snippets.

@MjHead
Last active November 5, 2015 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MjHead/5c1c0ba963cfbc8c8085 to your computer and use it in GitHub Desktop.
Save MjHead/5c1c0ba963cfbc8c8085 to your computer and use it in GitHub Desktop.
<?php
/**
* Adding style attribute and class into row shortcode.
*
* Before using replace themeXXXX with your theme name.
*/
add_filter( 'cherry_shortcodes/data/shortcodes', 'themeXXXX_row_style_att', 100, 1 );
add_filter( 'shortcode_atts_row', 'themeXXXX_row_pass_style', 10, 3 );
add_filter( 'cherry_shortcodes_output_row_class', 'themeXXXX_row_pass_style_class', 10, 2 );
/**
* Add style attribute control to row and row inner shortcodes
*
* @param array $shortcodes default shortcodes array for editor.
* @return array
*/
function themeXXXX_row_style_att( $shortcodes ) {
$style = array(
'type' => 'select',
'values' => array(
'light' => __( 'Light', 'themeXXXX' ),
'dark' => __( 'Dark', 'themeXXXX' ),
),
'default' => 'light',
'name' => __( 'Style', 'themeXXXX' ),
'desc' => __( 'Select row styling type', 'themeXXXX' ),
);
foreach ( array( 'row', 'row_inner' ) as $shortcode ) {
if ( ! isset( $shortcodes[ $shortcode ]['atts'] ) ) {
continue;
}
$shortcodes[ $shortcode ]['atts']['style'] = $style;
}
return $shortcodes;
}
/**
* Pass style attribute into row shortcode
*
* @param array $out outputed shortcode attributes.
* @param array $pairs default attribute values.
* @param array $atts attributes array parsed from shortcode string.
* @return void
*/
function themeXXXX_row_pass_style( $out, $pairs, $atts ) {
$style = ! empty( $atts['style'] ) ? esc_attr( $atts['style'] ) : 'light';
$out['style'] = $style;
return $out;
}
/**
* Pass style-related class into row shortcode
*
* @param string $class row class.
* @param array $atts attributes array.
* @return string
*/
function themeXXXX_row_pass_style_class( $class, $atts ) {
if ( ! isset( $atts['style'] ) ) {
return $class;
}
return sprintf( '%s row-style-%s', esc_attr( $class ), esc_attr( $atts['style'] ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment