Writing a WordPress Plugin:Part I

I’ve been working on ‘StatTraq‘ a WordPress statistics plugin and have been able to find reasonably good documentation and have supplemented the rest of my needs for<> information with ‘Find in Files’, a useful feature of TopStyle. I’ll share what I’ve learned so far in a series of articles on programming WordPress 1.2 plugins.

The first thing you’ll need in creating a WordPress plugin is a set of hooks for either actions or filters. These hooks are places in the code that call your functions when an event or certain text is processed. I’ll explain both in further detail below. A list of actions and filter events can be found at the WordPress Wiki.

Actions
Actions are events that take place during the WordPress document creation cycle. When WordPress gets a request from a client (browsers like Firefox, RSS aggregators like FeedDemon or any other device like a WAP 2.o/XHTML basic phone) and the PHP application starts up. WordPress gives you the ability to call a function or functions when certain events take place.

For example with my statistics plugin I need to add information about the request to the database, to make sure that I didn’t hender the the display of the WordPress data I added a hook for the ‘shutdown’ action like so:
add_action('shutdown', 'stat_traq_event');
This allows the stat_traq_event function that I created to initiate the data entry into the database to be called after the page is created but before PHP shuts down.

Filters
The key to your plugin is determining what event should trigger your plugin. Some plugins are filters, which means that they should be run when certain text is output. For a plugin that turns your article text into 1611 Old English (the year the King James Bible was published) you’d want your filter to be called on whenever text was output.
add_filter('the_content','thine_olde_English_plugin');
When ‘the_content’ is requested the old English plugin will be passed the text of the article to manipulate it. In this case words like ‘your’ would be changed to ‘thine’ and ‘you’ would be changed to ‘thee’ and ‘donkey’ would be changed to ‘ass.’

Be sure to check out the API documentation on the wiki and feel free to participate on the WordPress forums or post questions here [as a comment], if I know the answer I’ll write you, if I don’t I’ll see if I can send you a link to somewhere with the answer.

In Part II I’ve written about interacting with the database in WordPress, something that is easy and comes with a few nifty tools built in.

A Drive in the Mountains

Today my dad and mom took Abby and I for a drive in the mountains to get us out of Jessica’s hair. Jessica wanted to finish some last minute cleaning before her sisters come into town for 1,036,800 seconds. It was a good drive and Abby was pretty well behaved. She was cute asking my dad to do certain things with her. At one point in time she said, “No. Sit in seat Grandpa!” Which I made her follow with a please, but she wanted him to sit next to her while we were at a vista point looking over the valley that holds Denver.

I love the mountains and if I could I’d carry them in my pocket so that I could play in them whenever I felt like it 🙂

Sunday

Church
The church service was really good today as we learned about Ephesians 2:7

that in the ages to come he might show the exceeding riches of his grace in kindness toward us in Christ Jesus

One verse, but totally packed full of detail. The thing that struck me is that God is doing those things toward us, we are the recipients of His kindness if we are redeemed by His son Christ. Heaven is not described in terms of Man’s experience but more in God’s actions. Sometimes we think about what we’ll be doing rather than what we should be thinking, “What will God be doing?” In this verse it is clear that God will be showing kindness to us eternally! If you can conceive of 10,000 years think of that as being nothing in the scope of infinity, and all of that time our minds will be amazed (blown away, astonished, boggled, fascinated, overwhelmed, etc.) by His kindness towards us as He reveals His love. What is even more amazing is that the amazing nature of His revelation of character will be yet more amazing even after a trillion years [if the time-space continuum can be forced on the heavenlies].

All of this amazing love because of Christ’s work on the cross. Wow!

The Second Party
The first party happened last night at the Kaes’ house for Kailey and Trystan and this afternoon we converged for a second party and had yet another great time. The best fellowship to be had in Colorado. Craig Kaes works on Jabber’s server side software and he and I have had some really neat conversations about programming but also about other things in life. It is neat to have a programming friend who likes to talk about programming but also loves so many other things.

Craig and Brian White (also there at the party with his wonderful wife and cute infant) were extolling the wonders of freshly roasted coffee. Not just recently (some coffee places), within the last year (Starbuck’s) or within the last millennia (Folger’s) but within the last 48 hours. Apparently roasted coffee loses its freshness after the first three days. Craig made me a fresh roasted, freshly ‘everythinged’ cappuccino, which was great. He explained the whole process which was pretty fascinating and I learned a lot about things and some things were very intuitive to me like the difference between a double and single shot espresso ‘filters’ [since I don’t know what they’re really called] and why some of the filters designs leant themselves to poor espressos.

