查看文章
 
Dissect WordPress Plugin 2
2008-01-12 14:10

5)如果插件中涉及UI

其实是一样的。以WordPress FeedBurner Plugin中添加菜单为例:

如果想添加一个菜单,就需要注册“admin_menu”这个Action Tag(系统事件):

  1. <?php add_action('admin_menu', 'ol_add_feedburner_options_page'); ?>

即可,插件中的这个函数为:

  1. <?php function ol_add_feedburner_options_page() {
  2. if (function_exists('add_options_page')) {
  3. add_options_page('FeedBurner', 'FeedBurner', 8, basename(__FILE__), 'ol_feedburner_options_subpanel');
  4. }<br>}
  5. ?>

“add_options_page”这个函数就会在系统的“Options”菜单中添加“FeedBurner”这样一个子菜单。

而这个函数其实就是增加 Menu 或者 SubMenu,

  1. <?php
  2. function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') {
  3. global $submenu;
  4. global $menu;
  5. $parent = plugin_basename($parent);
  6. $file = plugin_basename($file);
  7. // If the parent doesn't already have a submenu, add a link to the parent
  8. // as the first item in the submenu. If the submenu file is the same as the
  9. // parent file someone is trying to link back to the parent manually. In
  10. // this case, don't automatically add a link back to avoid duplication.
  11. if (! isset($submenu[$parent]) && $file != $parent) {
  12. foreach ($menu as $parent_menu) {
  13. if ($parent_menu[2] == $parent) {
  14. $submenu[$parent][] = $parent_menu;
  15. }
  16. }
  17. }
  18. $submenu[$parent][] = array($menu_title, $access_level, $file, $page_title);
  19. $hookname = get_plugin_page_hookname($file, $parent);
  20. if ( !empty($function) && !empty($hookname) )
  21. add_action($hookname, $function);
  22. return $hookname;
  23. }
  24. function add_options_page($page_title, $menu_title, $access_level, $file, $function = '') {
  25. return add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file, $function);
  26. }
  27. ?>

6)其它

还有一些简单的插件就是只提供一些API函数。比如Most_Commented Plugin,它提供一个API “mdv_most_commented”:通过数据库查询得到评论最多的文章,并加以显示。因为这个插件已经被Include过,所以可以用这个API来进行显示


类别:Php||添加到搜藏 |分享到i贴吧|浏览(373)|评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
     

   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu