[theme-reviewers] File operations in themes, which PHP functions are/will stay allowed?
Otto
otto at ottodestruct.com
Tue Apr 5 02:51:25 UTC 2011
On Mon, Apr 4, 2011 at 8:15 PM, Lmm Muc <lmmmuc at gmail.com> wrote:
> I plan to write dynamic CSS to a file (ending on .css) located in the theme
> folder
With regards to this specific problem, there is a couple of issues
with the idea:
1. On any kind of secure setup, you probably don't have permissions to
write files into the themes directory. Using the upload folder would
work, but suffers the same ownership problems. Using the WP_Filesystem
to write the file works around this ownership and permissions problem,
but if you write into the themes directory, a theme upgrade wipes out
your static file.
2. For any normal kind of theme, you probably don't have that much
dynamic CSS that you actually need to create. You probably only have a
few settings, for things like colors, fonts, etc. No more than 1K of
code, probably. The dynamic CSS should go *inline* in the page itself.
Minified, if you prefer.
Look at how the custom_background and custom_header stuff in core
works. It's creating CSS and then inserting it right into the page
using the wp_head hook. That's the right way to do dynamic CSS. Not
only does it avoid the whole writing files problem, but it also avoids
an extra HTTP round trip to the server to get your dynamically-written
static, but small, CSS file. It's actually faster and simpler to put
the dynamic CSS inline on the page itself.
-Otto
More information about the theme-reviewers
mailing list