WordPress 3.0

【2010-06-21】今天,我已经升级到了3.0了。over
———————————————————-
上次是RC,这次是RC2,看来正式版离我们很近了。
事实上我也明白,如果不想多用户版,2.9已经够用了。wp为了让插件更容易开发,忽略的是性能,因此,在不装插件的情况下,WP的性能其实也还是可以接受的。只是插件多了,每次都要add_actin,add_xxxxx,就慢上很多。虽然插件都有缓存,但IO的消耗不会少呀?
看原新闻怎么说吧,RC2只更新了一条:
Changes:
This release contains many bugfixes and improvements since Release Candidate 1. There have been improvements in the nav menus, multisite, the TwentyTen theme, and the upgrade functions, to name a few. There is also new contextual help available.
感觉好象没什么太大的意义,看来,稳定多了。stable版本即将出现了

WordPress : Adding Administration Menus

If you want to give your pluging an options page,you must set a administration menu or options sub menu. Some manual can find it on wordpress.org.
OK,to add an administration menu, you must do three things:

1. Create a function that contains the menu-building code
2. Register the above function using the “admin_menu” action hook
3. Create the HTML output for the page (screen) displayed when the menu item is clicked

It is that second step that is often overlooked by new developers. You cannot simply call the menu code described; you must put it inside a function, and then register the function.

Here is a very simple example of the three steps just described. This plugin will add a sub-level menu item under the Settings top-level menu, and when selected, that menu item will cause a very basic screen to display. Note: this code should be added to a main plugin PHP file or a separate PHP include file.

< ?php
add_action('admin_menu', 'my_plugin_menu');

function my_plugin_menu() {
  add_options_page('My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options');
}

function my_plugin_options() {
  if (!current_user_can('manage_options'))  {
    wp_die( __('You do not have sufficient permissions to access this page.') );
  }
  echo '< div class="wrap" >';
  echo '< p >Here is where the form would go if I actually had options.< / p >';
  echo '< / div >';
}
?>

Now,you looked this example, the function, my_plugin_menu(), adds a new item to the Administration menu via the add_options_page function. Note: more complicated multiple menu items can be added, but that will be described later. Notice the add_action line–that invokes the hook which “registers” the function, my_plugin_menu(). Without that add_action, a PHP error for “undefined function” will be thrown when attempting to activate the plugin. Finely, the add_options_page code refers to the my_plugin_options() function which contains the actual page to be displayed (and PHP code to be processed) when someone clicks the menu item.

The actual detail of these processes is described in more detail in the sections below. Remember to enclose creation of the menu and the html page in functions, and invoke the admin_menu hook to get the whole process started!
—//some code and english manual copy from http://codex.wordpress.org/Adding_Administration_Menus—
if you want to set an administration menu,you can see it..

wordpress开发的几个事项

1、自定义字段,详见 http://codex.wordpress.org/Using_Custom_Fields ,几个常见的方法有:
add_post_meta($id,$key,$value,$unique),update_post_meta,delete_post_meta
get_post_meta,get_post_meta_keys,get_post_meta_values
用于模版中的有,the_meta,get_post_meta

2、图片存在哪里?图片其实也是一条post数据,只是 post_type = attachment而己
其它post_type有,draft(草稿),revision(历史数据)等。
当图片的post_parent没有值时,认为它是孤立附件。如果有值是认为是有关联的,仅关联第一次,如果有多个文章插入此图片,默认只关联第一次的。

3、wp_links是友情链接表
wp_comments是回复表
wp_commentmeta和postmeta类似,但一般都用不到。
wp_options是系统配置表,可以用get_options等获取。
wp_terms等三个表是关联表,wp_terms里面存放了category,tag等信息
wp_users等两个表是用户相关表。由于usermeta信息是key,value对应的,所以当要取所有的用户及全部配置信息时就很郁闷。如果用户不多,建议是把wp_usermeta全部取出来之后,再用foreach等做键值对应,否则,SQL查询就会死人。

WordPress的插件开发全攻略(目录)

