Here's a small but incredibly useful snippet of code I'd like to share. When I'm developing WordPress websites, I often find myself in a situation where I need to code on a site that's actually live. Naturally I want to keep my prototyping invisible to the visitors of that site. After all, I don't want anyone seeing all my mistakes now do I?
The following wrapper can be applied to a block of code and the results will only be visible on the live site to users who are logged in with admin privileges.
global $user_ID;
if ($user_ID) :
if (current_user_can('level_10')) :
// Prototyping code here...
endif;
endif;
That's all there is to it.
Last Revision: October 24th, 2009 at 11:32
Until you forget a semicolon…
Eh? Have I? Where? I don’t see it! (But then I wouldn’t if I’d missed it would I?)
No, I mean, this only works as long as you don’t introduce a parse error into the script. One of those, and the whole page goes boom.
Ah, yes, I got it. I realised what you were saying Noah, not long after I’d posted my reply. Duh! All I can say in my defence is that it was early and I hadn’t been up long… and I hadn’t had my caffeine injection.
So I need to add some kind of trapping mechanism to the “Cloaking Device” eh? Okay, I’ll look into it.
Watch this space!