Skip to content

Instantly share code, notes, and snippets.

@osbre
Created April 16, 2025 20:07
Show Gist options
  • Select an option

  • Save osbre/36f250c5b8cda02f94c5e2b9979fffc5 to your computer and use it in GitHub Desktop.

Select an option

Save osbre/36f250c5b8cda02f94c5e2b9979fffc5 to your computer and use it in GitHub Desktop.

Revisions

  1. osbre created this gist Apr 16, 2025.
    23 changes: 23 additions & 0 deletions svg-upload-support.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <?php
    /**
    * Plugin Name: SVG Upload Support
    * Description: Allows SVG uploads for admins only.
    * Version: 1.0
    * Author: Ostap Brehin
    * Author URI: https://ostapbrehin.com
    */

    add_filter('upload_mimes', function ($mimes) {
    if (current_user_can('manage_options')) {
    $mimes['svg'] = 'image/svg+xml';
    }
    return $mimes;
    });

    add_filter('wp_check_filetype_and_ext', function ($data, $file, $filename, $mimes) {
    if (!$data['type'] && current_user_can('manage_options') && preg_match('/\.svg$/i', $filename)) {
    $data['type'] = 'image/svg+xml';
    $data['ext'] = 'svg';
    }
    return $data;
    }, 10, 4);