Writing a Wordpress Plugin (My First Wordpress Plugin)
May 10th, 2008
I’ve never actually taken the time to write my own pluging for wordpress. I have thought about it a few times, but I’ve never had the need to.
See wordpress uses one of my favorite rewrite rules that checks to see if a file exists, and if it does, it acknowledges the fact it does, and doesn’t try to take over. So in the past, when I needed something customized, I would simply create a php file of my own, and bypass wordpress all together. It the down and dirty solution to adding pages to a site without needing to integrate it with wordpress. So the need for writing a plugin has never really been there.
Well today, I decided that some code I was writing deserved to be made into a plugin. I’m presently coding up the module for my wedding website that will allow people to RSVP. There is probably already a module out there for doing this kind of thing, but I didn’t find one in the 5 minutes I looked for one that could do everything I wanted…
That said, it’s time to get started. I’m hoping to document the process here in a series of blog posts (if I don’t get to lazy). The code will most likely be finished within an hour or two of this blog post, but my lessons probably won’t be online for awhile longer (I’ll delay each post as I write it to provide daily content for the blog… After all, no one wants to read this stuff all at once right?)
So let’s begin… Hello world time!
Getting Started
It’s really easy to get Wordpress to recognize that you have a plugin you want it to play with. You simpy have to put a file with some of the “right” information, into the right folder… So let’s do it. Here it is laid down in step by step instructions.
- Create a php file. Name it something resonable and make sure it ends with .php.
- At the start of that file, insert the following lines of code, modifying it with your details (obviously):
< ?php
/*
Plugin Name: OurVows RSVP
Plugin URI: http://www.ourvows.net
Description: A Private Plugin for RSVPing on our wedding website
Version: .50
Author: Justin Gehring
Author URI: http://www.rinsefirst.com/
*/
- Save and upload the php file to your “wp-content/plugins/” folder
- Open up web browser and load up your wordpress admin panel.
- Goto the “Plugins” section of the Wordpress admin panel. There you should see a line for your newly created plugin that looks like this:
Congratulations! You just created your first Wordpress plugin. It does ABSOLUTELY NOTHING! But hey, at least its in the list of plugin’s right. Next post, we’ll talk about how you actually go about getting it to display information to the page.
5 Late Night Tips for Avoiding CSS Headaches
March 30th, 2008
I just finished writing an email to a friend helping him out with some CSS trouble he was having. I decided that the 5 tips I put at the beginning of the letter is good CSS advice for all of us… And although it might not be perfect… when your learning how to program CSS, it’s probably best to implement some of these things… Cause it can only save you from a headache. So without further adu… the 5 tips:
- Always build for firefox, and then fix IE… Never the other way around. Why? Because Firefox is standards compliant… IE is not (yet). There are fixes for the problems in IE. There are no fixes for the problems in firefox (because it’s all standardized). That said, if it looks bad in firefox, it’s probably because your taking advantage of something broken in IE, and how do you “break” firefox to fix it :-). So that said… code from firefox!
- Make use of Firebug and Webmaster Toolbar (both in firefox), it will allow you to code realtime, which is priceless when it comes to debugging.
- Start your css with the following line:
* {margin: 0px;padding: 0px;}The reason: it basically gives you a leg up on building with the box model because every single object has the same margins and padding to start with (where as, they normally don’t… For example ul’s tend to have a margin of like 15 or something… which can throw everything off.)
- Get in the habit clear “clearing” sections… Namely by using clear: both;. If you treat each section of your webpage as just that… a section… then at the end of every section that has a float, you need to be sure you have something that is clearing everything… otherwise the float from the previous section may have adverse affects on the next section.
- Lastly: when all else fails… clear all the formatting… and start over…. and work your way down… Building CSS on top of existing content is probably the easiest way to do it… and it’s much easier to work top to bottom than it is any other direction when it comes to building layout.
Hope someone found this useful… It’s time for me to write another post…
Thinking outside the box
February 19th, 2008
Over the last few weeks, all the various design/web standards blogs have been talking about this funny new feature of IE that allows the web developer to specify what version of IE they want the site to render in. Of course, it would seem that most of the web community hates this idea for one reason of another… Whether it’s the fact that it’s not standard (and if the all the browsers MS made were following the standards this wouldn’t be needed anyway) or just that they think it’s going to cause more web developers to be lazy and not fix their code for the future, etc.
In fact, my mind is drawing a blank, but I may have already said something about this here on this site (or maybe it was in a comment on another site).
In any case, I have now decided that although I believe there should be some standard behaviors for all browsers to follow, just to keep everyone sane, I am no longer in support of making things follow standards for the sake of following standards. In fact, I don’t think I’ve been this way for awhile.
The truth is this: If microsoft followed the standard, they wouldn’t have some of the cooler things you can do with a website at this point… For example, in IE you can customize the color of the scroll bar. You can cause your page to transition differently from page to page. If I remember correctly, they were even the ones that started all the favicon additions you see in all the modern browsers. The fact of the matter is… these were all features that were outside the HTML standard persay. Things that spurred innovation and outside thought into the web community…
I am now of the thought that if you can break the standard in a “different” useful way, I’m not sure it’s a bad thing. If that means creating a meta tag that allows you to defy what is right, so be it. If that means creating some non-standard CSS, awesome. If you can find a way to do it still inside the standard, even better. But whatever it is MS, keep adding features that the web developer community hates. We may continue to hate you. We may think you are the bane of our existence because of all the crap you make us go through to build a site, but the more I think about it, you have brought some rather interesting things that users love to the table… And even if they didn’t last, someone needs to be thinking outside the box.
Blogging To The Money Part 5 - Installing the Blog
February 5th, 2008
With hosting and a domain name out of the way, I’m now actually moving on to building the blog.
To do this, I am going to be using Wordpress’s free blogging software. It’s the same software that is powering rinsefirst, ourvows, shatteredcube, bananamonkey, and graceified at this point. It’s quick, it’s painless, and best of all, it’s open source.
In most cases, I would have to go the long way, which is to say: I would have to download wordpress from the wordpress site, and then proceed to follow it’s installation instructions to get it all online. The whole process takes about 30 minutes that way. However, I’m a sucker for speed and time savers… So like all good hosts, Westhost, has a 1-click install of wordpress. Simply tell it what you want your username and password to be and Wha-la the default wordpress install is setup.
So depending on when you read this, you can now go see my fresh install of wordpress over at the new domain by clicking here: http://www.websolguy.com/. There isn’t much to look at (unless your reading this post and the site has already been live a month), but hey, odds are your reading it now…
Hey doesn’t it look a lot like Shatteredcube? hmmm….
Blogging To The Money Status:
- Non-Time Cost So Far: $127.03
- .com Domain from www.GoDaddy.com
with promo code Oyh3 to get it for 7.15
- Westhost webhosting for a year (9.99/month for 12 months): $119.88
- .com Domain from www.GoDaddy.com
- Amount Made: $0.00
- Net: -$7.15
Blogging To The Money Part 4 - Hosting
February 4th, 2008
Every good blog needs a host.
There are plenty of options here, each with it’s own upsides and downsides.
For example, I could go with a “hosted” blog solution… You know, something that anyone can sign up for free of charge. Something like Wordpress.com or Blogger.com. In theory this would be fine, except, most of the “free” blog hosting sites are out to monetize your site on their behalf… Thereby, not allowing you to make money. That said, that doesn’t seem like the right solution for me… Instead, I’m going to go the self hosted route, and because I must play by my own spending rules, I will put down the total I paid and not just how much it would cost me for this month (because the fact of the matter is, this is going to be a longer experiment than a month).
In any case, here’s what I did. I went with the hosting company I have been recommending to my clients ever since the previous host I had been recommending went south. Their name: Westhost. You can find them here:
http://affiliates.westhost.com/z/55/CD970/
They are a VPS solution, they can support multiple sites, and they allow me to recompile php to my hearts content. They also have 1-click installs of Wordpress which should save me a little bit of time in getting going with the site… But more on Wordpress later.
In any case, I opened my hosting account, and have my domain from Godaddy successfully pointed at Westhost (oh, if your doing this yourself, Westhost’s 9.99/month package comes with a free domain, so you can skip over the Godaddy step if you would like). Now on to building the site. C’ya All tomorrow!
Blogging To The Money Status:
- Non-Time Cost So Far: $127.03
- .com Domain from www.GoDaddy.com
with promo code Oyh3 to get it for 7.15
- Westhost webhosting for a year (9.99/month for 12 months): $119.88
- .com Domain from www.GoDaddy.com
- Amount Made: $0.00
- Net: -$7.15
Storing IP Addresses In Mysql
February 2nd, 2008
One of the more common pieces of data that I store to databases is IP addresses.
IP’s are something you need store for the security and traceability of certain things to certain people. They are simply a nice sequence of 8 bit integers written out in base 10 form with this funny dot notation. For example, your ip address may look like this: 192.168.0.1. I could go on in massive length as to what these things are, how they are used, etc… But that would defeat the purpose of this post, which is to explain how to store the bloody things in Mysql.
For the longest time I knew there had to be a better way to store them than as a Char(15) or as a VarChar(15) (which is the equivalent of saying, I want to store the decimal text version of the number, and which would take up 15 bytes of data everytime i went to store an IP). I knew this from my networking class back at the U of M… For example, I knew you could represent an IP address as a 32 bit unsigned int. It’s the reason that you can pull up a webpage by going to the integer version of the ip address (like this: http://1089054563/).
What I didn’t know until tonight (when I finally took the time to go look it up) is that Mysql has a way to convert IP addresses (in their dotted notation) to integers (the way that is easy to store). It’s two functions basically:
- INET_ATON(’192.168.1.100′) will store it to an int
- INET_NTOA(3232235530) will undo the store
Pretty simple… For me, this is almost as big as the time I discover how to properly store dates in a database… Yay for saving 11 bytes of data!