Skip to content

Commit

Permalink
KAD-2226
Browse files Browse the repository at this point in the history
  • Loading branch information
oakesjosh committed Feb 20, 2024
1 parent 2f581d5 commit d2069ab
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
27 changes: 27 additions & 0 deletions includes/blocks/class-kadence-blocks-abstract-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,31 @@ public function enqueue_style( $handle ) {
wp_enqueue_style( $handle );
}


/**
* Gets the HTML tag from the attributes.
* If the tag provided isn't allowed, return the default value.
*
* @param array $attributes Array of the blocks attributes.
* @param string $tag_key Offest on $attributes where the tag is set.
* @param string $default Default tag to use if $tag_key attribue is undefined or invalid.
* @param array $allowed_tags Array of allowed tags.
* @param string $level_key If defined, we'll assume heading tags are allowed.
*
* @return string
*/
public function get_html_tag( $attributes, $tag_key, $default, $allowed_tags = array(), $level_key = '' ) {

if( !empty( $attributes[ $tag_key ] ) && in_array( $attributes[ $tag_key ], $allowed_tags ) ) {

if( $attributes[ $tag_key ] === 'heading' ) {
$level = !empty( $attributes[ $level_key ] ) ? $attributes[ $level_key ] : 2;
return 'h' . $level;
}

return $attributes[ $tag_key ];
}

return $default;
}
}
21 changes: 8 additions & 13 deletions includes/blocks/class-kadence-blocks-advanced-heading-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Kadence_Blocks_Advancedheading_Block extends Kadence_Blocks_Abstract_Block
*/
protected $has_script = false;

/**
* Allowed HTML tags for front end output.
*
* @var string[]
*/
protected $allowed_html_tags = array( 'heading', 'p', 'span', 'div' );

/**
* Instance Control
*/
Expand Down Expand Up @@ -372,7 +379,7 @@ public function build_html( $attributes, $unique_id, $content, $block_instance )
$this->enqueue_script( 'kadence-blocks-' . $this->block_name );
}
if ( ! empty( $attributes['icon'] ) ) {
$tag_name = $this->get_tag_name( $attributes );
$tag_name = $this->get_html_tag( $attributes, 'htmlTag', 'h2', $this->allowed_html_tags, 'level' );
$text_content = $this->get_inner_content( $content, $tag_name );
// Start empty.
$content = '';
Expand Down Expand Up @@ -546,18 +553,6 @@ private function get_icon( $attributes ) {
return '<span class="kb-svg-icon-wrap kb-adv-heading-icon kb-svg-icon-' . esc_attr( $attributes['icon'] ) . ' kb-adv-heading-icon-side-' . esc_attr( $icon_side ) . '">' . $svg_icon . '</span>';
}

/**
* Get the html tag name.
*
* @param array $attributes the blocks attributes.
*/
private function get_tag_name( $attributes ) {
if ( $attributes['htmlTag'] === 'heading' ) {
return 'h' . $attributes['level'];
}

return $attributes['htmlTag'];
}
}

Kadence_Blocks_Advancedheading_Block::get_instance();
12 changes: 10 additions & 2 deletions includes/blocks/class-kadence-blocks-infobox-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class Kadence_Blocks_Infobox_Block extends Kadence_Blocks_Abstract_Block {
*/
protected $block_name = 'infobox';

/**
* Allowed HTML tags for front end output
*
* @var string[]
*/
protected $allowed_html_tags = array( 'heading', 'p', 'span', 'div' );

/**
* Instance Control
*/
Expand Down Expand Up @@ -343,8 +350,9 @@ public function build_css( $attributes, $css, $unique_id, $unique_style_id ) {
$css->add_property( 'border-bottom-color', ( isset( $media_style['hoverBorder'] ) && ! empty( $media_style['hoverBorder'] ) ? $css->render_color( $media_style['hoverBorder'] ) : '#444444' ) );
}

$titleTagType = !empty( $attributes['titleTagType'] ) ? $attributes['titleTagType'] : 'heading';
$titleTag = 'heading' === $titleTagType ? 'h' . ( !empty( $attributes['titleFont'][0]['level'] ) ? $attributes['titleFont'][0]['level'] : '2' ) : $titleTagType;
$attributes['titleTagLevel'] = !empty( $attributes['titleFont'][0]['level'] ) ? $attributes['titleFont'][0]['level'] : 2;
$titleTag = $this->get_html_tag( $attributes, 'titleTagType', 'h2', $this->allowed_html_tags, 'titleTagLevel' );

if ( isset( $attributes['titleColor'] ) || isset( $attributes['titleFont'] ) ) {
$css->set_selector( $base_selector . ' .kt-infobox-textcontent ' . $titleTag . '.kt-blocks-info-box-title' );
if ( isset( $attributes['titleColor'] ) && ! empty( $attributes['titleColor'] ) ) {
Expand Down
11 changes: 10 additions & 1 deletion includes/blocks/class-kadence-blocks-row-layout-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class Kadence_Blocks_Rowlayout_Block extends Kadence_Blocks_Abstract_Block {
*/
protected $block_name = 'rowlayout';

/**
* Allowed HTML tags for front end output
*
* @var string[]
*/
protected $allowed_html_tags = array( 'div', 'header', 'section', 'article', 'main', 'aside', 'footer' );


/**
* Instance Control
*/
Expand Down Expand Up @@ -1475,7 +1483,8 @@ public function get_video_render( $attributes ) {
*/
public function build_html( $attributes, $unique_id, $content, $block_instance ) {
if ( ! empty( $attributes['kbVersion'] ) && $attributes['kbVersion'] > 1 ) {
$html_tag = ( ! empty( $attributes['htmlTag'] ) ? $attributes['htmlTag'] : 'div' );
$html_tag = $this->get_html_tag( $attributes, 'htmlTag', 'div', $this->allowed_html_tags );

$outer_classes = array( 'kb-row-layout-wrap', 'kb-row-layout-id' . $unique_id );
$outer_classes[] = ! empty( $attributes['align'] ) ? 'align' . $attributes['align'] : 'alignnone';
if ( isset( $attributes['vsdesk'] ) && $attributes['vsdesk'] ) {
Expand Down

0 comments on commit d2069ab

Please sign in to comment.