Cleaning up PHP functions

Last year, I took some time to write a small blog theme for Anchor CMS using some PHP and a lot of CSS. Too much, if you ask me. If I had the time, I'd go back and clean a lot of it up. Maybe during a rainy day.

I haven't logged into GitHub in a while. Teaching has been all consuming lately and I've not really had time to mess around with some coding projects I'd started so long ago. I hopped on tonight to grab some code for something else I've been working on, and alas, a problem with my theme.

Someone, somewhere thought my theme was good enough to use, which is pretty cool. But, some of the functions weren't working correctly, and some were just plain missing (oops). I'd made a mistake somewhere in my cloning and rebasing, and I hadn't taken the time to make sure I didn't flub something up along the way. Anyways, long story short, he grabbed some code from my live demo site and got it working. But still. Customer support is our number one priority.

Here's what I started with:

broke

function twitter_account() {
    return Config::get('meta.twitter');
}

function twitter_url() {
    return 'http://www.twitter.com/' . twitter_account();
}

The idea was to have someone create some metadata (twitter_account) once and then have it populate a link to their Twitter page as well as be the attribution info on any of the tweet links on posts. Easy enough, right? Wrong. The account function wasn't returning the correct URL because I done messed up my PHP call. It should have been this:

fixed

function twitter_account() {
    return Config::get('meta.twitter');
}

function twitter_url() {
    return 'http://www.twitter.com/' . site_meta('twitter_account');
}

I'd forgotten that the twitter_account meta field only stores the data object. I have to tell the second function that there is some site metadata stored in the twitter_account call, not just the function itself. Oops.

All's well now and it's working fine, from what I can tell. Iteration is the game. Back to the workshop...

Leave a Reply

Your email address will not be published. Required fields are marked *