Skip to content

Instantly share code, notes, and snippets.

@brettshumaker
Created January 27, 2017 18:44
Show Gist options
  • Save brettshumaker/a62e6d207a5a8f0b103c1e53a4adfdbe to your computer and use it in GitHub Desktop.
Save brettshumaker/a62e6d207a5a8f0b103c1e53a4adfdbe to your computer and use it in GitHub Desktop.
Altered file for svg-support/functions/attachment-modal.php Fatal Error
<?php
/**
* Display SVG in attachment modal
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
function bodhi_svgs_response_for_svg( $response, $attachment, $meta ) {
if( $response['mime'] == 'image/svg+xml' && empty( $response['sizes'] ) ) {
$svg_path = get_attached_file( $attachment->ID );
$dimensions = bodhi_svgs_get_dimensions( $svg_path ) ? bodhi_svgs_get_dimensions( $svg_path ) : json_decode("{'width':'0','height':'0'");
$response[ 'sizes' ] = array(
'full' => array(
'url' => $response[ 'url' ],
'width' => $dimensions->width,
'height' => $dimensions->height,
'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait'
)
);
}
return $response;
}
add_filter( 'wp_prepare_attachment_for_js', 'bodhi_svgs_response_for_svg', 10, 3 );
function bodhi_svgs_get_dimensions( $svg ) {
$svg = simplexml_load_file( $svg );
if ( $svg ) {
$attributes = $svg->attributes();
$width = (string) $attributes->width;
$height = (string) $attributes->height;
return (object) array( 'width' => $width, 'height' => $height );
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment