下面是一个PHP库,它是为清理SVG文件而创建的,可能值得一看。https://github.com/darylldoyle/svg-sanitizer
下面是一个如何使用的示例:
// Now do what you want with your clean SVG/XML data
function your_save_meta( $post_id, $post, $update ) {
// - Update the post\'s metadata.
if ( isset( $_POST[\'svg_meta\'] ) ) {
// Load the sanitizer. (This path will need to be updated)
use enshrined\\svgSanitize\\Sanitizer;
// Create a new sanitizer instance
$sanitizer = new Sanitizer();
// Pass your meta data to the sanitizer and get it back clean
$cleanSVG = $sanitizer->sanitize($_POST[\'svg_meta\']);
// Update your post meta
update_post_meta( $post_id, \'svg_meta_name\', $cleanSVG );
}
}
add_action( \'save_post\', \'your_save_meta\', 10, 3 );