Giter VIP home page Giter VIP logo

wp-sanitize-accented-uploads's Introduction

geniem-github-banner

WP Plugin: Sanitize Accented Uploads

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

WordPress plugin which removes accented characters like åöä from future uploads and has easy wp-cli command for removing accents from current uploads and attachment links from database. This helps tremendously with current and future migrations of your site and helps you to avoid strange filename encoding bugs. It also turns spaces into dashes ' ' => '-' and removes any other special characters like ™ ¼ so that they don't bother you anymore.

Sanitize accents from Cyrillic, German, French, Polish, Spanish, Hungarian, Czech, Greek, Swedish. This even removes rare but possible unicode NFD characters from files by using PHP Normalizer class. These usually happen if you have mounted uploads into your vagrant box in OS-X.

This plugin even tries to fix your files which are already corrupted. For example you can fix situations where you might have uploaded file ääkkönen.png which has corrupted into ääkkönen.png. See more in last section. These encoding errors are taken from http://www.i18nqa.com/debug/utf8-debug.html.

This plugin and wp-cli command are WordPress multisite compatible.

Installation

Composer

Install with composer by running:

$ composer require devgeniem/wp-sanitize-accented-uploads

OR add it into your composer.json:

{
  "require": {
    "devgeniem/sanitize-accented-uploads": "*"
  },
  "extra": {
    "installer-paths": {
      "htdocs/wp-content/mu-plugins/{$name}/": ["type:wordpress-muplugin"]
    }
  }
}

It installs as mu-plugin so that your clients won't accidentally disable it.

Wordpress.org

You can also download the plugin from wordpress.org:

https://wordpress.org/plugins/wp-sanitize-accented-uploads/

Contributing

Contributions are welcome! If you add new functionality remember to add new unit tests too.

Use WP CLI to remove accents from uploads and database

This searches for accented filenames in all of your attachments. If it founds any it looks if these attachments are used in post content and sanitizes all occurences of the the attachment filename path from wp_posts and wp_postmeta.

Take backup from your files and database before running this. It works for us but we can't give any guarantees.

# You can analyze before running it:
$ wp sanitize all --verbose --dry-run

# When you are sure go ahead and run it
$ wp sanitize all

# If you have a network you can do network wide replace
$ wp sanitize all --network

Example output

$ wp sanitize all
Found: 5 attachments.
This may take a while...
REPLACING: ääkkönen.png ---> aakkonen.png
----> Checking image:     /var/www/wp/wp-content/uploads/2016/04/ääkkönen.png
----> Replaced file:      ääkkönen.png -> aakkonen.png
----> Checking thumbnail: /var/www/wp/wp-content/uploads/2016/04/ääkkönen-150x68.png
----> Replaced thumbnail: ääkkönen-150x68.png -> aakkonen-150x68.png

Remaining workload: 2 attachments...

Success: Replaced 1 from 5 attachments.

wp-sanitize-accented-uploads's People

Contributors

jeremyzahner avatar onnimonni avatar rhurling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-sanitize-accented-uploads's Issues

Problem with a PDF file

I tried to fix existing files with the command line tool but the tool ran into some error on a PDF file. The file didn't have any special characters. 21 characters, with one uppercase character and an underscore.

Unfortunately I was quite busy at the time and didn't have time to troubleshoot, so I don't have any more details to tell about this possible bug. I didn't even save the error message anywhere 😑 I just renamed that file manually and after that the command line tool worked well.

This ticket is only a small reminder that there might be a problem with PDF files. I will report more if I ever run into the problem again or have time to recreate the problem somehow.

Using the plugin visually?

I want to use visually plugin from the wp-admin wordpress, how do I do?
PS: No I have access to WP-CLI

Force sanitize database entries

I have a larger site and for some reason wp sanitize all didn't go through as expected, so I have everything right in Media Library, but in articles the images are in the old format, capitalized and with wrong letters - so lots of 404s. Any way to force sanitize all db entries?

Problems with .mp4 files

used the CLI command to process old files, and for some reason all uploaded mp4 files broke miserably and were deleted.

Thank god for backups.

Metadata values for uploads are replaced incorrectly

$ wp sanitize all will change the metadata of your files incorrectly in some cases.

Here's example of metadata from my site:

wp eval "var_dump(wp_get_attachment_metadata(9));"
array(5) {
  ["width"]=>
  int(418)
  ["height"]=>
  int(280)
  ["file"]=>
  string(17) "2014/11/test1.jpg"
  ["sizes"]=>
  array(5) {
    ["thumbnail"]=>
    array(4) {
      ["file"]=>
      string(17) "test1-150x150.jpg"
      ["width"]=>
      int(150)
      ["height"]=>
      int(150)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
    ["medium"]=>
    array(4) {
      ["file"]=>
      string(17) "test1-280x160.jpg"
      ["width"]=>
      int(280)
      ["height"]=>
      int(160)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
    ["small"]=>
    array(4) {
      ["file"]=>
      string(16) "test1-107x75.jpg"
      ["width"]=>
      int(107)
      ["height"]=>
      int(75)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
    ["map-img"]=>
    array(4) {
      ["file"]=>
      string(17) "test1-152x108.jpg"
      ["width"]=>
      int(152)
      ["height"]=>
      int(108)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
    ["custom-size"]=>
    array(4) {
      ["file"]=>
      string(17) "test1-418x200.jpg"
      ["width"]=>
      int(418)
      ["height"]=>
      int(200)
      ["mime-type"]=>
      string(10) "image/jpeg"
    }
  }
  ["image_meta"]=>
  array(11) {
    ["aperture"]=>
    int(0)
    ["credit"]=>
    string(0) ""
    ["camera"]=>
    string(0) ""
    ["caption"]=>
    string(0) ""
    ["created_timestamp"]=>
    int(0)
    ["copyright"]=>
    string(0) ""
    ["focal_length"]=>
    int(0)
    ["iso"]=>
    int(0)
    ["shutter_speed"]=>
    int(0)
    ["title"]=>
    string(0) ""
    ["orientation"]=>
    int(1)
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.