Author Archives: Alan Levine aka CogDog

There’s a First Time For Everything… My First Plugin

I’ve been using WordPress since 2005, hacking themes since 2008, and doing a whole lot more since then.. yet I have never written a plugin. All of my custom code has been done in theme templates and functions.php files

Well, now I have done so, without spilling much blood.

This is also the first time I have written something with a proper PHP class.

As usual I came across a wide swath of how to posts, many of them as helpful as echoing Hello World level complexity. I found Francis Yaconiello’s How to write a WordPress plugin good for giving a solid foundation for elements to include, I plucked bits from the WordPress Plugin Developer Guidelines. And because my plugin needed to create and respond to a form, jaskokyn’s How to Create a WordPress Admin Form was of assistance too.

I do find it worth noting that I rarely get my answer in a single tutorial, I have to mix and match (and discard often).

Do not get to excited, this is not very exciting. And I bet Martin Hawksey has already done something way more elaborate.

The folks I am working with on DML Commons are doing some research on the interactions and were looking for some data from the blog syndication. I’ve looked at a smattering of WordPress stats tools, and they all are like log data, and are presented only to the admin side. I was thinking there might be something that does slick charts and graphs and stuff for the public side (I bet there is, one cannot find everything out there).

But there was nothing even I could find that would give them some basic data by category for the syndicated posts (things brought into the blog hub via Feed WordPress). My first effort was to do a one off custom script that generated the following in CSV format:

  • post ID
  • source indicated (either ‘local’ or ‘syndicated’)
  • post title
  • publication date and time
  • author name (first and last name from profile, this is added to user profiles via the gravity form signup thing I built)
  • author username on site
  • blog name (host blog or remote blog if syndicated post)
  • ost character count (string character count after HTML stripped out)
  • post word count (after HTML stripped out)
  • number of links in post (count of ” tags)
  • list of hyperlink urls (from all href= tags, hoping my regex is on target)

I set up a duplicate of the site on a dev server, and sent them a few links to export the data for the two different strands, Professional PathWays and Design Research (because of the syndication design, these posts get put into categories). This was supposed to be just a test of the functionality.

They said, “thanks this is perfect!”

Hmmm.

I really need to start rolling some of my things into plugins so they can be use elsewhere w/o needing the theme hacking.

So in a few hours this morning I got a working plugin, now a very alpha version on github as Export Post Data to CSV. When activated, it adds a Post CSV Export item to the WordPress Tools menu. Nothing sophisticated:

My big fat plugin
My big fat plugin

You can choose to export data on all posts, or from within a category. The wp_dropdown_categories() function is handy as it can generate the menu, including an item for All Categories, keeping the category hierarchy, and even including a post count. I have it running here on my blog:

CogDogBlog Sloppy Category menu selector
CogDogBlog Sloppy Category menu selector

Then you click the Blue Button.

The script generates the CSV data which you then choose where to download. I did an export on my category for Syndicated posts from my Barking Dog Studios site (I bring in posts there from a category on that site I go “inside the photo”).

Boom! Barking Dog Category CSV Data

Screen shot of CSV data
Screen shot of CSV data

I do not know how helpful this kind of data per post is. Ideally we’d like to cross it by time maybe with twitter data. What else might there be worth extracting from posts? I can already see that I could get tags and categories.

This on its own is not big, but now I have the method started. For the upcoming #vcubrb projects, I am hoping to roll into a plugin a lot of the functionality I have been hand coding into the Feed WordPress sites I have been building. This way we could potentially make it easier for people to create a Connected Course. I can see having:

  • A Shortcode for adding a user sign up form, without needing gravity forms (including the logic to add the data to Feed WordPress directly
  • The Shortcodes I use for generating the blog lists
  • A script to generate OPML feeds for categories of blogs

But at least now I have grown up, written a plugin, and can shave like a big boy.

Leaving #TWP15 Tracks

This is just making sure there’s a post in the category in the feed that connects to the Teaching with WordPress thing going on at UBC, being led by good colleagues and friends there.

I’ve been using WordPress since April 2005, when it was version. Why do I know that? Because I have a blog post marking the migration from a few years of running a blog on MovableType. Here is how snazzy it looked (thanks Internet Archive Wayback Machine):

The styling dog blog in 2006...
The styling dog blog in 2006…

Admission. I do code. And I like it. I am not a super sophisticated programmer and am sure many on StackExchange would rip my code to shreds. But I can do stuff to make WordPress do what I want it to do, rather than me having to figure out what it will let me do.

I bet in 2005-2006 I was mostly publishing and doing a bit of trying plugins, but once I started working for NMC in 2006 I was already starting to bend themes. One of the prouder ones I did was a hacking of a theme to build a site for the NMC Pachyderm Project— this one standing out in mind because I was showing it in a (Moosecamp?) session on it at Northern Voice in 2006, and this guy named Matt Mullenweg was in the audience.

That probably led to be invited in 2008 to talk about WordPress in Education at the main Wordcamp in San Francisco.

And so on.

I would like perhaps the focus not to be so much “Making a Course Site” in WordPress which sort of leads to LMS like thinking. There’s a lot more broader things one can build that are not just course sites, not just reverse listed chronological posts adjacent to a sidebar. In fact, I think I’ve only done a handful of course sites.

I’ve been more interested in using WordPress as a tool to help people make other tools, this was the focus of my recent time at TRU working on SPLOTs and some of the other not quite documented well projects milling around my github. There are built as WordPress Themes with built in functionality, but also configurability to do things like make your own flavor of a DS106 Assignment Bank (this is somewhat of an update in progress making changes for a new project this summer).

And so on.

WordPress is my HyperCard.

And that is for a later post.


Top / Featured image credit: flickr photo by SoulRider.222 http://flickr.com/photos/automotocycle/4364347610 shared under a Creative Commons (BY-ND) license