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
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!”
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:
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:
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”).
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.
The post "There’s a First Time For Everything… My First Plugin" was originally cracked open and scrambled from a rotten egg at CogDogBlog (https://cogdogblog.com/2015/06/my-first-plugin/) on June 3, 2015.