Make Advanced Custom Fields smarter about handling date fields

I love Advanced Custom Fields almost as much as I love WordPress itself. But that’s not to say it doesn’t have its problems. Most are obscure, and minor… and incredibly aggravating once you stumble upon them.

Here’s one such case. Date Picker fields are great, but no one seems to be able to agree on how to store dates in a database… other than insisting on avoiding Unix timestamps, the obvious choice.

ACF stores its dates, for some reason, in YYYYMMDD format (or, as we’d express it in PHP Land, Ymd). No delimiters at all. If you’re not going to use Unix timestamps, why not at least use the MySQL convention of Y-m-d H:i:s? But I digress.

I’m presently working on a project that merges some functionality of ACF and Gravity Forms, along with some custom code, to create a jobs board. It’s super-slick how Gravity Forms can create posts from a form submission, and even set them to pending review so a site editor can come in and review them before publishing.

But… dates. Jobs boards have a lot of dates. And while Gravity Forms offers a wealth of options for date string format, Ymd isn’t one of them. So it ends up storing the date value in the database in a format ACF doesn’t like. Because ACF is very picky. It wants that format, and no other. If the value in the field is not in Ymd format, the value displayed on the admin editing screen is just… blank. And then when you save, whatever was previously saved in that field is erased.

It doesn’t have to be this way. And thanks to the following bit of code, it won’t be. Now bear in mind, this is only altering what ACF renders on the editing screen. Once you’ve saved again from that point, the date will be stored in ACF’s preferred format, but up until then, it will be in whatever other format it was in when it landed in the database.

If you’re writing your front end code proactively, that won’t matter. Because you’re already assuming data inconsistency and using strtotime() to standardize any dates you’re working with in your templates, right? Of course you are.

OK, then. So the real goal here is just to get ACF to display the correct, saved date when you go in to edit the post, so it doesn’t then wipe out the date when you hit Save Changes.

In your functions.php file, or wherever you think is best (a plugin would be nice), do this:

function acf_smart_dates($field) {
  if ($field['value']) {
    $field['value'] = date('Ymd',strtotime($field['value']));
  }
  return $field;
}
add_filter('acf/prepare_field/type=date_picker','acf_smart_dates');

That’ll do.

On products, services, and the trouble with Twitter

Much of the buzz this week among online geek types has been the latest step in the gradually unfolding revelation of exactly where Twitter (the business) intends to take Twitter (the service), and just how stark the difference is between that place and where these same geeks — who have been largely responsible for the establishment of Twitter as a successful platform — would like to see it go.

The latter place can most easily be summed up as, “where it started out,” but the details of where it started out, and how far it is from where the company now wants to take it, reveal a lot about the nature of the Internet as a place for commercial business, vs. the way most users see it, as a medium for communication.

Most people who use the Internet have little knowledge of, or interest in, how it actually works. Even those of us who make our living building it don’t always have a firm grasp of the technologies that make it all possible. But understanding those details, and understanding the differences between a service and a product, for lack of a more effective yet equally succinct description, can shed light on the current trouble with Twitter.

The crux of geek anger towards Twitter of late has to do with Twitter’s ongoing efforts to shut down a number of its APIs that allow third-party apps like Tweetbot (my personal favorite iPhone Twitter client) to interact with data from Twitter’s servers. Without these APIs, these third-party apps can’t function. The specifics of the situation are a lot more complicated than this, but I’ll leave the reader to investigate further; Dalton Caldwell’s post from yesterday, Twitter is pivoting, is a great place to start.

All of this may seem supremely geeky and esoteric to most Twitter users, though I suspect anyone who’s been using the Internet for more than two years would take pause at the fact that Peter Chernin, who was deeply involved in the downfall of MySpace, has just joined Twitter’s board of directors. (Especially since he chose to tweet it in a way that reveals a profound lack of understanding of how Twitter works.)

Which brings me to the topic of products and services. As I am using the terms here, a “service” is what we on the geek side of the Internet refer to as a protocol. On the Internet, a protocol is a technology, built upon a publicly documented specification, which allows particular types of interactions between devices over the Internet. A protocol is inherently public, open, and decentralized. That’s the only way they can work. Each protocol tends to have a strange acronym associated with it, some of which the creakier, older parts of the Internet may have failed to shield you from: things like HTTP (the web) or IMAP (email). All of these protocols are built upon a more fundamental, lower-level protocol: TCP/IP.

