wordpress插件开发

在线文档:

http://codex.wordpress.org/zh-cn:%E5%87%BD%E6%95%B0%E5%8F%82%E8%80%83

http://phpdoc.wordpress.org/trunk/

开发插件 http://codex.wordpress.org/zh-cn:%E5%BC%80%E5%8F%91%E4%B8%80%E4%B8%AA%E6%8F%92%E4%BB%B6

怎样在admin中添加菜单 http://codex.wordpress.org/Adding_Administration_Menus

 

admin管理中添加脚本和样式表资源:http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts

plugins_url的调用需要注意场合,应该在hook方法中调用,否则得不到值。

遇到的headers already sent问题:

插件在本地运行的好好的,发送到网站上启用后报:这个插件在启用的过程中产生了xx 个字符的异常输出。插件是可以运行的,但是退出admin时就一大堆headers already sent(xxxx 第xx行),连xmlrpc也不能用了。删除插件就没这个问题。

我在网上查,发现php utf-8 bom这个问题。

php utf-8的 BOM 问题解决  http://blog.csdn.net/ok7758521ok/article/details/1756052

我就以为是这个问题,但是用unicode 16进制查看却没有发现bom头。

后来才发现eclipse utf-8格式本身就是不带bom头的。 http://stackoverflow.com/questions/2905582/working-with-utf-8-files-in-eclipse

Both bug 78455 ("Provide an option to force writing a BOM to UTF-8 files") and bug 136854 don't leave much hope for such an option.

The support for encoding in the workspace is based on what is available from Java.
For any given resource in the workspace, it is possible to obtain a charset string that can be used with any Java APIs that take charset strings.
Examples are:

  • 'US-ASCII',
  • 'UTF-8',
  • 'Cp1252',
  • 'UTF-16' (Big Endian, BOM inserted automatically),
  • 'UTF-16BE' (Big Endian, BOM not inserted automatically),
  • 'UTF-16LE' (Little Endian, BOM not inserted automatically).

For Java encodings, except for the 'UTF-16' encoding, BOMs are not inserted (when writing) or discarded (when reading) for free.
Even if this is puzzling to end users, this is how all Java applications work.
If applications want to support creating UTF-8 files with BOMs to match their users' expectations, they need to provide such capability on their own (as neither Java nor the Resources model will help with that).
Eclipse does provide some improvements towards detecting BOMs, but not with generating or skipping them.

真是冤大头,我还用notepad++的格式/转为utf-8 wihout BOM转换了一下,确实不是这个原因。

最后发现那个报错已经说明了是哪一行,那一行是个php code之外的空白,把空白删除了就可以了!

再查查wordpress plugin资料,原来插件主文件代码里是要注意空白的。如果在展示上有空白,建议写在另外的php文件中在require进来。

http://codex.wordpress.org/WordPress_Coding_Standards

Remove Trailing Spaces

Important: Make sure you remove trailing whitespace after closing PHP tags.

Also remove trailing spaces at the end of each line of code.

 

在wp-setting.php中32 行设置默认时区 date_default_timezone_set( 'PRC' );


Total views.

© 2013 - 2024. All rights reserved.

Powered by Hydejack v6.6.1