这篇文章是我转自sexywp.com的文章,有PDF版的下载哦,不过仔细看了之后,还是觉得比较简单,当然如果是初学的话,了解一下也足够了。

  1. How to Write a WordPress Plugin – Introduction
  2. 介绍
  3. Seven Reasons to Write a WordPress Plugin
  4. 编写插件的七个理 由
  5. How to Get Ideas for WordPress Plugins
  6. 怎样获得 WordPress插件的创意
  7. Structure of a WordPress Plugin
  8. WordPress 插件的结构
  9. WordPress Plugin Actions
  10. WordPress 插件Actions
  11. WordPress Plugin Filters
  12. WordPress 插件Filter
  13. Constructing a WordPress Plugin Admin Panel
  14. 构造一个 WordPress插件管理员面板
  15. Constructing a WordPress Plugin User’s Panel
  16. 构建一个 WordPress插件用户面板
  17. WordPress Plugins and Database Interaction
  18. WordPress 插件和数据库交互
  19. Using JavaScript and CSS with your WordPress Plugin
  20. 在你的 WordPress插件中使用Javascript和CSS
  21. Using AJAX with your WordPress Plugin
  22. 在你的WP插件中 使用AJAX
  23. Releasing and Promoting Your WordPress Plugin
  24. 发布并推广你的 WordPress插件

作者:Charles 原文链接:插件开发全攻略(目 录)

测试最简单的插件

尝试使用wordpress的时候,看了一下插件的简要信息,说白了,就是一个add_filter在调用相关信息。于是参照hello_dolly插件写了一个最简单的插件,也就是在文章内容后面加上一个版权信息。好象除了默认的模版外,其他就没有这样的提示了。所以,我就开始这样的尝试。

/**
 * @package NeatCN Copyright
 * @author neatcn / gouki
 * @version 0.1
 */
/*
Plugin Name: NeatCN WordPress Copyright
Plugin URI: http://neatcn.com/#
Description: 显示文章的版权信息
Author: NeatCN / gouki
Version: 0.1
Author URI: http://neatcn.com/
*/
function neatCopyRight ( $content )
{
	$content .= < <

于是在文章内容结束后就有了这一行信息。当然上面仅仅是测试,我不会满足这点的。于是我对neatCopyRight进行了改进,插件也就变成了0.2版了。

/*
  说明,the_time,the_category这些函数在文章里居然没有输出值,所以还需要研究一下
  0.2是个失败的作品,晚上回家继续研究
 */
function neatCopyRight ( $content )
{
	$postTime = the_time('l, F jS, Y') . the_time();
	$currentCate = the_category(', ');
	$rssLink = post_comments_feed_link('RSS 2.0');
	$content .= < <

本文发表于 $postTime , 隶属于 $currentCate 分类,你可以订阅本文的评论:$rssLink 

EOT;
	echo( $content );
}

第一个插件,连配置啥的都没有。只能算是一个尝试,尝试了一下add_filter函数而己

如何关闭WordPress修订功能

WordPress其实挺不错,但是Revision却不是特别方便,因为每一次的版本保存,都会增加一条主键记录。所以,你会发现,我的网站的文章,第一条是show-1-1.shtml,第二条却是show-11-1.shtml,中间10条却是Reversion所导致的。
由此可见,这样的频繁添加记录对于数据库来说是一个不小的压力,但对于普通用户来说,这个功能却真的并不是那样重要,但所幸,还是有办法 可以解决这个问题。
只要你打开wp-config.php文件,在文件的最后require(‘wp-setting.php’)前加入:

/**
 * 当值为-1或者true时,代表保存所有的Revision
 * 当值为false或者0时,代表关闭Revision
 * 当值大于0,并且是数字是,代表保留n次Revision
 */
define('WP_POST_REVISIONS',false);

具体说明请查看官方的说明文档“Revision Management”。

不过,如果你已经有了Revision的控制,但却想删除它,怎么办?除了直接执行sql外,还有就是安装这个WP Cleaner插件,我这里就不多做介绍了,我用下来,感觉不错很方便。