Created
January 27, 2017 18:44
-
-
Save brettshumaker/a62e6d207a5a8f0b103c1e53a4adfdbe to your computer and use it in GitHub Desktop.
Altered file for svg-support/functions/attachment-modal.php Fatal Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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