Fireworks
We went to see the fireworks at Belleview Park and that was fun. I used to not enjoy fireworks so much about since I was a teenager. I’m not entirely sure why, but they lost their excitement. However, this year proved to be an wonderful experience as Abby added a fresh excitement to the old ‘blow-up and bright’ of fireworks. She kept saying, “Again” and, “Loud” and clapping as the ‘bombs burst in mid-air. At the end she said, “Good job.” I love being her dad. I know I’ve said that before but she’s a wonderful treat.

I kept thinking as the beautiful display went off before our upward-facing eyes that there were real people who saw real bombs and faught in real wars losing real friends who had real families back home. I’m blessed to live in this country and I hope and pray that our soldiers in Iraq come home quickly.

May your year between July fifth until next July 4th be blessed with the blessings I had today!

Happy Fourth of July

Today, as we honor the anniversary of the United States, take a moment to pray for our leaders. Love them of Hate them God has put them in charge and your prayers for them are warranted from either motivation: pray for them to change and pray for them to be molded and straightened to quality and compassion.

I pledge allegiance to God – and I thank Him for blessing me by making me an United States citizen.

However, because nothing on this site can be without a little humor: If the Goof Balls at www.christianexodus.org takes off we’ll be the Untied States of Umerica. [Pssst, if you have a blog/web site copy that link and add it to your site and then leave a comment here, we’ll Google bomb, make sure the text of the link read ‘goof balls’]

If Only I was a Teenager Again

If only I was a teenager again, then I could do this. I think my brother could have done close to this since he could eat a Denny’s Ice Cream Sunday in 90 seconds while I took over two minutes (usually due to an ‘ice cream headache’ AKA ‘Freezer Burn’). Please leave a comment stating your fastest food record. Comment moderation is turned on so I will have to approve your comment for it to show up on the site.

Go!

SPF on HE.net

If you’re hosted by he.net like I am you have access to edit your DNS records. I host my email on an Alt-N MDaemon server, but I was able to add SPF records to my DNS to allow me to help prevent spam messages from being sent out from my domain. The DNS record looked like this:

randypeterman.com IN TXT “v=spf1 a mx ?all”

This tells the servers that are SPF aware that they need to only accept mail from my ‘A’ DNS mail record and that if the message doesn’t come from that server, it’s spam.

For more information on SPF go to http://spf.pobox.com

Eat spam, but don’t spread it.

2nd of July

This morning two cute girls were lined up at my door seeking my affection: My bride and my daughter. I’ve got some more pictures of Abby to put up so I’ll try to get that done by the end of today. She’s sure behaving funny right now because several of her teeth are coming through.

In other news John Kerry broke new fundraising records for a presidential campaign fund raiser/raider. I believe the number is 175 Million for one fund raider. Why does any campaign need that much?

A Review of MSN’s New Search Interface

MSN has created a new version of its search engine and along with that comes a new interface. On first glimpse it looks nice, it’s rather blocky feeling compared to the last iteration and minimalist which is better for load times, but it feels naked compared to Google.

Usability
The new interface is usable, you can get what you need done relatively quickly because they’ve not got a lot of extra interface distractions, but leaves room for improvement. To MSN’s credit they didn’t add an advertisement to the inital search page, which is atypical for MSN, they love to make money on any page they show.

However, the search results page leaves me asking, “Are there only 10 results?” You get your default number of results and then you have to turn your search engine on: you must locate the ‘next’ links. The ‘next’ links were carefully placed in the right hand side looking inconspicuous rather than prominently displayed. To MSN’s credit there are not a lot of ads on the results page either.

Speed
The MSN search speed is pretty quick, not quite as quick as Google, but close enough that most users will not notice a difference. I did not do a benchmark test because I didn’t see that as a huge difference from my user perception.

How Good Are the Results?
I’m not sure how good the results are compared to Google on a full scale comparison because as one guy without some powerful application, I can’t do a head to head comparison. I searched for two phrases I know link to my site from Google: ‘Randy Peterman’ and ‘Women of Walmart.’ The Randy Peterman search returned almost identically to Google, however ‘Women of Walmart’ turned up nothing for my site on the first several pages (at which point I stopped). To MSN’s credit www.randypeterman.com is probably not where most people want to go for ‘information’ on ‘Women of Walmart’ 🙂