Today I wanted to talk about a problem which Justin Tadlock will be covering in more detail at some point in the future and that is, plugins which contain a CSS file to edit their style. Don’t get me wrong, Lester Chen is a great plugin author, but I find it increasingly annoying that after I make the necessary styling changes to his WP-PageNavi plugin so that it blends in with my theme, I overwrite those changes once I upgrade his plugin.
Based on what I’ve been told, it’s fairly easy to add a plugins stylesheet to your themes CSS file so that this sort of thing doesn’t happen. But, I wanted to raise the question if whether or not plugins should come with their own CSS file for editing or just store the styling information in the database so that end users don’t have to worry about messing around with the CSS in the first place? I’m pretty sure this is how Lester’s WP-Polls plugin works as I can define from within the plugin options page which colors the voting bars should be via hexadecimal color codes.
What are the drawbacks to storing plugin style information in the database versus a CSS file? On the surface, seems like adding the style information right into the plugins options table in the database is A OK to do.
I favor a hybrid approach.
Provide for color changes and styling within the plugin administration, storing the values in the database. Make this the default functionality. Then also provide the necessary CSS information so if a user wants to write his own CSS they can, and they can add this to their themes CSS.
If a user chooses to manage his own CSS he can tell the plugin not to output the database driven styles.
This approach satisfies the power users and developers as well as the novices who need a simple solution.
I’m not a big fan of the plugin itself having it’s own static CSS file(s). Get to be too much to manage if a bunch of your plugins all have their own CSS files to juggle.