Protocols are what make the Internet work. And they’ve existed since well before anyone saw (or at least fully exploited) the Internet’s potential for profit. Protocols as services are so ubiquitous and inherent to the experience of using the Internet, we don’t even realize they exist, or what they are, or how exactly they work. And we tend to assume that anything we interact with on the Internet is kind of all the same. We might have a vague sense that something like Facebook or Twitter is a commercial enterprise, but even the geekiest among us who actively use these services products don’t often think about just how different they are at the core than things like email.

In contrast to these protocols/services, we have commercial products like Facebook or Twitter. These are not protocols. While we are all by now painfully aware of how open and public the information we share on them can be, there is nothing whatsoever that is “open” or “public” about how they actually work, and their functionality is entirely centralized within the competitive, secretive, for-profit businesses that own them.

Facebook has taken a lot of flak in recent years for its aggressive commercialization of the user experience. The information you share is not only overly public, it is parsed by their ingenious algorithms to allow them to put highly-targeted advertising in front of your eyeballs. (At least, that’s the theory; in practice it doesn’t always work so well.) As the saying goes, if you’re not paying for it, you’re not the customer… you’re the product being sold.

While it’s been easy to see how Facebook is monetizing our online interactions, the gradual creep of Twitter’s monetization has been quieter, and more insidious. It’s been easy enough to ignore promoted tweets and trending topics, and they’ve even backpedaled on occasion in response to negative user reaction. (Remember the Dickbar?) But eventually, true to the cliché, there’s a straw that breaks the camel’s back. And the latest API deprecations may represent that last straw.

You see, you can only change a product so much before eventually it ceases to resemble in any meaningful way the thing that it once was, the thing that appealed to its users in the first place. And for Twitter, the business, it is entirely their prerogative to make those changes, to “pivot,” into something completely different. But in so doing, they reveal the true nature of their product, and the fact that it was never really the service its loyal users took it to be.

Ayn Rand’s (in)famous novel Atlas Shrugged ends with capitalist Übermensch John Galt tracing the sign of the dollar with his finger. But when the dollar sign becomes the ultimate symbol of human achievement, money is the only thing in life that has value. This may be a rather heavy-handed reference (she is the most heavy-handed writer of the 20th century, after all), but profit as the primary motive of a business can easily corrupt or destroy any other values the company has.

Twitter seems to be following the standard arc of a startup, especially in the Internet age: a group of inspired geeks build something cool, it becomes a hit, venture capital comes pouring in, the founders sell out and “management” moves in, the focus of the company shifts from building something cool into turning that cool thing into a way to make money, the thing ceases to be cool (or even very useful), people move on to the next big thing, the company dies a slow death.

We’ve seen it plenty of times before (again, MySpace), but with Twitter something seems different. Twitter has become a deeply ingrained part of the Internet experience for its loyal users in a way that no other product from a for-profit business has before. It’s as essential to how many of us experience the Internet on a daily basis as email or the web itself. But while it’s just as essential, its essence is entirely different. And now the foolishness of investing so heavily and personally — in time and passion, not money — in this kind of product is becoming painfully obvious.

So, what are our alternatives? This summer, Adam Curry (yes, that Adam Curry) wrote about the value of RSS as a Twitter alternative. I think for one way Twitter is used (as a means of disseminating links to interesting news/blog posts), RSS is great, and I am a die-hard RSS user along with Twitter. But RSS can’t replace Twitter’s role as a microblogging platform.

Enter Dalton Caldwell’s (remember him?) App.net. What is App.net? It’s basically an effort to do Twitter right. For a small annual subscription fee, you get access to an ad-free social network that functions almost identically to Twitter. (The main distinction: each post is limited to 256 characters, rather than 140. Those of us who do a lot of work with databases are probably thrilled with the implications of that particular number.) Many of the geeks who were early Twitter adopters are now prominent members of the App.net community. Many of the developers of third-party Twitter clients have gotten on board with App.net sibling apps (like Netbot).

