我正在努力准备好我的主题视网膜。我在我的主题文件中包含了以下代码。但它引起了以下关注
Uncaught reference Error: Exports is not defined
.............js/retina.js?ver=4.6.1 line 12.
我想知道为什么它说错误在脚本文件中。因为我一次又一次地下载了脚本文件,我非常确定视网膜中没有错误。js文件。有人能帮忙解决这个问题吗?以下是我的代码:
<?php
add_action( \'wp_enqueue_scripts\', \'retina_support_enqueue_scripts\' );
/**
* Enqueueing retina.js
*
* This function is attached to the \'wp_enqueue_scripts\' action hook.
*/
function retina_support_enqueue_scripts() {
wp_enqueue_script( \'retina_js\', get_template_directory_uri() . \'/js/retina.js\', \'\', \'\', true );
}
add_filter( \'wp_generate_attachment_metadata\', \'retina_support_attachment_meta\', 10, 2 );
/**
* Retina images
*
* This function is attached to the \'wp_generate_attachment_metadata\' filter hook.
*/
function retina_support_attachment_meta( $metadata, $attachment_id ) {
foreach ( $metadata as $key => $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $image => $attr ) {
if ( is_array( $attr ) )
retina_support_create_images( get_attached_file( $attachment_id ), $attr[\'width\'], $attr[\'height\'], true );
}
}
}
return $metadata;
}
/**
* Create retina-ready images
*
* Referenced via retina_support_attachment_meta().
*/
function retina_support_create_images( $file, $width, $height, $crop = false ) {
if ( $width || $height ) {
$resized_file = wp_get_image_editor( $file );
if ( ! is_wp_error( $resized_file ) ) {
$filename = $resized_file->generate_filename( $width . \'x\' . $height . \'@2x\' );
$resized_file->resize( $width * 2, $height * 2, $crop );
$resized_file->save( $filename );
$info = $resized_file->get_size();
return array(
\'file\' => wp_basename( $filename ),
\'width\' => $info[\'width\'],
\'height\' => $info[\'height\'],
);
}
}
return false;
}
add_filter( \'delete_attachment\', \'delete_retina_support_images\' );
/**
* Delete retina-ready images
*
* This function is attached to the \'delete_attachment\' filter hook.
*/
function delete_retina_support_images( $attachment_id ) {
$meta = wp_get_attachment_metadata( $attachment_id );
$upload_dir = wp_upload_dir();
$path = pathinfo( $meta[\'file\'] );
foreach ( $meta as $key => $value ) {
if ( \'sizes\' === $key ) {
foreach ( $value as $sizes => $size ) {
$original_filename = $upload_dir[\'basedir\'] . \'/\' . $path[\'dirname\'] . \'/\' . $size[\'file\'];
$retina_filename = substr_replace( $original_filename, \'@2x.\', strrpos( $original_filename, \'.\' ), strlen( \'.\' ) );
if ( file_exists( $retina_filename ) )
unlink( $retina_filename );
}
}
}
}