How can I prevent my plugin updates from clobbering the user edits and file additions in a particular subdirectory of my plugin?
I wrote a syntax highlighting plugin that makes use of GeSHi. A sub folder of the plugin is GeSHi itself. Many users will want to customize / edit the language files within GeSHi.
Specifically here is the directory structure:
- wp-contente/plugins/my-plugin/
- several subdirectories etc
- wp-content/plugins/my-plugin/geshi/geshi/
- users are going to add files to this directory
- they will also edit files in this directory
- when they pick up their new updates I don’t want to erase their edits
What’s the best way of solving this?
Thanks!
Here’s what I was thinking, but I don’t know how to implement:
- On the update plugin action hook (?) make a temporary copy of the files I want to preserve.
- Get the new version unzip and install like usual
- Copy the preserved files from the temp copy to the new version
- Remove the temp copy
Ideally this would all be done with files, but worst case scenario I could save data to the DB.
Problem is I don’t see hooks for plugin updates. I looked here and here.
Don’t allow your users to add files or edit your files.
Instead, use things like
do_action
andapply_filters
like the WordPress core does.I’m not familiar with GeSHi, but I would suggest you figure out where in the class it loads the file required for the language. Modify the file path so it looks something like this:
Then users could hook into it and modify the file path accordingly…
Your best bet is probably to create a Subclass of GeSHi, modify the methods you need to modify (as suggested), and use that class for your plugin. If GeSHi updates, you can drop in the new version without loosing your changes.
No having to worry about overriding user files or anything else. Users, if they need a new language in the library, can just create a very simple plugin of their own.
Generally wordpress encourages one to use the uploads folder. Any plugin update will always overwrite whatever is in the plugin folder.
I have my plugins create a subfolder under uploads that stores any use editable stuff. That way it is safe from both wp and plugin / theme updates.
So far languages, my plugin checks if there is a custom language file in uploads/subfolder. If not then it loads from the plugin language folder the latest default language version.
Why not use version control software and let everyone contribute to their own branch? At a certain point, you could simply fold those branches into your main plugin repo.