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.

I'm wondering--what is the best way to prevent a file (say, a custom CSS file associated with a plugin) from being overwritten during the update process?

Would setting the file's status as immutable do the trick, or would this just cause an error during update? What is the best way to go about doing this?

share|improve this question
    
Can you give an example to a situation where such thing is required? What is the difference if the file is overwritten with the same code during the upgrade or being excluded from the upgrade? –  Mark Kaplun Dec 14 '12 at 5:15
    
My issue is that the plugin upgrade process overwrites my custom CSS. Say for example I have a slider plugin which overwrites a CSS file every time the upgrade runs. I would like to prevent ONLY that one file from being overwritten. –  WordPress Wombat Dec 14 '12 at 8:20

1 Answer 1

up vote 0 down vote accepted

Basically you should not include the file in the plugin in the first place. If the reason you don't want it to be overwritten is because you modify it based on some local setting, then you should leave the immutable part of the file in it and create another file which will contain the mutable parts.

Then you can use your CSS like that (assuming you suplly constant.css with the plugin and generate costum.css locally.

add_action('wp_head','my_plugin_addcss');

function my_plugin_addcss() {

  // register and enqueue the immutable part
  wp_register_style('constantStyle', WP_PLUGIN_URL . '/my_plugin/constant.css');
  wp_enqueue_style('constantStyle');

  // register and enqueue the custom part
  wp_register_style('costumStyle', WP_PLUGIN_URL . '/my_plugin/costume.css');
  wp_enqueue_style('costumStyle');
}
share|improve this answer
    
I am not the author of the plugin. Are you saying I should force a deregistering of the plugin CSS file from outside the plugin files, then register my own elsewhere? What if the hook or name changes at some point in the future? –  WordPress Wombat Dec 14 '12 at 10:06
    
I understand the problem and I don't know a good solution for your problem. Why don't you just include another CSS in your theme that overrides the rules of the plugin's CSS instead of changing the plugin itself? –  Mark Kaplun Dec 14 '12 at 10:35
    
Well, that just feels like a hack. What if the plugin author decided that they wanted to add !important to all of their CSS? This would nullify my previous adjustments. –  WordPress Wombat Dec 14 '12 at 15:35
    
And what if the plugin's PHP code will be changed in a way not compatible with the rest of your code? what if it will stop being updated and will not be fixed when it will become incompatible with future WP? Then the plugin do not meet your needs anymore and you look for a replacement. I know that the mantra is to always upgrade, but if the site is important then you have to test before you upgrade. –  Mark Kaplun Dec 14 '12 at 16:18
    
Rarely would I ever change PHP of a plugin, but you do make a solid point. When the heck is WP going to make the move to MVC, so we can start using vQmod?? Argh! –  WordPress Wombat Dec 14 '12 at 19:24

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.