5)如果插件中涉及UI
其实是一样的。以WordPress FeedBurner Plugin中添加菜单为例:
如果想添加一个菜单,就需要注册“admin_menu”这个Action Tag(系统事件):
- <?php add_action('admin_menu', 'ol_add_feedburner_options_page'); ?>
即可,插件中的这个函数为:
- <?php function ol_add_feedburner_options_page() {
- if (function_exists('add_options_page')) {
- add_options_page('FeedBurner', 'FeedBurner', 8, basename(__FILE__), 'ol_feedburner_options_subpanel');
- }<br>}
- ?>
“add_options_page”这个函数就会在系统的“Options”菜单中添加“FeedBurner”这样一个子菜单。
而这个函数其实就是增加 Menu 或者 SubMenu,
- <?php
- function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') {
- global $submenu;
- global $menu;
-
- $parent = plugin_basename($parent);
- $file = plugin_basename($file);
-
- // If the parent doesn't already have a submenu, add a link to the parent
- // as the first item in the submenu. If the submenu file is the same as the
- // parent file someone is trying to link back to the parent manually. In
- // this case, don't automatically add a link back to avoid duplication.
- if (! isset($submenu[$parent]) && $file != $parent) {
- foreach ($menu as $parent_menu) {
- if ($parent_menu[2] == $parent) {
- $submenu[$parent][] = $parent_menu;
- }
- }
- }
-
- $submenu[$parent][] = array($menu_title, $access_level, $file, $page_title);
-
- $hookname = get_plugin_page_hookname($file, $parent);
- if ( !empty($function) && !empty($hookname) )
- add_action($hookname, $function);
-
- return $hookname;
- }
-
- function add_options_page($page_title, $menu_title, $access_level, $file, $function = '') {
- return add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file, $function);
- }
- ?>
6)其它
还有一些简单的插件就是只提供一些API函数。比如Most_Commented Plugin,它提供一个API “mdv_most_commented”:通过数据库查询得到评论最多的文章,并加以显示。因为这个插件已经被Include过,所以可以用这个API来进行显示。