Changeset 3165218
- Timestamp:
- 10/08/2024 07:35:34 PM (18 months ago)
- Location:
- svgplus
- Files:
-
- 3 edited
-
tags/1.0.9/svgplus.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/svgplus.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
svgplus/tags/1.0.9/svgplus.php
r3165214 r3165218 120 120 121 121 // Sanitize SVG files upon upload 122 function svgplus_sanitize_uploaded_svg($data, $file, $filename, $mimes) { 123 if ($data['type'] === 'image/svg+xml') { 124 $svg_content = file_get_contents($file['tmp_name']); 122 function svgplus_sanitize_uploaded_svg($upload) { 123 $filetype = wp_check_filetype($upload['file']); 124 125 if ($filetype['ext'] === 'svg' && $filetype['type'] === 'image/svg+xml') { 126 $svg_content = file_get_contents($upload['file']); 125 127 $sanitized_svg = SVGPlus_Sanitizer::sanitize_svg($svg_content); 126 128 127 129 if ($sanitized_svg === false) { 128 $data['error'] = 'Unable to sanitize SVG file.'; 130 $upload['error'] = __('Unable to sanitize SVG file.', 'svgplus'); 131 return $upload; 129 132 } else { 130 file_put_contents($file['tmp_name'], $sanitized_svg); 133 // Overwrite the uploaded file with the sanitized content 134 file_put_contents($upload['file'], $sanitized_svg); 131 135 } 132 136 } 133 137 134 return $ data;138 return $upload; 135 139 } 136 add_filter('wp_ check_filetype_and_ext', 'svgplus_sanitize_uploaded_svg', 10, 4);140 add_filter('wp_handle_upload', 'svgplus_sanitize_uploaded_svg'); 137 141 138 142 // Enqueue custom CSS -
svgplus/trunk/readme.txt
r3165213 r3165218 4 4 Requires at least: 5.0 5 5 Tested up to: 6.6 6 Stable tag: 1.0. 96 Stable tag: 1.0.10 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 116 116 == Upgrade Notice == 117 117 118 = 1.0. 9=118 = 1.0.10 = 119 119 120 120 Please update to this version to benefit from improved SVG sanitization and functionality enhancements. -
svgplus/trunk/svgplus.php
r3165213 r3165218 3 3 * Plugin Name: SVGPlus 4 4 * Description: Upload, sanitize, and display SVG files securely in WordPress. 5 * Version: 1.0. 95 * Version: 1.0.10 6 6 * Author: Rizonepress 7 7 * License: GPL2 … … 71 71 $roles = get_editable_roles(); 72 72 73 // Ensure 'allowed_roles' is an array 74 if (!isset($settings['allowed_roles']) || !is_array($settings['allowed_roles'])) { 75 $settings['allowed_roles'] = ['administrator', 'editor', 'author']; 76 } 77 73 78 ?> 74 79 <div class="wrap"> … … 107 112 function svgplus_upload_mimes($mimes) { 108 113 $settings = get_option('svgplus_settings', svgplus_default_settings()); 109 $allowed_roles = isset($settings['allowed_roles']) ? $settings['allowed_roles'] : ['administrator', 'editor', 'author'];114 $allowed_roles = isset($settings['allowed_roles']) && is_array($settings['allowed_roles']) ? $settings['allowed_roles'] : ['administrator', 'editor', 'author']; 110 115 $user = wp_get_current_user(); 111 116 … … 120 125 121 126 // Sanitize SVG files upon upload 122 function svgplus_sanitize_uploaded_svg($data, $file, $filename, $mimes) { 123 if ($data['type'] === 'image/svg+xml') { 124 $svg_content = file_get_contents($file['tmp_name']); 127 function svgplus_sanitize_uploaded_svg($upload) { 128 $filetype = wp_check_filetype($upload['file']); 129 130 if ($filetype['ext'] === 'svg' && $filetype['type'] === 'image/svg+xml') { 131 $svg_content = file_get_contents($upload['file']); 125 132 $sanitized_svg = SVGPlus_Sanitizer::sanitize_svg($svg_content); 126 133 127 134 if ($sanitized_svg === false) { 128 $data['error'] = 'Unable to sanitize SVG file.'; 135 $upload['error'] = __('Unable to sanitize SVG file.', 'svgplus'); 136 return $upload; 129 137 } else { 130 file_put_contents($file['tmp_name'], $sanitized_svg); 138 // Overwrite the uploaded file with the sanitized content 139 file_put_contents($upload['file'], $sanitized_svg); 131 140 } 132 141 } 133 142 134 return $ data;143 return $upload; 135 144 } 136 add_filter('wp_ check_filetype_and_ext', 'svgplus_sanitize_uploaded_svg', 10, 4);145 add_filter('wp_handle_upload', 'svgplus_sanitize_uploaded_svg'); 137 146 138 147 // Enqueue custom CSS … … 147 156 } 148 157 add_action('wp_enqueue_scripts', 'svgplus_enqueue_custom_css'); 149 150 158 ?>
Note: See TracChangeset
for help on using the changeset viewer.