Personally, I was one of those App.net early adopters (member #5,644). But I will admit I’ve found it hard to break my old habits of working mainly with Twitter. Partly that’s because I’ve relied on Twitter’s functionality as the glue between my various social networks. I can post photos on Instagram and, via my existing Twitter-to-Facebook link, easily share my photos to both social networks with a tap. I used to have LinkedIn in the mix too, before I more-or-less abandoned it. The point is, up to now Twitter has been a geek’s paradise of a social network, with a wealth of APIs that could be used in innovative ways to do all sorts of cool things.

But Twitter doesn’t want us to do all sorts of cool things. They want us to do the things that put our eyeballs on their sponsors’ messages, because that’s the only way they’ve been able to think of (or willing to try) to make money. I would gladly pay a subscription fee for Twitter, to cut out the ads and retain access to those awesome APIs they’re so aggressively shutting down. But since they’re not interested in taking the business in that direction, a door has been opened for App.net to do all kinds of things Twitter could have done, but, it now appears, never will.

Wow, I thought the spike in traffic might last a little bit longer

Last week I was excited by the prospect of increased traffic here when I discovered that a New York Times blog had linked to a 2-year-old post on this site.

I eagerly watched my hit count go up. The post received over 500 hits in the 5 hours immediately following the appearance of the NYT link. But wow, did the traffic drop off fast. I’m still getting a trickle of hits on that 2-year-old post each day, but my overall site traffic is back down to pre-NYT levels. Here’s a chart of hits on my site over the past month. Can you tell when the NYT link appeared?

For what it’s worth, I think the earlier jump in activity from late October occurred because that was right around the time I worked with my hosting provider to reinstate some third-level domains (such as coltrane.room34.com) for links to subsections of my site. I had used these third-level domains several years ago but they had been “turned off” for at least 3 or 4 years. I can only assume from the increase in traffic that there are still sites out there that have been linking to these URLs for all of that time, even though they didn’t work.

Product placement? Fine, but then can you get rid of commercial breaks?

Product placement is as old as TV itself, and if anything it’s less insidious now than it was in the early days of television. But it seems to be coming back in a big way, and while I’m over my initial offense at seeing my favorite shows turn into “advertainment,” I still find it incredibly distracting, even when it’s funny.

Case in point, in last night’s episode of The Office, Kevin got some rare screen time and proceeded to giddily demonstrate the awesome power of the company’s shredder. Note I called it a “shredder,” not a “paper shredder,” because as Kevin demonstrated, it can shred not only a fistful of paper at once, but also such surprising objects as CDs and (OK, this joke was a little too broad) credit cards.

The thing that distracted me was that there was a prominently placed “Staples” logo on the front of the shredder. In fact, it looked like a sticker slapped on for advertising purposes in the show, and not something that’s actually a part of the unit’s design.

What really got me was that at the next commercial break, there was a Staples ad for this exact shredder!

I’ve gotten used to the product placement in The Office, what with the frequent after-work visits to Chili’s (always prominently showing the neon sign outside), and the entire Christmas episode written around the iPod. But it’s getting to the point where in some ways the show feels like a lead-in to the commercial break.

Earlier, a network promo pumped up interest in upcoming NBC shows next week, and concluded with “…And stay tuned for Ellen’s new commercial!” which at first suggested to me that Ellen DeGeneres was starting a new primetime NBC show. But no. It was an American Express commercial. And NBC promoted it as if it were one of their programs. (They even had her name on screen with the bouncing letters and pointing peacock feather that they’re using this year.)

Then, of course, we have the premiere episode of 30 Rock, in which Alec Baldwin’s character bragged about having invented the GE Trivection Oven (and how he had been promoted to Director of Television and Microwave Programming). The way the oven was described in the show made it seem like an over-the-top joke (the way SNL, I believe it was, had joked about four-blade razors a few years ago… certainly before Gillette introduced a five-blade razor last year — although I suppose technically that’s actually a “5.1-blade” razor, in true Surround Sound style). But then, you guessed it, the first commercial break featured an ad for none other than the GE Trivection Oven… a real product! (And one manufactured by NBC’s parent company, no less.)

I’d be outraged, if I weren’t such a tool.

Oh, by the way… if anyone wants to get me that shredder or a Trivection for Christmas, I’d love to receive either.