The Ultimate Wordpress Video Blog Theme

How to Create a Simple Wordpress Plugin
Posted on 10 June, 2009 at 19:49 PM There are already 14 Comments

About the Show

In this screencast, Marc runs over his code for a simple "Twitter Directory" plugin for Wordpress, explaining certain details and sharing tips along the way.

The following issues are attended to in this post:

  • Adding an Activation Hook to your plugin.
  • Creating new tables in your Wordpress database using SQL.
  • Running a custom database Query.
  • How to get wp_redirect() to work without throwing the "Cannot modify header information" error.
  • Correct usage of the add_menu() function.

Download the OCMX Twitter List plugin HERE

Useful links related to this post:

User Comments

Rob MacKay's Gravatar

Rob MacKay    10 Jun, 2009 20:05:50 PM

I've been deep in learning PHP all day so this is very well timed :) thanks dude its a great overview I will be watching it a good few times.




Marc Perel's Gravatar

Marc Perel    10 Jun, 2009 20:14:14 PM

@Rob - Thanks dude, glad you found it useful...


Hugh Collier's Gravatar

Hugh Collier    11 Jun, 2009 00:30:32 AM

This is way over my head at the moment (I'm literally just starting out with PHP) but I'm sure it'll come in handy once I get a bit better.

I'm on lesson 3 or 4 of themeforest's dive into PHP video series which I'm finding absolutely brilliant. I'd totally recommend it to any beginners who find this tut a bit advanced/involved. Link is here:

www.multiurl.com/ga/Diving_Into_PHP


Sam's Gravatar

Sam    11 Jun, 2009 00:38:37 AM

Great tutorial! Next step is so you only have to enter the twitter name and it'll look up their actual name for you :-)

One criticism though, I know this is in the admin pages, but you should never do something like "SELECT * FROM table WHERE id=" . $_GET['id'] as you're just opening up your query for a SQL injection attack. Make sure you validate your variables before passing them to SQL (ie. in this case, id must be a number).




Marc Perel's Gravatar

Marc Perel    11 Jun, 2009 00:48:16 AM

@Sam - Very good point mate, thanks for pointing that out.

My bad - *Runs and hides in a corner*


Dave Kirk's Gravatar

Dave Kirk    11 Jun, 2009 02:23:01 AM

Nice tutorial, I have a couple of comments, both relating to specifity,

1 - When declaring you $plugin_prefix, you should specify it is a global variable, otherwise it won't be available in certain situations, ie:

global $plugin_prefix; $plugin_prefix = "ocmx_";

2 - The same also applies to the table name, in your 1st file ocmx-twitter-list.php you should declare it as global, then in the setup file, you can simply reference the that variable, rather than re-declare the variable

global $wpdb; global $twitter_table; $twitter_table = $wpdb->prefix . 'table_name';

This will mean that both your variables will always be available, otherwise they may not be available to you during activation, etc


Dave Kirk's Gravatar

Dave Kirk    11 Jun, 2009 02:26:20 AM

With reference to my previous comment, see Register Activation Hook Documentation and read the section on Variable Scope


Marc Perel's Gravatar

Marc Perel    11 Jun, 2009 10:41:54 AM

@Dave is 100% about setting global variables for easier access, thanks Dave.


Adam's Gravatar

Adam    11 Jun, 2009 15:08:03 PM

Great tutorial Marc!

Definitely makes the learning curve much easier.


a_k _iirlerim's Gravatar

a_k _iirlerim    25 Jun, 2009 03:23:05 AM

thanks video post.. (:


Ask siiirleri's Gravatar

Ask siiirleri    11 Jul, 2009 00:40:07 AM

thank admin very nice


Radyo Dinle's Gravatar

Radyo Dinle    17 Jul, 2009 00:56:55 AM

thanks


ask sozleri's Gravatar

ask sozleri    30 Jul, 2009 00:18:42 AM

thanks