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 writing my first wp plugin and I have many problems, most of those I got to solve by just reading the codex, but I don't know how to write into a css file within my plugin's options. Maybe there's a better way of doing it, but what I had in mind was using a text field and saving that into an empty custom.css file that would be packed with the plugin. I don't want having to save css info into the wp_options table. Is there a standardized way of having custom css for your plugins which could be changed by the user without having to open the css file themselves??

Thanks in advance

share|improve this question
1  
    
thanks a lot wyck, I had missed that one –  user5057 May 3 '11 at 12:09
add comment

1 Answer 1

What's wrong with saving CSS to the database? That is the correct approach. And that way, you can simply output the options to a function, which can be enqueued properly, using wp_print_styles, and entirely avoid file operations/writing to .css files.

share|improve this answer
    
Well I didn't know that Chip. Thanks for your response. How do I save it though? everything in one field like a big string? or should I add several fields in my form labeled as the attrs? –  user5057 May 3 '11 at 12:07
    
It depends entirely on what your options are. If, e.g. you're allowing the user to customize colors, then I would have one text field for each element, to hold the user-specified color value. But if you're allowing general "custom CSS", then you might use a textarea instead. (Note that the former is much easier to validate/sanitize than the latter.) –  Chip Bennett May 3 '11 at 13:24
    
Yeah, I guess I know what you mean Chip. It would be rather complex if I were to validate a whole text area. I guess that's why I would rather store that somewhere else other than the database –  user5057 May 11 '11 at 22:29
    
Well, not really, because it's still just CSS that goes into the textarea. The sanitization is easy ( wp_filter_nohtml_kses( $input['some_textarea_css'] );, but the validation would be more difficult (if you even attempt to validate arbitrary CSS). –  Chip Bennett May 11 '11 at 22:53
add comment

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.