My theme includes a custom css code block where I permit the site owner to include any custom css they require straight to the mind portion of the theme. This card inserts whatever they have put into this block in to the wordpress database like a custom option place.

Then i retrieve the information into header.php and output it between an inline style tag like so...

<style type="text/css">
.test h1 {}
.testcss2, .somecss {}

This works perfectly fine, however, I must cleanup and minify the markup when its written towards the database. I guess a regex is required to do that? If that's the case, an amount that be?

The end result I am searching for, once the code is written in to the page's markup is...

<style type="text/css">.test h1{}.testcss2,.somecss{}</style>

I'd like to turn back minified markup when its presented to the consumer to edit during my theme options. For the reason that view, Among the finest to reformat the minified css code to ensure that each directive has returned by itself line.

It is dependent what you would like achieve using this method. To be sure with @thomasfedb that you'll likely messup design for most peoples CSS using this method transformation and can likely cause more trouble than its worth.

It's my suggestion that you simply keep your data just as the consumer joined it, after which 'minify' it whenever you render it towards the page.

This can not help you save and storage inside your database, and it'll improve your CPU usage per page render, but you will save the bandwidth of all of the extra new-line figures.

An alternative choice, supposing database storage isn't a concern, would be to keep data two times, once in which the user edits, and when minified. Then simply just minify and copy the consumer-editable area in to the minified area whenever the consumer makes any changes.

I do not use whatever real reason to get this done, a couple of newline charactors inside a web page is not realy likely to set you back greatly page-weight.

Therefore my solution could be: don't.

Also, even when you turn back minification, you may 'mess using the style' of many people, who choose different css designs.