Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I'm working in Wordpress, I quite often need to make adjustments to plugins. The recommended method, as I understand it, is to take the plugin file I'd like to modify (say, mypluginfile.php), and copy it to my theme folder. The file will now override the plugin's version of the file.

My problem with this is that in order for it to work, the file HAS to be in the root of the theme directory...which means that the theme root quickly becomes incredibly messy. With adjusted plugin files strewn throughout the theme root, it's also very difficult to, at a glance, keep track of which file belong to which plugin.

Is there any way of modifying plugin files but still maintaining a nice directory structure. Maybe something like:

- /mytheme/style.css
- /mytheme/functions.php
- /mytheme/myplugin/mypluginfile.php
- /mytheme/myplugin/mysecondpluginfile.php
- /mytheme/mysecondplugin/anotherpluginfile.php

I have a hard time believing that everyone out there just fills their theme folder with an array of files belonging to different plugins. What's best practice here?

share|improve this question

1 Answer 1

Putting plugin files into the theme is not recommend, quite the contrary.

If you really have to change the plugin, create a Git repository for the plugin directory:

cd plugindirectory
git init

Now create a new branch:

git checkout -b modified

Git will now hold the original state in the branch master and you can edit the files in the branch modified.

When there is an update for the original available, you switch to the master …

git checkout master

… run the update, make a commit …

git add .
git commit -m 'update'

and then merge the improvements into your modifications:

git checkout modified
git merge master

You can automate these tasks and run the git commands per script on updates.

Keep your theme directory as clean as possible and the plugin code “updatable”.

share|improve this answer
    
Hmm, how about if I were to pass the site off to a client. With that method, wouldn't they run into issues if they ever updated a plugin that I had modified? –  Pete May 1 at 15:39
    
@Pete They will run into problems anyway when they miss security updates. –  toscho May 1 at 15:40
    
Hmm, is there no way around them having problems? –  Pete May 1 at 15:41
    
@Pete There is: create your own plugin and maintain it. –  toscho May 1 at 15:42
    
That doesn't make any sense. For example, let's say I'm using theme-my-login, and I simply want to change the order that "Register" and "Lost Password" appear in on the page. It is certainly not practical to maintain my own plugin just to accomplish that, yet if I use the git method, it will be overwritten by an update performed by the client. –  Pete May 1 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.