Astra_Customizer_Sanitizes::sanitize_social_icons( array $input )

Sanitize Social Icons using existing logo SVG sanitization.


Description

This function processes the social icons array and uses sanitize_logo_svg_icon() for each item.


Parameters

$input

(array) (Required) Social icons array.


Return

(array) Sanitized social icons array.


Source

File: inc/customizer/class-astra-customizer-sanitizes.php

		public static function sanitize_social_icons( $input ) {
			if ( ! isset( $input['items'] ) || ! is_array( $input['items'] ) ) {
				return $input;
			}

			// Process each social icon item
			foreach ( $input['items'] as $key => $item ) {
				if ( ! is_array( $item ) ) {
					continue;
				}

				// If this item has icon data (either icon-library or custom), sanitize it
				if ( isset( $item['icon_type'] ) && ( isset( $item['icon'] ) || isset( $item['custom_svg'] ) ) ) {
					if ( 'custom' === $item['icon_type'] ) {
						$input['items'][ $key ]['custom_svg'] = isset( $item['custom_svg'] ) ? self::sanitize_svg_code( $item['custom_svg'] ) : '';
						if ( ! isset( $input['items'][ $key ]['icon'] ) && isset( $item['id'] ) ) {
							$input['items'][ $key ]['icon'] = $item['id'];
						}
					} else {
						$input['items'][ $key ]['icon'] = isset( $item['icon'] ) && is_string( $item['icon'] ) ? sanitize_text_field( $item['icon'] ) : ( isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '' );
						// Remove custom_svg if switching to icon-library
						if ( isset( $input['items'][ $key ]['custom_svg'] ) ) {
							unset( $input['items'][ $key ]['custom_svg'] );
						}
					}
					$input['items'][ $key ]['icon_type'] = in_array( $item['icon_type'], array( 'icon-library', 'custom' ), true ) ? $item['icon_type'] : 'icon-library';
				} elseif ( isset( $item['id'] ) && ! isset( $item['icon'] ) && ! isset( $item['custom_svg'] ) ) {
					// Fallback for items without icon_type - assume icon-library
					$input['items'][ $key ]['icon']      = sanitize_text_field( $item['id'] );
					$input['items'][ $key ]['icon_type'] = 'icon-library';
				}
			}

			return $input;
		}

Changelog

Changelog
Version Description
4.11.8 Introduced.


User Contributed Notes

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