views:

72

answers:

3

I am a newbie in Plugin Development. So please correct me, wherever I get wrong.

I have a website which needs a Players Plugin with the following needs:-

  • An Admin controllable form for Player registration, with some details of them.
  • A listing page where all the registered players are to be shown.
  • Registered Players can be deleted & compared with each other.
  • Showing some Registered Players (10 random players) in the WordPress theme in the front-end.

I have completed the activation of Plugin, along with database table creation & admin menu options for this Plugin. I have also completed the Player Registration Interface, but without the database insertion code. But all of these have been done using normal procedural way.

I have now two headaches in completing the development of this Plugin:-

  • Develop this Plugin in the OOP format, for support to future versions of WordPress.
  • Complete the other requirements of this Plugin.

Can anybody please help me out (even with a little knowledge sharing) in how to proceed with the following:-

  • Creating WordPress Plugin from scratch using OOP way.
  • Calling a web form (like, for Player registration) using OOP.
  • Submitting all these player information into the Database using OOP.
  • Showing a listing page (like, for registered players & positioning them) using OOP.
  • Showing some players in the front-end of the WordPress theme, using either Template Tags or directly with the help of the Plugin.

I have searched the Google, tried to find some information in the Internet about these, but haven't succeeded much with the OOP thing. Please anybody, with any minimal knowledge, help me out.

Thanks in advance.

A: 

I found a recent post (August 2010) about how to write an Object Oriented WordPress Plugin: http://w3prodigy.com/behind-wordpress/object-oriented-wordpress-plugin/

Hope this help.

gulbrandr
+1  A: 

Hey there. I'm not the Guru but I've been working with WordPress for several years now and have quite a few plugins behind my back. Your first mistake I can point out is

along with database table creation

This is wrong. You don't create tables when you work with WordPress, the default schema is flexible enough to fit anything you have in mind. Even complicated plugins such as WP-eCommerce is being rewritten (or already, don't know) to fit the standard WordPress schema. Especially since WordPress 3.0 is already out. This has been mentioned on WordCamp earlier this year.

You can easily fit your players into the Users table. Their attributes could be stored in the Users Meta table, plus you could give them special roles and/or privileges.

Now, if you're really into OOP, you should download some cool plugins out there and read through the code to see how other people do it. As an example I could mention one of my own plugins called Twitter Friendly Links - it's not the best OOP around, but it's definitely a start ;)

You can kick it over to W3 Total Cache afterwards, where you'll see some very impressive stuff and code organization (thanks to Frederick Townes)

Also, some parts of the Codex now show examples in OOP style - the Widget API for instance. Hope to see more soon and hurray for OOP in WordPress! It's a good thing that people ask such questions, it what motivates the core developers :)

Cheers ~

kovshenin
Knowledge Craving
+1  A: 

Try to use WP's builtin custom post types and custom fields/taxonomies API. If it is not enough for your task - you can try to add some ORM like, say, Doctrine for backend. Also recently, I have developed a simple framework that provides some core functionality to add MVC approach to WP (basic request routing, html generation api, and "model" based on the wordpress' posts and custom fields). It is not perfect - but I can share the code and may be it will help you.

jetdog
Knowledge Craving
What I am offering is WP API extension we developed to support our everyday development :) If you're looking for a good way to structure your plugin code - pay attention to gulbrandr's answer. The article he referenced is really great and describes a really good "one class per function" approach which keeps your code clean.
jetdog