diff --git a/includes/utils/class-utils.php b/includes/utils/class-utils.php index 8f002bd..4f36718 100644 --- a/includes/utils/class-utils.php +++ b/includes/utils/class-utils.php @@ -86,6 +86,12 @@ public static function get_imagedata( $image_id ) { 'html' => wp_get_attachment_image( $image_id, 'full' ), ); + // Check if svg. + $svg = self::encode_svg( $image_id ); + if ( $svg ) { + $image_data['encoded_content'] = $svg; + } + // Add meta data. $image_meta = wp_get_attachment_metadata( $image_id ); if ( is_array( $image_meta ) ) { @@ -116,6 +122,25 @@ public static function get_imagedata( $image_id ) { return $image_data; } + /** + * Encode SVG file by id. + * + * @param int $image_id Attachement id. + * @return string|false + */ + private static function encode_svg( $image_id ) { + $file_path = get_attached_file( $image_id ); + $file_type = wp_check_filetype( $file_path ); + if ( $file_type['ext'] === 'svg' ) { + $svg_content = file_get_contents( $file_path ); + if ( $svg_content ) { + return base64_encode( $svg_content ); + } + } + + return false; + } + /** * Get video data by id. *