From fd8081da5fd3cf7f72ef07935da3d9adc4604dc0 Mon Sep 17 00:00:00 2001 From: Josh Oakes Date: Wed, 31 Jul 2024 16:23:28 -0500 Subject: [PATCH 1/2] KAD-3121 Support rendering children on encoded SVGs --- includes/class-kadence-blocks-svg.php | 47 +++++++++++++++++---------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/includes/class-kadence-blocks-svg.php b/includes/class-kadence-blocks-svg.php index 125a5db41..e25cc58ef 100644 --- a/includes/class-kadence-blocks-svg.php +++ b/includes/class-kadence-blocks-svg.php @@ -161,23 +161,7 @@ public static function render( $name, $fill = 'currentColor', $stroke_width = fa $svg .= '' . $title . ''; } if ( ! empty( $icon['cD'] ) ) { - foreach ( $icon['cD'] as $cd ) { - $nE = $cd['nE']; - $aBs = $cd['aBs']; - $tmpAttr = array(); - - foreach ( $aBs as $key => $attribute ) { - if ( ! in_array( $key, array( 'fill', 'stroke', 'none' ) ) ) { - $tmpAttr[ $key ] = $key . '="' . $attribute . '"'; - } - } - - if ( isset( $aBs['fill'], $aBs['stroke'] ) && $aBs['fill'] === 'none' ) { - $tmpAttr['stroke'] = 'stroke="currentColor"'; - } - - $svg .= '<' . $nE . ' ' . implode( ' ', $tmpAttr ) . '/>'; - } + $svg .= self::generate_svg_elements($icon['cD']); } $svg .= ''; @@ -193,6 +177,35 @@ public static function render( $name, $fill = 'currentColor', $stroke_width = fa return $svg; } + + private static function generate_svg_elements( $elements ) { + $output = ''; + foreach ( $elements as $element ) { + $nE = $element['nE']; + $aBs = $element['aBs']; + $children = ! empty( $element['children'] ) ? $element['children'] : []; + $tmpAttr = array(); + + foreach ( $aBs as $key => $attribute ) { + if ( ! in_array( $key, array( 'fill', 'stroke', 'none' ) ) ) { + $tmpAttr[ $key ] = $key . '="' . esc_attr( $attribute ) . '"'; + } + } + + if ( isset( $aBs['fill'], $aBs['stroke'] ) && $aBs['fill'] === 'none' ) { + $tmpAttr['stroke'] = 'stroke="currentColor"'; + } + + $output .= '<' . $nE . ' ' . implode( ' ', $tmpAttr ); + if ( ! empty( $children ) ) { + $output .= '>' . self::generate_svg_elements( $children ) . ''; + } else { + $output .= '/>'; + } + } + + return $output; + } /** * Return an array of icons. * From 8e9f5a54d60a87d477634e33f1d104c5be3bc920 Mon Sep 17 00:00:00 2001 From: Josh Oakes Date: Thu, 1 Aug 2024 09:58:56 -0500 Subject: [PATCH 2/2] Update class-kadence-blocks-svg.php --- includes/class-kadence-blocks-svg.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/class-kadence-blocks-svg.php b/includes/class-kadence-blocks-svg.php index e25cc58ef..431408124 100644 --- a/includes/class-kadence-blocks-svg.php +++ b/includes/class-kadence-blocks-svg.php @@ -178,6 +178,14 @@ public static function render( $name, $fill = 'currentColor', $stroke_width = fa } + /** + * Recursively generate SVG elements + * Out native SVGs do not have children, but user uploaded SVGs in pro can contain children elements. + * + * @param $elements + * + * @return string + */ private static function generate_svg_elements( $elements ) { $output = ''; foreach ( $elements as $element ) {