astra_icon_selector_svg( array $icon, bool $echo = false, string $default = '' )

Renders an SVG icon for SVG Icon Selector Control.


Description


Parameters

$icon

(array) (Required) The icon to be rendered. Contains type and value keys.

$echo

(bool) (Optional) Whether to echo the SVG markup directly or return it.

Default value: false

$default

(string) (Optional) The default icon to use if no icon is provided.

Default value: ''


Return

(string|null) The SVG icon markup or null if SVG icons are not enabled or no icon is provided.


Source

File: classes/astra-common-functions.php

	function astra_icon_selector_svg( $icon, $echo = false, $default = '' ) {
		// Bail early if SVG icons are not enabled.
		if ( ! Astra_Icons::is_svg_icons() || ! $icon ) {
			return $echo ? null : '';
		}

		$svg     = '';
		$classes = array( 'ast-icon' );

		if ( isset( $icon['type'], $icon['value'] ) ) {
			$type  = $icon['type'];
			$value = $icon['value'];

			if ( $type === 'custom' ) {
				$svg       = do_shortcode( $value );
				$classes[] = 'icon-' . $type;
			} elseif ( $type !== 'none' && is_callable( 'Astra_Builder_UI_Controller::fetch_svg_icon' ) ) {
				$svg       = Astra_Builder_UI_Controller::fetch_svg_icon( $value );
				$classes[] = 'icon-' . $value;
			}
		}

		if ( ! $svg && $default && is_callable( 'Astra_Builder_UI_Controller::fetch_svg_icon' ) ) {
			$svg = Astra_Builder_UI_Controller::fetch_svg_icon( $default );
		}

		if ( $svg ) {
			$svg = sprintf(
				'<span class="%1$s">%2$s</span>',
				implode( ' ', $classes ),
				$svg
			);
		}

		if ( $echo !== true ) {
			return wp_kses( $svg, Astra_Addon_Kses::astra_addon_svg_kses_protocols() );
		}
		
		echo wp_kses( $svg, Astra_Addon_Kses::astra_addon_svg_kses_protocols() );
	}

Changelog

Changelog
Version Description
4.10.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.