使用OOP开发WordPress插件 [英] WordPress plugin development using OOP

查看:96
本文介绍了使用OOP开发WordPress插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是插件开发的新手.因此,无论我在哪里出错,都请纠正我.

I am new to plugin development. So please correct me, wherever I get it wrong.

我有一个网站,该网站需要具有以下需求的播放器插件:-

I have a website which needs a players plugin with the following needs:-

  • 管理员可控制的球员注册表格,其中包含一些详细信息.
  • 将显示所有已注册玩家的列表页面.
  • 已注册的玩家可以删除&彼此比较.
  • 在前端的WordPress主题中显示一些注册玩家(10个随机玩家).

我已经完成了插件的激活,以及该插件的数据库表创建和管理员菜单选项.我还完成了播放器注册界面,但是没有数据库插入代码. 但是所有这些操作都是使用常规的程序方式完成的.

I have completed the activation of the plugin, along with database table creation and administrator 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 now have two headaches in completing the development of this plugin:-

  • 以OOP格式开发此插件,以支持WordPress的未来版本.
  • 完成此插件的其他要求.

如何进行以下操作(即使有一点知识共享)?

How to proceed with the following (even with a little knowledge sharing)?

  • 使用OOP方式从头开始创建WordPress插件.
  • 使用OOP调用网络表单(例如,用于注册玩家).
  • 使用OOP将所有这些玩家信息提交到数据库中.
  • 使用OOP显示列表页面(例如,针对注册玩家并定位他们).
  • 使用模板标签或直接在插件的帮助下,在WordPress主题的前端显示一些玩家.

我已经搜索过Google,试图在Internet上找到一些有关这些的信息,但是在OOP方面我并没有取得多少成功.

I have searched Google, tried to find some information in the Internet about these, but I haven't succeeded much with the OOP thing.

- 对于我们所有人(WordPress OOP插件开发的新成员)来说,有一些突出显示其用法的代码片段将对我们所有人都非常有帮助和高兴.如果可能,您还可以提供一些文章链接,这些链接将正确描述如何编写此类OOP插件.

- It will be very helpful and nice for all of us (new to WordPress OOP plugin development) to have some code snippet highlighting its use. If possible, you can also provide some article links which will properly describe how to write such OOP plugins.

诸如" gulbrandr "所提供的文章很有帮助,我也要感谢" kovshenin "分享/提及某些OOP插件的链接;但是如果能够提供更多文章或任何代码片段来描述开发OOP插件的正确步骤,那将是非常棒的.

Articles, like what "gulbrandr" provided, was helpful, and I also would like to thank "kovshenin" for sharing / mentioning links of some OOP plugins; but it will be very great if some more articles or any code snippet can be provided, describing the proper steps of developing the OOP plugins.

推荐答案

我不是专家,但是我已经使用WordPress已有几年了,并且背后有很多插件.我可以指出的第一个错误是

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

这是错误的.使用WordPress时,您无需创建表,默认架构足够灵活,可以满足您的所有需求.甚至甚至复杂的插件(例如 WP-eCommerce )都已被改写(或者已经不改写了)知道)以适合标准WordPress模式.特别是由于WordPress 3.0已经发布.今年早些时候,在 WordCamp 上已经提到了这一点.

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.

现在,如果您真的很喜欢OOP,则应该在那里下载一些很棒的插件,并通读代码以了解其他人是如何做到的.例如,我可以提到我自己的一个插件,称为 Twitter友好链接-这不是最好的OOP,但这绝对是一个开始;)

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 ;)

之后,您可以将其移至 W3总缓存,在这里您会看到一些非常令人印象深刻的东西和代码组织(感谢 Frederick Townes ).

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).

此外,食典的某些部分现在以OOP样式显示示例-例如Widget API.我希望很快能看到更多,并为WordPress中的OOP欢呼!人们问这样的问题是一件好事,这是促使核心开发人员发展的动力:)

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 :)

这篇关于使用OOP开发WordPress插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