WordPress plugin updates / set file as immutable to prevent certain files from changing?

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?

Related posts

Leave a Reply

1 comment

  1. 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');
    }