updated plugin Menu Icons
version 0.12.8
This commit is contained in:
@ -420,10 +420,45 @@ final class Menu_Icons_Front_End {
|
||||
$classes = sprintf( '%s _svg', self::get_icon_classes( $meta ) );
|
||||
$style = self::get_icon_style( $meta, array( 'svg_width', 'vertical_align' ) );
|
||||
|
||||
$svg_icon = esc_url( wp_get_attachment_url( $meta['icon'] ) );
|
||||
$width = '';
|
||||
$height = '';
|
||||
if ( 'image/svg+xml' === get_post_mime_type( $meta['icon'] ) ) {
|
||||
|
||||
// Check `WP_Filesystem` function exists OR not.
|
||||
require_once ABSPATH . '/wp-admin/includes/file.php';
|
||||
\WP_Filesystem();
|
||||
global $wp_filesystem;
|
||||
|
||||
$svg_icon = get_attached_file( $meta['icon'] );
|
||||
$svg_icon_content = $wp_filesystem->get_contents( $svg_icon );
|
||||
if ( $svg_icon_content ) {
|
||||
$xmlget = simplexml_load_string( $svg_icon_content );
|
||||
$xmlattributes = $xmlget->attributes();
|
||||
$width = (string) $xmlattributes->width;
|
||||
$width = (int) filter_var( $xmlattributes->width, FILTER_SANITIZE_NUMBER_INT );
|
||||
$height = (string) $xmlattributes->height;
|
||||
$height = (int) filter_var( $xmlattributes->height, FILTER_SANITIZE_NUMBER_INT );
|
||||
}
|
||||
} else {
|
||||
$attachment_meta = wp_get_attachment_metadata( $meta['icon'] );
|
||||
if ( $attachment_meta ) {
|
||||
$width = isset( $attachment_meta['width'] ) ? $attachment_meta['width'] : $width;
|
||||
$height = isset( $attachment_meta['height'] ) ? $attachment_meta['height'] : $height;
|
||||
}
|
||||
}
|
||||
if ( ! empty( $width ) ) {
|
||||
$width = sprintf( ' width="%dpx"', $width );
|
||||
}
|
||||
if ( ! empty( $height ) ) {
|
||||
$height = sprintf( ' height="%dpx"', $height );
|
||||
}
|
||||
return sprintf(
|
||||
'<img src="%s" class="%s" aria-hidden="true"%s />',
|
||||
'<img src="%s" class="%s" aria-hidden="true"%s%s%s/>',
|
||||
esc_url( wp_get_attachment_url( $meta['icon'] ) ),
|
||||
esc_attr( $classes ),
|
||||
$width,
|
||||
$height,
|
||||
$style
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user