bool enablePostingToWordpress = Config.GetAppSetting<bool>("EnablePostingToWordpress", false);
bool requireWordpressOverride = Config.GetAppSetting<bool>("RequireWordpressOverride", true);
string myUrl = "blah";
if (AllowPostToWordpress(enablePostingToWordpress, requireWordpressOverride, myUrl))
{
// do stuff
}
private static bool AllowPostToWordpress(bool enablePostingToWordpress, bool requireWordpressOverride, bool siteUrlOverrideExists)
{
// this is verbose (the code could have been written in many fewer lines)
// but i want it to be clear what's going on here. there are two levels of protection
// against accidental posts to wordpress which are here for our dev/staging environments.
// first, we have a key that simply says whether or not we can post to production.
// next, we have the ability to override the xmlrpc endpoint in the database
// finally, we have the ability to require that the endpoint is overridden
bool doPost = false;
if (enablePostingToWordpress)
{
if (!requireWordpressOverride)
{
doPost = true;
}
else
{
if (siteUrlOverrideExists)
{
doPost = true;
}
}
}
return doPost;
}