给WordPress插件添加设置页面

“将文章从WordPress首页上隐去”的插件的时候,发现一个插件居然没有配置界面,而让用户改php文件,太发指了,不符合我心中WordPress的完美形象。于是对如何写插件,如何给插件添加配置界面产生了兴趣。偷空查看了文档并测试了一下,记录在这里作为技术资料吧。

在WordPress管理后台上给你自己的插件添加配置界面只要三步,很简单:

  1. 写一个函数(func_a),它吐出你的配置界面的表单
  2. 写一个函数(func_b),调用WordPress的add_submenu_page(…….., func_a),吧func_a传给add_submenu_page
    1. 如果你想把自己的配置页面放到后台左导航菜单的一级菜单就调用add_menu_page方法,但这显得太自大了
  3. 在插件php文件中直接调用,add_action(‘admin_menu’, ‘func_b’);这样WordPress会在初始化后台菜单的时候调用你的func_b函数。

好了,代码如下,下一篇文章将如何将配置界面里的配置项保存到WordPress的数据库。

WordPress的文档:http://codex.wordpress.org/Adding_Administration_Menus

BTW:中国那么多人为什么没人去翻译这个文档?

Related posts

One thought on “给WordPress插件添加设置页面

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>