WordPress plugin development using OOP

ε祈祈猫儿з 提交于 2019-12-03 01:57:56
kovshenin

I'm not a 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. I hope to see more soon and hurray for OOP in WordPress! It's a good thing that people ask such questions, it is what motivates the core developers :)

I often download plugins to look at the code hoping I’ll learn something from the developers methods and coding style. Often I find myself frustrated reading through poorly written plugins. It’s not that they’re bad developers, they just haven’t focused enough on alternative coding styles and refining how they go about programming their plugins. Here’s a quick step-by-step on how I write my WordPress Plugins hoping to influence other developers.

Steps on how to getting started with plugin developement

Step 1 – Create your file and let it be known as a plugin

Step 2 – Create the objects of your plugin

Step 3 – Adding your actions and filters

Step 4 – Adding settings/options to your plugin

Finish up your code

Reference: Writing a WordPress Plugin Using Classes

gulbrandr

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!