<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Becomin&#039; Charles &#187; Plugins Develop</title>
	<atom:link href="http://sexywp.com/cata/wp/wp-plugins-dev/feed" rel="self" type="application/rss+xml" />
	<link>http://sexywp.com</link>
	<description>Building another myself~~</description>
	<lastBuildDate>Fri, 27 Jan 2012 16:00:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>［插件开发］获知文章状态变化</title>
		<link>http://sexywp.com/get-updated-when-post-status-changed.htm</link>
		<comments>http://sexywp.com/get-updated-when-post-status-changed.htm#comments</comments>
		<pubDate>Fri, 31 Dec 2010 18:23:47 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=413</guid>
		<description><![CDATA[文章（post）是 WordPress 博客的核心价值所在，围绕一篇文章的增、删、改，我们可以开发很多有用的插件。近来，由于维护一款插件的需要，我碰巧研究了一下围绕文章发布流程而设立的一些钩子（hook）。微有所得，记录备查。

事情的起因是插件中的一个函数hook到了一个action上，名字是publish_post，顾名思义，在文章发布时候被激发的。为了要更清楚地掌控这个action，我想在源代码中，把触发点给找出来，这一找，问题来了。理论上，我们hook任何action，WP内部都会有对应的do_action来激发这个钩子，这一次，一搜，根本没有publish_post，那就有点小麻烦，说明具体激发哪个钩子，是运行时决定的，再明白点说吧，这个action的名字，应该使用变量拼出来的，所以我们直接搜publish_post很难找到调用点。

<span class="readmore"><a href="http://sexywp.com/get-updated-when-post-status-changed.htm" title="［插件开发］获知文章状态变化">Keep Reading --- 934 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>文章（post）是 <a href="http://sexywp.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 WordPress 下的日志">WordPress</a> 博客的核心价值所在，围绕一篇文章的增、删、改，我们可以开发很多有用的插件。近来，由于维护一款插件的需要，我碰巧研究了一下围绕文章发布流程而设立的一些钩子（hook）。微有所得，记录备查。<span id="more-413"></span></p>
<p>事情的起因是插件中的一个函数hook到了一个action上，名字是publish_post，顾名思义，在文章发布时候被激发的。为了要更清楚地掌控这个action，我想在源代码中，把触发点给找出来，这一找，问题来了。理论上，我们hook任何action，WP内部都会有对应的do_action来激发这个钩子，这一次，一搜，根本没有publish_post，那就有点小麻烦，说明具体激发哪个钩子，是运行时决定的，再明白点说吧，这个action的名字，应该使用变量拼出来的，所以我们直接搜publish_post很难找到调用点。</p>
<p>具体寻找的过程，我也不想赘述了，无非是查文档，搜代码。这里想要一提的是，我发现一个新的小技巧，给技巧取个名字叫“农村包围城市”，因为一下无法定位到想要找的代码，那么能准确定位其周边代码也是可以的，至少可以缩小查找范围。从文档中我们看到，在publish_post被激发的点附近，应该还有save_post，那么搜一下save_post，乖乖，准确找到了，然后就看到还有wp_insert_post，pre_post_update等等。然后，马上写一个小插件，向4个感兴趣的点hook，然后随便发布一下文章，根据打出的log，基本确定了publish_post就在pre_post_update和save_post中间激发。这时候就剩下80行左右的范围了，那一行行找还是很快的。</p>
<p>最终结果还是比较有意思的，有个函数叫<strong>wp_transition_post_status</strong>，这里面提供了3个hook，也可以说n个吧，因为这里面就看到了那个运行时才决定的hook名称的代码。最后不但搞清楚了publish_post的激发原理，还发现了原来可以随意通过hook监测每篇文章的状态变化。虽然短期内看不出来有啥用，但是以后一定可以想出来一些应用的。</p>
<ul>
<li><strong>transition_post_status</strong> 当一篇文章或者页面状态变化时触发，三个参数，分别是原状态，现在状态，文章对象本身</li>
<li><strong>状态_to_状态</strong> 某个具体的状态流转时候触发，可以是draft_to_pending，private_to_publish等等，只要是合法的status取值，可以随意组合。一个参数是文章对象本身。</li>
<li><strong>状态_类型</strong> 一个状态+一个类型，可以知道publish_post这个钩子，本质上就是这种，真实含义是有一篇类型是post（还可以是page）的文章，状态变成了publish，而不是已开始我理解成的发布一篇文章时候激发。说起来差别不大，但是你对其的理解已经完全变掉了。以此类推，你可以hook到private_post，还可以是draft_page等等。随意组合。</li>
</ul>
<p>通过上述非常灵活的3种钩子，我们就可以随时掌控任何文章的状态变化了。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fget-updated-when-post-status-changed.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/action" title="action" rel="tag">action</a>, <a href="http://sexywp.com/tags/development" title="development" rel="tag">development</a>, <a href="http://sexywp.com/tags/hooks" title="hooks" rel="tag">hooks</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/get-updated-when-post-status-changed.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>在插件管理页面给你的插件添加“设置”链接</title>
		<link>http://sexywp.com/add-settings-link-to-ur-plugin.htm</link>
		<comments>http://sexywp.com/add-settings-link-to-ur-plugin.htm#comments</comments>
		<pubDate>Mon, 27 Sep 2010 13:53:31 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[code examples]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=383</guid>
		<description><![CDATA[在插件管理页面，每个插件下面有2-3个Action link，包含了用户可以对该插件进行的几种操作。在插件为禁用状态时，可用的操作有：Activate（启用），Edit（编辑），Delete（删除）；在插件为已经启用的状态下，默认有两个可用的操作：Deactivate（禁用）和Edit（编辑）。如果我们在这个列表里仔细观察，就会发现，有些插件会多出一个Settings（设置）操作。本文记录了，为插件添加Settings link的方法。没有什么过多的描述，直接放代码了。在插件主要文件中（包含了插件信息注释语句的那个文件），使用下面的代码，就可以为这个插件添加一个Settings link了。

<span class="readmore"><a href="http://sexywp.com/add-settings-link-to-ur-plugin.htm" title="在插件管理页面给你的插件添加“设置”链接">Keep Reading --- 264 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（12）---发布并推广你的WordPress插件" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-12.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（12）---发布并推广你的WordPress插件</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>在插件管理页面，每个插件下面有2-3个Action link，包含了用户可以对该插件进行的几种操作。在插件为禁用状态时，可用的操作有：Activate（启用），Edit（编辑），Delete（删除）；在插件为已经启用的状态下，默认有两个可用的操作：Deactivate（禁用）和Edit（编辑）。如果我们在这个列表里仔细观察，就会发现，有些插件会多出一个Settings（设置）操作。本文记录了，为插件添加Settings link的方法。没有什么过多的描述，直接放代码了。在插件主要文件中（包含了插件信息注释语句的那个文件），使用下面的代码，就可以为这个插件添加一个Settings link了。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">fmp_add_setting_link</span><span style="color: Olive;">(</span><span style="color: Gray;"> </span><span style="color: #00008b;">$links</span><span style="color: Gray;"> </span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$links</span><span style="color: Olive;">[</span><span style="color: Olive;">]</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">'</span><span style="color: Red;">&lt;a href=&quot;#&quot;&gt;Settings&lt;/a&gt;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">怎样构造这个link呢？大家可以自己想想</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$links</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">is_admin</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">add_filter</span><span style="color: Olive;">(</span><span style="color: Gray;">&nbsp;</span><span style="color: #8b0000;">'</span><span style="color: Red;">plugin_action_links_</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> . </span><span style="color: Blue;">plugin_basename</span><span style="color: Olive;">(</span><span style="color: Gray;"> </span><span style="color: Green;">__FILE__</span><span style="color: Gray;"> </span><span style="color: Olive;">)</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">fmp_add_setting_link</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> </span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（12）---发布并推广你的WordPress插件" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-12.htm&from=http%3A%2F%2Fsexywp.com%2Fadd-settings-link-to-ur-plugin.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（12）---发布并推广你的WordPress插件</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/code-examples" title="code examples" rel="tag">code examples</a>, <a href="http://sexywp.com/tags/development" title="development" rel="tag">development</a>, <a href="http://sexywp.com/tags/diy" title="DIY" rel="tag">DIY</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/add-settings-link-to-ur-plugin.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[插件开发]：检测WP插件的运行环境</title>
		<link>http://sexywp.com/check-the-runtime-evn-of-wp-plugins.htm</link>
		<comments>http://sexywp.com/check-the-runtime-evn-of-wp-plugins.htm#comments</comments>
		<pubDate>Tue, 16 Feb 2010 01:31:36 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=362</guid>
		<description><![CDATA[WP的插件在开发完成后，会在用户的服务器上运行，而用户的服务器环境基本上可以用千奇百怪来形容。开发过程中，在本地运行得好好的插件的，一旦安装到用户的服务器上，也有可能变得无法运行。

所以，作为WP插件的开发者，最好不要对插件最终的运行环境做任何假设。而且，最好能够在插件被启用的时候，进行必要的检查，给用户以提示，对于自己没法兼容的问题，应该明确指出，避免用户遭遇不必要的麻烦。

在我个人的WP插件开发过程中，我主要遇到的问题，基本上都是PHP相关的问题。

<span class="readmore"><a href="http://sexywp.com/check-the-runtime-evn-of-wp-plugins.htm" title="[插件开发]：检测WP插件的运行环境">Keep Reading --- 1392 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（06）---WordPress插件Filter" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-06.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（06）---WordPress插件Filter</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>WP的插件在开发完成后，会在用户的服务器上运行，而用户的服务器环境基本上可以用千奇百怪来形容。开发过程中，在本地运行得好好的插件的，一旦安装到用户的服务器上，也有可能变得无法运行。</p>
<p>所以，作为WP插件的开发者，最好不要对插件最终的运行环境做任何假设。而且，最好能够在插件被启用的时候，进行必要的检查，给用户以提示，对于自己没法兼容的问题，应该明确指出，避免用户遭遇不必要的麻烦。</p>
<p>在我个人的WP插件开发过程中，我主要遇到的问题，基本上都是PHP相关的问题。<span id="more-362"></span></p>
<p>第一个是PHP的版本问题，现在主流的PHP版本是PHP 5.x，而事实上，PHP 4.x仍旧大行其道，如果插件中用到了PHP 5的特性，那么就要想到，插件可能出现兼容问题。比如PHP 5和PHP 4在面向对象方面有一些不同，应用了新特性的插件，在旧有环境下，可能无法正常工作。</p>
<p>我自己遇到的一个例子是DOM Document函数扩展，在PHP 4 和PHP 5中，差别很大，没法兼容，对于这种情况，我也没有很好的办法，只能为两种版本各创建一个函数的版本。做这样的事情非常吃力，乃至我后来已经决定不再开发支持PHP 4版本的插件，只是在插件的说明中写明，未进行过基于PHP 4环境的测试工作，请用户慎重，可能无法运行。这也是一种权衡利弊，有的时候，你的时间精力都有限，可能不愿意做这种吃力不讨好的事情，那也是无可厚非的，但是最好说明这一点。</p>
<p>另一个问题是，个别函数的问题的。比如我遇到一个是mb_str*系列函数的问题，这个系列函数，对于中国用户来说，可能意义特别重大，因为这个系列函数可以正确处理亚洲字符和兼容UTF8字符集。而事实上mbstring这个扩展，并非是每个服务器环境都会配备的，如果调用到了系列的函数，必须要进行检测，好在有好多此系列的函数，可以通过自己实现来弥补。</p>
<p>一般来说，对于有可能不存在的函数，都可以通过自己实现来解决，但是这其中也有一些小陷阱，在解决这种类似的兼容问题后，最好进行全面的测试。举个例子，如果运行时php环境没有包含mbstring扩展，那么当需要调用mb_strlen函数的时候，很简单，可以用自己实现的版本；可是另一些情况就不行，我这里想举个例子，就是scandir函数，这个函数是PHP的内置函数，但是在很多服务器环境中，出于安全的考虑，可能会被禁用，常见的被禁函数有（passthru, exec, phpinfo, system, ini_alter, readlink, symlink, leak, proc_open, popepassthru, chroot, scandir, chgrp, chown, escapeshellcmd, escapeshellarg, shell_exec, proc_get_status），如果插件中用到了，最好认真针对其进行测试。我在处理scandir函数的时候，也用了自己实现函数的法子来解决，谁知道，一测试才发现了不对劲，看看这个提示：</p>
<p>Fatal error: Cannot redeclare scandir() in E:\Green_Software\xampp\htdocs\demos\index.php  on line 24</p>
<p>这是我遇到的错误提示。后来写了一小段代码进行了测试，才发现这个问题，scandir是内置函数，在php.ini中，通过disable_functions选项将scandir屏蔽掉后，function_exists('scandir')函数将返回false值，然而，这个函数的状态却是declared。也就是说，这个函数明明“声明”了，却并不“存在”，那么一般套用的先判断函数是否存在，再决定是否实现自己版本的做法，就失灵了，会引发上述错误。这个问题让我相当头痛，在我看来，想要完美地解决，几乎是不可能。我用了一个非常笨拙的方法，就是对这一类可能会被禁止的函数进行封装。然后在实际调用的时候，调用自己重命名过的函数版本。</p>
<p>综上可以知道，就算同样是function_exists返回false情况，用同一种方法，也不能一并解决所有问题。最好的办法，还是用不同的办法综合起来解决问题，并且进行尽可能全面的测试工作，最后对插件可能引发的问题进行详细的说明。</p>
<p>在具体开发过程中，还是不要进行任何假设，对runtime环境进行一遍检查比较稳妥，下面贴一个本人进行环境安全检查的例子：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"><br /></span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">safe_check</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">scandir</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">opendir</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> || !</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">readdir</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">?&gt;</span><span style="color: Black;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;div class=&quot;error fade&quot; id=&quot;message&quot;&gt;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;p&gt;&lt;strong&gt;Sorry, PHP function 'scandir' is forbidden in your server, so that the plugin will not work. Please disable the plugin.&lt;/strong&gt;&lt;/p&gt;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;/div&gt;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br /></span><span style="color: Olive;">}</span><span style="color: Gray;"><br /></span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">is_admin</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">admin_notices</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">safe_check</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: Blue;">?&gt;</span></div></div>
<p>如上，用户会在打开后台页面时，就发现一条警告信息，说明此插件可能无法正常工作。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（06）---WordPress插件Filter" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-06.htm&from=http%3A%2F%2Fsexywp.com%2Fcheck-the-runtime-evn-of-wp-plugins.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（06）---WordPress插件Filter</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/check-the-runtime-evn-of-wp-plugins.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[插件开发]：后台管理页面脚本按需加载</title>
		<link>http://sexywp.com/include-scripts-on-demand.htm</link>
		<comments>http://sexywp.com/include-scripts-on-demand.htm#comments</comments>
		<pubDate>Mon, 15 Feb 2010 09:05:21 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=361</guid>
		<description><![CDATA[插件的后台管理页面的主要功能是协助用户设定插件运行时参数，一般都需要用户进行交互，这就少不了需要客户端脚本的参与（主要是js脚本，当然还有配套的css样式表）。

WP的后台本身就已经加载了许多的脚本，包括各类类库和基础功能的脚本。过多的脚本文件引入，会增加HTTP请求，增加流量，拖慢速度。好在，WP的后台已经采取了相当多的措施，来管理后台加载的脚本。首先是用wp-dependency管理依赖关系，用load-scripts来压缩、并加载脚本，使得各种类库被合并到同一个文件中进行加载，节省了HTTP请求数量和流量。

<span class="readmore"><a href="http://sexywp.com/include-scripts-on-demand.htm" title="[插件开发]：后台管理页面脚本按需加载">Keep Reading --- 2177 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（04）---WordPress插件的结构" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-04.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（04）---WordPress插件的结构</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（09）---WordPress插件和数据库交互" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-09.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（09）---WordPress插件和数据库交互</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>插件的后台管理页面的主要功能是协助用户设定插件运行时参数，一般都需要用户进行交互，这就少不了需要客户端脚本的参与（主要是js脚本，当然还有配套的css样式表）。</p>
<p>WP的后台本身就已经加载了许多的脚本，包括各类类库和基础功能的脚本。过多的脚本文件引入，会增加HTTP请求，增加流量，拖慢速度。好在，WP的后台已经采取了相当多的措施，来管理后台加载的脚本。首先是用wp-dependency管理依赖关系，用load-scripts来压缩、并加载脚本，使得各种类库被合并到同一个文件中进行加载，节省了HTTP请求数量和流量。<span id="more-361"></span></p>
<p>在开发插件管理后台的时候，窃以为还是遵循WP本身的开发习惯比较好，也将这一套措施应用到自己的开发过程中，这样一来，会有很多的好处。首先，不会给WP的后台带来太多的负担，使用WP本身的脚本加载机制，就不会为WP的后台增加多于的HTTP请求，而且，WP后台中，将脚本在页面的最尾部引入到页面之中，这也遵循了比较优秀的实践经验。</p>
<p>其次，使用WP自身的脚本管理机制，不会重复引入相同的脚本，也可以合理地管理依赖关系，在进行WP相关的开发过程中，如果需要引入特定的脚本库，只需要调用wp_enqueue_script函数即可，比如引入jquery类库，wp_enqueue_script('jquery);就可以实现在页面中正确引入jquery类库。WP_Script对象会自动判断重复，如果已经有别的插件或者页面本身已经引入了jquery，那么就不会重复引入。另举个例子，假如需要一个拖拽排序的效果，那么需要选用jquery ui中的sortable组件，那么只要调用wp_enqueue_script('jquery-ui-sortable');即可，在页面中，就可以发现，ui.core.js也被加载了，ui.core是sortable依赖的库，但是却不需要开发者自己去操心了。</p>
<p>从上述描述中，也可以看到另一个好处，就是wp其实已经包含，并且注册了很多常用的类库和效果库，使用其自带机制，调用这些脚本都是非常容易的，并不用费心去管这些脚本到底存在何处，其url到底是什么，只需要简简单单用一个名字既可以引入页面中。此外，如果插件中引用的脚本类库升级了，那么也会随着用户端WP的升级而自动更换是上升级的脚本，省却了更新插件的麻烦。</p>
<p>下面是我个人在开发中的实践作法。</p>
<p>在插件开发过程中应用脚本库和特定脚本需要调用的函数就是wp_enqueue_script，上面已经介绍过了，接下来介绍一下这个函数调用的位置。</p>
<p>比如说，我现在要开发一个插件，叫做detail info，在其后台管理页面中，需要用到jquery ui selectable组件。引入这个脚本的方法如下：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">plugin_detail_info_init</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">一些初始化工作</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">wp_enqueue_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">jquery-ui-selectable</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">将实现插件功能的函数挂载到正确的hook上面</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_filter</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_content</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">display_detail_info</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">plugins_loaded</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">plugin_detail_info_init</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>一般我个人开发一个插件的时候，都喜欢将所有的插件初始化工作放到一个init函数中，然后将这个函数hook到plugins_loaded之上（这么做的原因就不赘述了）。在init函数中，就可以调用wp_enqueue_script函数了，当然也有不按照这个结构来写插件的，但是道理是一样的，就是此函数要在action wp_head和admin_head发生之前被调用，<a href="http://sexywp.com/tags/plugins" class="st_tag internal_tag" rel="tag" title="标签 plugins 下的日志">plugins</a>_loaded这个action发生的顺序是非常靠前的，所以此函数放在这里，一定可以正确引入脚本。</p>
<p>当然，这么做只是可行的做法，却不是正确的做法，这么做的话，由于是添加到了plugins_loaded这个action中，那么所有的页面中，至少会多出几个脚本文件，一个jquery，一个是ui.core，一个是ui.selectable，这个组件仅需要在后台中引入，却不得不在所有的页面中加载，可以说，是一种很不经济的做法。对于开发者来说没什么，但是对于用户来说，就增加了他们服务器的负担。当然更多时候，用户可能并不懂得其中的意义，他只知道一件事情，就是插件装得越多，自己的博客运转速度就越慢，很多WP用户都经历过热衷于安装各种插件，到头疼安装了很多插件，到最后一切从简对插件望而却步的一个转变过程。其实，我个人觉得，在这个转变过程中，插件的开发者是负有一定责任的。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">plugin_detail_info_init</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">一些初始化工作</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">is_admin</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">wp_enqueue_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">jquery-ui-selectable</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">将实现插件功能的函数挂载到正确的hook上面</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_filter</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_content</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">display_detail_info</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">plugins_loaded</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">plugin_detail_info_init</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上面是更加常用的一种做法，通过is_admin()条件判断函数，来使得脚本只在后台加载，这样的话，就不会在博客的页面上添加可能根本就完全不会用到的脚本。</p>
<p>做到了这一步，基本上，事情已经做到差不多了，但是，这离尽善尽美还很遥远。使用上述第2个代码范例，可以使脚本不在前台页面加载，但是在后台页面还是没有区分能力，简单说，就是会在后台所有的页面中都添加了上述几个脚本文件。这样，会拖慢博客后台的速度，好在后台用户并不多，访问压力并不大，一时半会儿，也不会出什么问题。但是，短时间没问题不代表永远没有问题，在后台所有页面引入相同的脚本，有一个后果，很有可能在插件安装数量多了以后，出现脚本冲突问题。虽然这种冲突，可以通过脚本地开发技巧来解决，一般比较成熟的类库都不会互相发生冲突，但是，如果有开发者用这种机制引入了自己的编写的专用脚本，那就很难说了。</p>
<p>最佳的做法，无疑是只在用到的那个页面，才引入相关的脚本。其他页面一律不加入脚本。做到这一点，并不容易，乃至是相当苦难。我个人在开发过程中也试过几种方法，但是效果都不是很好。</p>
<p>起初，我的做法是，直接将脚本写在插件的管理页面的代码中，这么一来，肯定是可以实现脚本按需加载的，但是这样一来，就会使js脚本代码和页面代码混在一起，开发起来，维护起来，还是调试起来，都不是很方便。另外也破坏了web开发行为和数据表现分离的准则。不过，这种做法，确实是一种比较稳定而且比较容易想到，又比较好实现的做法。对与自己写的脚本来说，也没什么太多不便，不便主要体现在类库的引入上面，前文提到的好处一个都不复存在了。</p>
<p>后来，我又发现了一种方法，就是通过$_SERVER系统变量中的QUERY_STRING来判断当前所处的页面。比如，在上述范例的插件中，其管理界面的url显示成这个样子：</p>
<p>http://localhost/<a href="http://sexywp.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 WordPress 下的日志">wordpress</a>/wp-admin/options-general.php?page=detail_info_manager</p>
<p>从这个URL中，就可以判定出来，当前打开的页面确实是这个插件的管理页面，这样一来，以此为依据就可以决定是否要引入脚本，其示例如下：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">plugin_detail_info_init</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">一些初始化工作</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">is_admin</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: Blue;">strpos</span><span style="color: Olive;">(</span><span style="color: #00008b;">$_SERVER</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">QUERY_STRING</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">detail_info_manager</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> !== </span><span style="color: Green;">false</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">wp_enqueue_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">jquery-ui-selectable</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">将实现插件功能的函数挂载到正确的hook上面</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_filter</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_content</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">display_detail_info</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; ....</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">plugins_loaded</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">plugin_detail_info_init</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上述这个办法在后台脚本引用管理方面的效果还算不错，基本上按照我的要求做到了按需加载。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（04）---WordPress插件的结构" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-04.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（04）---WordPress插件的结构</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（09）---WordPress插件和数据库交互" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-09.htm&from=http%3A%2F%2Fsexywp.com%2Finclude-scripts-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（09）---WordPress插件和数据库交互</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/include-scripts-on-demand.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何才能按需加载脚本？</title>
		<link>http://sexywp.com/how-to-include-script-file-on-demand.htm</link>
		<comments>http://sexywp.com/how-to-include-script-file-on-demand.htm#comments</comments>
		<pubDate>Sun, 26 Apr 2009 14:35:12 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://sexywp.com/%e5%a6%82%e4%bd%95%e6%89%8d%e8%83%bd%e6%8c%89%e9%9c%80%e5%8a%a0%e8%bd%bd%e8%84%9a%e6%9c%ac%ef%bc%9f.htm</guid>
		<description><![CDATA[本文提出问题，并不解决问题。

我在研究Extended Live Archive（ELA）插件的代码，发现一个问题，这个问题具有一定的共性，而且，我现在也没有什么好的解决办法，所以我把它描述一下，看看有没有高人高见。

 

<span class="readmore"><a href="http://sexywp.com/how-to-include-script-file-on-demand.htm" title="如何才能按需加载脚本？">Keep Reading --- 1119 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>本文提出问题，并不解决问题。</p>
<p>我在研究Extended Live Archive（ELA）插件的代码，发现一个问题，这个问题具有一定的共性，而且，我现在也没有什么好的解决办法，所以我把它描述一下，看看有没有高人高见。</p>
<p> <span id="more-343"></span>
<p>WP插件一般目标有两个，一个是增强博客页面功能，让观众有更好体验，另一个是增强博客管理页面功能，让博客管理者有更高管理效率。无论是哪一种，我们都经常会用到脚本，比如指定样式的CSS脚本，指定行为的JS脚本。好，现在问题来了，一般来说，我们使用插件增强的功能，都是在某个特定的页面上的功能，只有少数才是全局功能，直觉上，我们希望，在这个特定的页面上引入需要的脚本，而在其他的页面上不引入这段脚本。</p>
<p>我这个话说得有点绕，举个具体的例子。比如，某个插件，用于显示一个漂亮的相册，这个相册有一个自己专属的相册页面，这个相册的翻页功能需要用到prototype类库，你作为一个博客的主人，肯定是希望只有用户打开相册页面时，用户才需要下载prototype，平时看你的博客，不用每个页面都去下载一下prototype。（这个类库在没有pack的情况下128k大。）</p>
<p>希望我说清楚，这个问题概括成一句话，就是按需加载脚本，用到时，才下载。</p>
<p>事实上是这样的，我说得很轻巧，但是做起来却很难。就拿我手头的这个ELA来说事，这个插件是一个AJAX应用，用来展示一个结构化的归档目录。插件通过一个template tag提供用户接口，在调用这个template tag的页面，就会有归档目录出现。这个归档目录，必须要CSS文件来指定其样式，结果，我们的难点是，不知道用户会在哪个页面上调用这个tag，所以只能草草地把这个样式表hook到wp_head，导致的结果是，所有的页面上，都会链入这么一个样式表，而真正起作用的，只有一个页面而已。</p>
<p>我初步想了想，几乎想不出漂亮的办法能解决这个问题。这个问题的根本就在于，程序在执行到wp_head的时候，我们还没法知道后续的部分是不是会出现那个tag，而在真的执行到这个tag的时候，头部的内容已经形成了，我们回天乏力。一个直觉的办法，就是把那个样式表，直接也塞到tag的内部，事实上，插件的作者就是这么做的，不过，他只是把用到的JS脚本这么处理了，却没有把CSS这么处理，我猜想他代码写到这里的时候，可能内心也是非常矛盾的。（因为一个优秀的页面，就应该是数据、表现、行为分离的，这么做等于破坏了这个原则了）</p>
<p>好，到这里，问题应该算是说完了。其实这个问题相当普遍，只要我们需要将一个脚本添加到wp_head或者admin_head（对应的还有各自的footer部分），我们就面临着这个问题，你添加的东西，真的每个页面都需要么？如果是大多数页面需要，那还不是很浪费，最浪费的就是只有一个页面需要，而其他所有的页面都跟着增加负载。</p>
<p>WP的圈子里，有一种论调，就是插件用得越多，博客速度越慢，性能越差。我想，脚本没有能够做到按需加载，也算是造成这个论调的原因之一。</p>
<p>大家一起开动下脑筋吧~</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-include-script-file-on-demand.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/development" title="development" rel="tag">development</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-include-script-file-on-demand.htm/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>怎样撰写Features List</title>
		<link>http://sexywp.com/how-to-write-a-features-list.htm</link>
		<comments>http://sexywp.com/how-to-write-a-features-list.htm#comments</comments>
		<pubDate>Mon, 20 Apr 2009 15:02:05 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[English writing]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://sexywp.com/%e6%80%8e%e6%a0%b7%e6%92%b0%e5%86%99features-list.htm</guid>
		<description><![CDATA[当开发好一款插件的时候，要为插件撰写一个readme.txt文件，这是让用户了解你的插件的最好方式。很多插件都会在readme.txt的第一个section（description）里，附上一个简单明了的features list，以便用户可以快速扫描你插件包含的功能，决定是否选用。那么应该如何撰写features list呢？本文为您介绍。

 

我不是一个撰写readme.txt的专家，但是我经常需要做这件事情，我自己也很不在行，从来没有仔细研究过这件事情，今天在这里写下的是我第一次研究的笔记。对本文内容的权威性，大家请自己斟酌。

<span class="readmore"><a href="http://sexywp.com/how-to-write-a-features-list.htm" title="怎样撰写Features List">Keep Reading --- 894 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（07）---构造一个WordPress插件管理员面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-07.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（07）---构造一个WordPress插件管理员面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>当开发好一款插件的时候，要为插件撰写一个readme.txt文件，这是让用户了解你的插件的最好方式。很多插件都会在readme.txt的第一个section（description）里，附上一个简单明了的features list，以便用户可以快速扫描你插件包含的功能，决定是否选用。那么应该如何撰写features list呢？本文为您介绍。</p>
<p> <span id="more-342"></span>
<p>我不是一个撰写readme.txt的专家，但是我经常需要做这件事情，我自己也很不在行，从来没有仔细研究过这件事情，今天在这里写下的是我第一次研究的笔记。对本文内容的权威性，大家请自己斟酌。</p>
<p>首先来看一看例子：</p>
<ul>
<li>Templates : <span style="color: #800000">You can add custom templates for your theme. </span></li>
<li>Media RSS feed : <span style="color: #0080ff">Add the Cooliris Effect to your gallery</span> </li>
<li>Role settings : <span style="color: #008000">Each gallery has a author</span> </li>
<li>AJAX based thumbnail generator : No more server limitation during the batch process </li>
<li>Copy/Move : <span style="color: #0080ff">Copy or move images between galleries</span> </li>
<li>Sortable Albums : <span style="color: #0080ff">Create your own sets of images</span> </li>
<li>Upload or pictures via a zip-file (Not in Safe-mode) </li>
<li>Watermark function : <span style="color: #800000">You can add a watermark image or text</span> </li>
<li>JavaScript Effect : <span style="color: #0080ff">Use any available popular image effect : Shutter, Thickbox, Lightbox or Highslide</span> </li>
<li>Multiple CSS Stylesheet : <span style="color: #0080ff">Use a nice shadow effect for your thumbnails with your own CSS file</span> </li>
<li>Slideshow : <span style="color: #008000">Full integrated flash slideshow</span> </li>
<li>TinyMCE : Button integration for easy adding the gallery <a href="http://sexywp.com/tags/tags" class="st_tag internal_tag" rel="tag" title="标签 tags 下的日志">tags</a> </li>
<li>Sidebar Widget : <span style="color: #0080ff">Show a slideshow, random or recent picture at your sidebar</span> </li>
<li>Language support : <span style="color: #008000">Translated in more than 30 languages</span> </li>
<li>Upload tab integration : <span style="color: #800000">You have access to all pictures via the upload tab</span> </li>
<li>Tag support for images : <span style="color: #0080ff">Append related images to your post, create a image tag-cloud</span> </li>
<li>Meta data support : <span style="color: #0080ff">Import EXIF, IPTC or XMP meta data</span> </li>
<li>Sort images feature </li>
<li>Cool flash addons here : url </li>
</ul>
<p>这份列表，撰写得有其特色，这是NextGen Gallery的features list。其采用的格式为：“特性名称：简述”。特性名称，一般采用的是名词，可以是具体名词，也可以是动名词，其格式基本上比较统一。</p>
<p>而其简述部分，则比较自由。</p>
<p>第一句，you can do sth. 是一个简单句。以第二人称描述，这跟人的感觉像是一个推销员，在与你说话，隐含了一层意思，“如果你用了本插件”，“你就可以用这款插件做……”。第二句，是一个动宾短语，我们可以猜测其隐含主语，窃以为，仍旧是“你”，“(you are able to) add Cooliris Effect to your gallery (with it)”。看到这里，我们就可以统计一下，这么多features里，使用这两种用法的句子，暗红色为第一种，浅蓝色为第二种。除却这两种，我们还看到其他的例子，用绿色标出的，是我个人认为有一些共同点的例子，第一个是简单句，但是是以第三人称为主语的句子，后面两个，则是分词开头的关于，而我猜测其主语，也为第三人称。</p>
<p>看了看原作者的blog，基本上是英文写成的，而也有少量的德语，我们可以视其为是native speaker。从他撰写的特性列表里，我们可以学习到一些西方人传达信息和接受信息的模式。他们更关心的是，可以用这款插件做什么，他们应该怎么使用这款插件。一款插件的使用方式和其提供的可能性，是他们关心的东西。而插件本身利用的技术，插件本身的性质和特性，不是他们关注的东西。</p>
<p>如果你的插件，有许多的特性，你在描述的时候，应该转换一种表达思路，即这种特性，能够带来一种什么样的使用上的可能性。尽量使用第二人称来描述，“你用它，能够干……”。这是西方人，更能接受的一种方式，也符合他们的表达习惯。</p>
<p>行了，本文就写到这里。其实，我还看了两个插件的features list的，但是基本上雷同，大家可以自己分析。本文主要写给自己看，作为自己学习写作的一些笔记。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（07）---构造一个WordPress插件管理员面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-07.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（07）---构造一个WordPress插件管理员面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-features-list.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/english-writing" title="English writing" rel="tag">English writing</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-features-list.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Paypal Donate插件</title>
		<link>http://sexywp.com/plugin-simple-paypal-donate.htm</link>
		<comments>http://sexywp.com/plugin-simple-paypal-donate.htm#comments</comments>
		<pubDate>Sun, 12 Apr 2009 15:25:56 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[idea]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=337</guid>
		<description><![CDATA[Simple Paypal Donate是一款在博客中插入捐赠按钮的插件，但是其功能并不尽如人意，本文记录我对这款插件的改进意见。<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>如果你是一个插件开发者，那么应该使用这款插件，在你发布插件的页面上放上一个Paypal Donate按钮，这样如果用户心情好了，兴许就会给你捐一点。</p>
<p>今天终于看到了这么款插件，但是，我这篇文章其实是想说，这个插件，我对它很不满意，对不起它灌了一个Simple的名字，插入这个按钮好麻烦啊，还要用php函数去写。</p>
<p>我觉得，这款插件可以有个很体贴的改进，就是增加在对shortcode的支持。这样，我不但可以在页面中插入捐赠按钮，也可以在任何一篇文章中插入捐赠按钮，你们说呢？</p>
<p><a href="http://www.artiss.co.uk/simple-paypal-donate">插件页面在这里</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fplugin-simple-paypal-donate.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/idea" title="idea" rel="tag">idea</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/review" title="review" rel="tag">review</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/plugin-simple-paypal-donate.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[WP开发环境]在NetBeans中配置FTP</title>
		<link>http://sexywp.com/use-ftp-in-netbeans.htm</link>
		<comments>http://sexywp.com/use-ftp-in-netbeans.htm#comments</comments>
		<pubDate>Sun, 29 Mar 2009 12:23:26 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[enviornment]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[NetBeans]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=331</guid>
		<description><![CDATA[本文介绍了如何在NetBeans IDE 6.5.1 for PHP中配置FTP，以搭建一个便捷的WordPress 主题、插件开发环境。<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fbuild-wp-test-env.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">建立WordPress测试环境</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">WordPress 开发资源</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-05.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（05）---WordPress 插件Actions</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-07.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（07）---构造一个WordPress插件管理员面板</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>本文介绍了如何在NetBeans <a href="http://sexywp.com/tags/ide" class="st_tag internal_tag" rel="tag" title="标签 IDE 下的日志">IDE</a> 6.5.1 for PHP中配置FTP，以搭建一个便捷的WordPress 主题、插件开发环境。<span id="more-331"></span></p>
<p><a href="http://sexywp.com/tags/netbeans" class="st_tag internal_tag" rel="tag" title="标签 NetBeans 下的日志">NetBeans</a> IDE是一款非常优秀的IDE环境，我以前曾经介绍过，如何使用NetBeans作为WP的开发环境，今天，再来介绍一个直接链接远程服务器进行调试的技巧。那就是FTP，记得在Dreamweaver的时代，配置远程服务器就是非常方便的一件事情，对于NetBeans这个更加现代和超前的开发环境来说，这当然也是必备功能了。</p>
<p>跟着我做，只有3个步骤，就可以搞定。上一篇《<a href="http://sexywp.com/use-netbeans-to-develop-wp.htm">使用NetBeans作为WordPress开发环境</a>》已经介绍了如何将WP导入到NetBeans工程，在其基础上，我们来配置FTP。</p>
<p><img src="http://lh3.ggpht.com/_QYicOeu89Bk/Sc9is7kMwkI/AAAAAAAABSg/ovY4do-aGo8/s400/NetBeans-FTP-1.GIF" /></p>
<p>第一个步骤如上图，在项目面板，wp27项目上，单击右键，点属性，打开属性面板。下图为弹出的对话框。<strong>点击查看清晰大图</strong>。</p>
<p><a href="http://picasaweb.google.com/lh/photo/nw0KeRfVIghfDf5O-IVkeA?feat=embedwebsite"><img src="http://lh4.ggpht.com/_QYicOeu89Bk/Sc9itA24sKI/AAAAAAAABSo/MxKgE6-IJUA/s400/NetBeans-FTP-2.GIF" /></a></p>
<p>遵循上图中蓝色字迹标注的1、2两次点击，会弹出FTP服务器管理面板，创建好一个FTP服务器配置。确定后，回到属性面板。如下图所示。</p>
<p><a href="http://picasaweb.google.com/lh/photo/zsl6iDjIoO_NIuXgliKuyA?feat=embedwebsite"><img src="http://lh5.ggpht.com/_QYicOeu89Bk/Sc9itPHRg-I/AAAAAAAABSw/d-GrRy5bvpE/s400/NetBeans-FTP-3.GIF" /></a></p>
<p>在上图中，我们配置运行配置为在远程Web站点运行。配置的选项可以参考图片中的配置。注意，刚才我们配置ftp服务器的时候，远端路径为wp安装目录，现在我们本地的目录只要填写一个/即可，代表项目根目录。</p>
<p>上面三个步骤，已经配置好了FTP服务器。在具体开发过程中，像下图的样子，点击你开发的主题中的文件，点击上传，就会自动上传到正确的地方，覆盖源文件。一般我在用NetBeans开发主题或者插件的过程中，都配合有SVN支持，所以不用担心覆盖会出问题，可以恢复到上一个版本。</p>
<p><a href="http://picasaweb.google.com/lh/photo/2FfuoL0acgnnL_hotEYPig?feat=embedwebsite"><img src="http://lh4.ggpht.com/_QYicOeu89Bk/Sc9itVtT2nI/AAAAAAAABS4/CYhbma6hAao/s400/NetBeans-FTP-4.GIF" /></a></p>
<p>好，希望对您有帮助~~</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fbuild-wp-test-env.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">建立WordPress测试环境</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">WordPress 开发资源</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-05.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（05）---WordPress 插件Actions</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-07.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（07）---构造一个WordPress插件管理员面板</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/development" title="development" rel="tag">development</a>, <a href="http://sexywp.com/tags/enviornment" title="enviornment" rel="tag">enviornment</a>, <a href="http://sexywp.com/tags/guide" title="guide" rel="tag">guide</a>, <a href="http://sexywp.com/tags/ide" title="IDE" rel="tag">IDE</a>, <a href="http://sexywp.com/tags/netbeans" title="NetBeans" rel="tag">NetBeans</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/use-ftp-in-netbeans.htm/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>WordPress 开发资源</title>
		<link>http://sexywp.com/wordpress-developer-resource.htm</link>
		<comments>http://sexywp.com/wordpress-developer-resource.htm#comments</comments>
		<pubDate>Mon, 09 Mar 2009 12:59:05 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[interesting things]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=323</guid>
		<description><![CDATA[今天刚看到几个WordPress开发资源，觉得很不错~在这里记录一下。

WordPress phpDoc

WordPress内部使用phpDoc的语法进行注释，这是WordPress.org为其生成的文档。

<span class="readmore"><a href="http://sexywp.com/wordpress-developer-resource.htm" title="WordPress 开发资源">Keep Reading --- 166 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>今天刚看到几个WordPress开发资源，觉得很不错~在这里记录一下。<span id="more-323"></span></p>
<p><strong><a href="http://phpdoc.wordpress.org/">WordPress phpDoc</a></strong></p>
<p>WordPress内部使用phpDoc的语法进行注释，这是WordPress.org为其生成的文档。</p>
<p><strong><a href="http://wplookup.com/">WP 函数搜索引擎</a></strong></p>
<p>超级棒的一个功能~ 看看下文的说明。</p>
<blockquote><p>
I want to quickly let everyone here know of a site that one of my good<br />
friends, Andy Stratton (http://theandystratton.com), has setup<br />
recently.  The site is called WPLookup and can be found at<br />
http://wplookup.com/.  It provides a simple search box for quick<br />
lookups of <a href="http://sexywp.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 WordPress 下的日志">WordPress</a> functions and <a href="http://sexywp.com/tags/template" class="st_tag internal_tag" rel="tag" title="标签 template 下的日志">template</a> <a href="http://sexywp.com/tags/tags" class="st_tag internal_tag" rel="tag" title="标签 tags 下的日志">tags</a>.  If the appropriate<br />
codex page exists for the function you are looking for it will<br />
immediately redirect you there.  If it does not exist you will be<br />
directed to a documentation search on http://wordpress.org/search<br />
which will contain a list of results for you.</p>
<p>To make it even better the site can also integrate into your browsers<br />
search bar keeping you from ever having to actually navigate to the<br />
WPLookup site to do the search.</p>
<p>I have taken his service one step further and integrated his service<br />
into an IRC bot.  The bot is sitting in #wordpress on freenode.  To<br />
use the bot type something in the form of `.codex get_pages`.</p>
<p>Now what are you waiting for?  Check it out now at http://wplookup.com/.</p>
<p>Enjoy!<br />
--<br />
Matt Martz<br />
matt@sivel.net
</p></blockquote>
<p><strong><a href="http://xref.fergcorp.com/">WordPress源代码交叉引用</a></strong></p>
<p>WordPress各个版本的源代码交叉引用。</p>
<p><a href="http://pressography.com/plugins/wordpress-plugin-template/">WordPress插件开发模板</a></p>
<p>尝试一下吧，看看这个东西能从多大程度上提高你插件开发的效率？里面的东西相当全面啊，传达出了作者很多的开发经验。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/development" title="development" rel="tag">development</a>, <a href="http://sexywp.com/tags/interesting-things" title="interesting things" rel="tag">interesting things</a>, <a href="http://sexywp.com/tags/resources" title="resources" rel="tag">resources</a>, <a href="http://sexywp.com/tags/tools" title="tools" rel="tag">tools</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/wordpress-developer-resource.htm/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Template Tags（模板标签）使用指南</title>
		<link>http://sexywp.com/template-tags-usage.htm</link>
		<comments>http://sexywp.com/template-tags-usage.htm#comments</comments>
		<pubDate>Fri, 06 Mar 2009 04:28:40 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[usage]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=322</guid>
		<description><![CDATA[在WordPress里面，有一类函数，他们被称为Templete Tags，它们相比于普通的函数，有一个共同的特点。本文将为您介绍Template Tags的基本使用方法。<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="手动调用Simple Tags输出相关日志" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-simple-tags-mannually-to-output-related-posts.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">手动调用Simple Tags输出相关日志</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Google AJAX Libraries API替换WordPress自带的js库" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freplace-the-wp-js-lib-by-googleapi.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/23/9256004.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Google AJAX Libraries API替换WordPress自带的js库</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>在WordPress里面，有一类函数，他们被称为Templete <a href="http://sexywp.com/tags/tags" class="st_tag internal_tag" rel="tag" title="标签 tags 下的日志">Tags</a>，它们相比于普通的函数，有一个共通的特点。那么它们共通的特点是什么？应该如何使用模板标签呢？本文为您解答这个问题。<span id="more-322"></span></p>
<h3>概念阐述</h3>
<p><strong><a href="http://sexywp.com/tags/template" class="st_tag internal_tag" rel="tag" title="标签 template 下的日志">Template</a></strong></p>
<p><em>Template</em>的中文意思就是模板。在WordPress中，数据库里存储的一大堆文章也好、评论也好、链接也好，会按照一定的页面布局、排版形式，展现出来。这个“<strong>一定的页面布局、排版形式</strong>”，就是一个模板。比如，您的blog主页，使用的就是主页模板（home.php或者index.php），您的日志页面，使用的就是单页模板（single.php），等等。</p>
<p>模板都是由有经验的平面设计师和前台工程师所设计，首先由平面设计师绘制版面，然后由前台工程师编码成php、css和js。对于WordPress这样的开源产品，也有着大量的爱好者，自己身兼二职，独立完成模板制作。主页模板（home.php）、日志模板（single.php）、页面模板（page.php）等等这一大堆模板（最少只需要一个index.php，多的多达13个如hybrid这类的），有着统一的风格，他们往往由同一人设计，并且打包在一起发布。<strong>这个打好的包，我们称之为主题（Theme）</strong>。</p>
<p><strong>Template Tag</strong></p>
<p><em>Template Tag</em>的中文翻译是模板标签。（就我个人来看，这个翻译是很糟糕的。至少我一眼看去，不明白这个东西是干啥用的。不过大家貌似都这么叫，所以，我也这么叫。）模板标签的本质，是一个php函数，这一类php函数有一个共通的特点，就是它们一定会在页面上显示一些数据（如评论，日志，链接，任何数据库里的数据）。为了便于记忆，您可以这么想，在php文件中，模板标签，就是一个标记，在最后要给读者展示的页面中，这样的标记会被替换成对应的数据。一个模板就好像是一张完型填空的考卷，模板标签，就好比那一个个横线空格。</p>
<p>模板标签出现在一个模板中，那么该标签代表的那部分数据，就会出现在模板的那个位置。</p>
<h3>用法指南</h3>
<p>使用模板标签，是一件非常容易，又非常困难的事情。</p>
<p>有多容易？好多人，一上手，就会用了，都不需要学。他们定制自己的WP主题，并且乐此不疲，他们把自己的行为称作DIY。</p>
<p>有多困难？上述那些人里，一大半都不知道什么是<em><strong>真正的模板标签</strong></em>，只知道“那东西，写在那里，就会出现我要的”，以至于他们往往无法正确、全面、自由地使用模板标签，甚至错误地使用模板标签。</p>
<p><strong>到底应该如何使用？</strong></p>
<p>第一，有明确的文档说明此函数为模板标签，这个函数才是模板标签，否则，不一定是。官方文档（<a href="http://codex.wordpress.org/Template_Tags">去看看吧</a>）里有大量的标签可用，甚至有些插件，通过增加模板标签，来扩充WordPress的功能，典型的如WP Kit CN（<a href="http://sexywp.com/wp-kit-cn-doc">去看看它的文档</a>）。</p>
<p>第二，知道了哪些东西是标签，还要明白标签的使用位置。有些标签，随便写在哪里都OK，另一些标签，只能出现在特定的地方（The Loop内部）。一般，没有特别说明只能用于The Loop内部的标签，就随处可用。那个神秘的The Loop，我们后面来解释，这里先跳过。</p>
<p>第三，标签的本质是函数，调用函数就需要传递参数。一个函数<strong><strong>调用</strong></strong>长得像这个样子：</p>
<p>i_am_a_function(arguments);</p>
<p>我知道，很多人使用模板标签，都这样写，i_am_a_function();，后面是一对空的小括号。括号里是传递参数用的，但是一般为什么不传也可以？因为，这个标签的设计者，为这个标签指定了默认的参数，“<strong>如果没人告诉我，该怎么做，那么，我按照预先设定的方式工作。</strong>”模板标签如是说。所以，亲爱的读者，如果您希望模板标签按照您的要求工作，<strong>请您告诉它，应该怎么做</strong>。</p>
<p><strong>参数的用法</strong></p>
<p>模板标签的参数，有多种形态。这种混乱的局面，一方面是<a href="http://codex.wordpress.org/WordPress_Coding_Standards">WordPress官方的编码规范</a>没有指定造成；另一方面，各类插件开发者的背景习惯造成（有些人是C++/Java派系程序员，有些是PHP派系程序员）。</p>
<p><em><strong>常见风格1</strong></em></p>
<p>wp_list_bookmarks('title_li=&#038;categorize=0');</p>
<p>这个是WordPress标准模板标签，括号里面的内容，是一个字符串，就是所谓的参数，这种风格，我们视其为PHP派系程序员所为，另外，整个WP内部提供的模板标签，基本都是这种形态，我个人视其为<strong>事实上的标准形态</strong>。推荐插件作者都这么写。</p>
<p>对于亲爱的读者您，我来简单解释一下。上述例子中，是一个显示友情链接的标签，其参数字串是很有规律的，以&#038;符号分割，第一段title_li=，这个串指定了链接分类名称，=号后面什么都没有，代表不显示名称。第二段，categorize=0，代表所有友情链接不按照其类分类显示，而是混在一起显示。</p>
<p><em><strong>常见风格2</strong></em></p>
<p>get_recent_comments(5, '&lt;li&gt; ', '&lt;/li&gt;');</p>
<p>上述模板标签来自桑葚出品的中文WordPress工具箱。这种形态，我们视其为C++/Java派系程序员。这个模板标签作用是显示最近评论列表。第一个参数，表示显示数量，5条，第二个参数表明在每条前面加一个&lt;li&gt;，第三个表示每条后面加一个&lt;/li&gt;，如此这般，可以使每条评论成为一个HTML里的List Item，也即列表项。</p>
<p><em><strong>常见风格3</strong></em></p>
<p>$args = array(<br />
"number" => 10,<br />
"length" => 30,<br />
"skipuser" => 'Charles'<br />
);<br />
wkc_recent_comments($args);</p>
<p>上述模板标签来自本人写的WP Kit CN。<strong>这种形态，是常见风格1的变种。可以和风格1互换。</strong>所以，也是PHP派系的。这种调用方式，首先构造一个参数数组，然后把数组传递给标签。条理清楚，含义明确，书写规范。也是本人所倾向使用的标准形式。上述调用，可以写成：</p>
<p>wkc_recent_comments('number=10&#038;length=30&#038;skipuser=Charles');</p>
<p>代表显示10条评论，每条评论30个字，不显示Charles发表的评论。</p>
<p><strong>参数说明</strong></p>
<p>到这里，您可能会说了，“我怎么知道应该用那个参数？参数的名字是啥？”，OK，这个问题有两个地方可以找到答案。</p>
<p>第一，文档，上文给出过WP文档所在地，带有超链接的，可以点进去看，一般都带有说明，一共有几个参数，每个参数设定格式，有效数值范围等等。</p>
<p>第二，源代码，很多模板标签没有给出文档，那么只有一个地方可以看，即源代码。<strong>源代码之下，了无秘密。</strong>“我没有能力看源代码！”，那么，很抱歉，您<strong>可能</strong>还不具备使用不带文档的模板标签的能力，请不要去使用它。</p>
<p>一般，如果一个模板标签不带有文档有这么几个原因。第一，该标签原作者不推荐用；第二，实验产品，不推广使用；第三，作者超级懒惰，懒得写文档（狂晕，但确实如此，比如我曾经就这样）。</p>
<h3>总结</h3>
<p>亲爱的读者，模板标签，说难不难，说易不易。要想正确使用，还是需要下一番功夫，阅读文档。想要挑战一下的，或者您真的是一个DIY爱好者，请您一定要阅读源代码。那样，您肯定可以看透每个模板标签的秘密，成为DIY界的一代大侠，用上人人羡慕的，“与众不同”的主题。</p>
<p>谢谢！</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="手动调用Simple Tags输出相关日志" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-simple-tags-mannually-to-output-related-posts.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">手动调用Simple Tags输出相关日志</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="使用Google AJAX Libraries API替换WordPress自带的js库" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freplace-the-wp-js-lib-by-googleapi.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/23/9256004.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用Google AJAX Libraries API替换WordPress自带的js库</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Ftemplate-tags-usage.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/tags" title="tags" rel="tag">tags</a>, <a href="http://sexywp.com/tags/template" title="template" rel="tag">template</a>, <a href="http://sexywp.com/tags/usage" title="usage" rel="tag">usage</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/template-tags-usage.htm/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>浅析WordPress中的Hook机制</title>
		<link>http://sexywp.com/try-to-explain-hook-in-wp.htm</link>
		<comments>http://sexywp.com/try-to-explain-hook-in-wp.htm#comments</comments>
		<pubDate>Wed, 11 Feb 2009 08:48:11 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[filter]]></category>

		<guid isPermaLink="false">http://sexywp.com/try-to-explain-hook-in-wp.htm</guid>
		<description><![CDATA[Hook，既可以是动词，表示钩住，也可以是名词，表示钩子。在一个计算机程序中，Hook没有准确的并且合理的中文翻译，很多技术书籍文章，干脆就称之为“钩子”。

Hook机制（就是指Action和Filter的机制）正是WordPress能够有成千上万的插件支持的根源。

尽管我以前可能写过类似的文章来说明这个问题，但是我觉得这个东西是如此的重要，以至于如果你还没有明白什么是Hook，根本算不上走进了WP开发者的世界。又或者说，作为一个普通的玩家来说，深刻地理解Hook，能够帮助您走上DIY博客高速车道。

<span class="readmore"><a href="http://sexywp.com/try-to-explain-hook-in-wp.htm" title="浅析WordPress中的Hook机制">Keep Reading --- 1273 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-06.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（06）---WordPress插件Filter</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fplugin-options-inspector.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">WordPress插件：选项查看器</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-07.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（07）---构造一个WordPress插件管理员面板</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-03.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（03）---怎样获得WordPress插件的创意</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-04.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（04）---WordPress插件的结构</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>Hook，既可以是动词，表示钩住，也可以是名词，表示钩子。在一个计算机程序中，Hook没有准确的并且合理的中文翻译，很多技术书籍文章，干脆就称之为“钩子”。</p>
<p>Hook机制（就是指Action和Filter的机制）正是WordPress能够有成千上万的插件支持的根源。</p>
<p>尽管我以前可能写过类似的文章来说明这个问题，但是我觉得这个东西是如此的重要，以至于如果你还没有明白什么是Hook，根本算不上走进了WP开发者的世界。又或者说，作为一个普通的玩家来说，深刻地理解Hook，能够帮助您走上DIY博客高速车道。</p>
<p>Hook这个东西，说难吧，很难，说容易吧，很容易，还真的不好解释。我不能保证每个看完这个文章的人能懂，知道个大概就行了。现在，我们开始。</p>
<p> <span id="more-296"></span>
<p>&#160;</p>
<p>我相信，很多像我一样的80后，会在高中的时候对编程感兴趣，你们很可能选择了一个东西作为入门，那就是Visual <a href="http://sexywp.com/tags/basic" class="st_tag internal_tag" rel="tag" title="标签 basic 下的日志">Basic</a>（VB）。在VB里面，编程变成了一件非常容易的事情，画一个界面，然后这个界面上的元素会在某个事件发生的时候，触发一个函数，在这个函数里，写好你要做的事情，一个Windows桌面应用就完成了。</p>
<p>这种编程的模型叫做事件驱动。你们一定会写一堆叫做OnButtonClick，OnSomethingDosth之类的Sub，具体的意思，就是说，当一个按钮按下，这个事情发生的时候，执行OnButtonClick这个Sub里面的代码。Ok，我想说的就是，在WP里面，就是一种很类似的东西，一个插件的代码，就好比是OnButtonClick这一类Sub里面的代码，而我们的主角hook（可能是一个action，也可能是一个filter，比如post_content，又比如wp_head），就是一个能够触发那段代码的事件，一旦发生，插件就会开始运行。希望到这里，很多学过VB的朋友能有个认识了。</p>
<p>&#160;</p>
<p>接着，时代发展了，OO，也即面向对象大行其道了。学OO，就不得不学一点设计模式了，否则，怎么敢说自己在面向对象呢？如果你碰巧看到过一个模式叫Observer的，那么我愚蠢地以为，可以从一定程度上解释hook机制。把整个WP，看作是一个对象，这个对象最终要打印一个网页出来，这个网页会按照PHP代码的先后顺序，一块一块生成，每个插件都分别是一个对象，非常关心它自己要处理的那一小块网页，它们就是各自关心的那一小块网页的观察者们。在WP初始化的时候，这些插件们就把自己添加到观察者的队列里面（即add_filter或者add_<a href="http://sexywp.com/tags/action" class="st_tag internal_tag" rel="tag" title="标签 action 下的日志">action</a>），而它们观察WP内部的这个窗口，就是action或者filter，WP在执行到特定的时候，就会通知这些插件，某个事情发生了（即apply_filters和do_<a href="http://sexywp.com/tags/action" class="st_tag internal_tag" rel="tag" title="标签 action 下的日志">action</a>）。</p>
<p>&#160;</p>
<p>抽象过后，来一点形象的东西。我又要使用我那不着边际的比喻了。想象一根电线，上面串连着一个接一个的插座。每个插件就是一个小家电，有一个插销，他们被各自地插到了合适自己的那个插座上。然后，电流从这个电线的一头流入，每经过一个插座，这个插座上连接着的电器就开始运转了。所有电器都通电运转了一遍以后，电闸关上了。Ok，这些插座，就好像是hook，有的是action形状的，有的是filter形状的，但是本质上就是插座。</p>
<p>&#160;</p>
<p>好了，我已经废了很多的唇舌了，我心里很清楚，结果可能是这样的，不理解的人，依旧不理解，理解的人，不用看就理解。虽然是这样，我还是执着地想要尝试着解释一下，因为我后面要写一个介绍Hybrid的文章，这个主题框架里面遍布着action和filter，如果不理解这个东西，无论如何也不可能用好Hybrid，同样，要说清Hybrid这个东西，无论如何也躲不过地要说一下hook。毕竟我还是想受人以渔的。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-06.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（06）---WordPress插件Filter</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fplugin-options-inspector.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">WordPress插件：选项查看器</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-07.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（07）---构造一个WordPress插件管理员面板</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-03.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（03）---怎样获得WordPress插件的创意</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-04.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">插件开发全攻略（04）---WordPress插件的结构</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/action" title="action" rel="tag">action</a>, <a href="http://sexywp.com/tags/basic" title="basic" rel="tag">basic</a>, <a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/filter" title="filter" rel="tag">filter</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/try-to-explain-hook-in-wp.htm/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>使用NetBeans IDE 6.5作为WordPress的开发环境</title>
		<link>http://sexywp.com/use-netbeans-to-develop-wp.htm</link>
		<comments>http://sexywp.com/use-netbeans-to-develop-wp.htm#comments</comments>
		<pubDate>Fri, 30 Jan 2009 06:27:25 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[NetBeans]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=287</guid>
		<description><![CDATA[从一个大牛那里看到了介绍NetBeans IDE for PHP的文章，立刻下载下来尝试。立刻被它那强大、便捷、体贴的开发功能所吸引。本文主要介绍我在安装、试用、开发过程中的一些使用体验及感受。





<span class="readmore"><a href="http://sexywp.com/use-netbeans-to-develop-wp.htm" title="使用NetBeans IDE 6.5作为WordPress的开发环境">Keep Reading --- 2009 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="[WP开发环境]在NetBeans中配置FTP" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[WP开发环境]在NetBeans中配置FTP</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>从一个大牛那里看到了<a href="http://wp.gdragon.info/2008/11/22/wordpress-and-netbeans-ide/">介绍NetBeans IDE for PHP的文章</a>，立刻下载下来尝试。立刻被它那强大、便捷、体贴的开发功能所吸引。本文主要介绍我在安装、试用、开发过程中的一些使用体验及感受。</p>
<p><img src="http://lh6.ggpht.com/_QYicOeu89Bk/SXNOTOsS87I/AAAAAAAABBM/KsNZMHoMzMw/s400/NetBeans-01.png" title="NetBeans Web Site" /><br />
<span id="more-287"></span></p>
<h3>从NetBeans官方网站下载IDE</h3>
<p>打开<a href="http://www.netbeans.org/">NetBeans的官方网站</a>，点击Download，可以看到下载页面，如果没有其他的开发需求，选择for PHP的版本即可，大小只有26MB。</p>
<p>上面的语言选择框，大家不要费神去选了，我试过了，选择English和简体中文，下载下来的东西都是同一个，都是Multi-Language版本，而且安装的时候，不可以选择语言，NetBeans会根据系统的语言设定，来自动选择语言。据说可以通过修改配置文件的方式来更改界面语言，想用英文的同学，请自己Google之。</p>
<p>运行NetBeans IDE需要java虚拟机，如果需要开发java的同学，可以只下载JRE，很简单，打开http://java.com，下载即可。有些像我一样，想要以防万一的同学，可能想要安装JDK，那么<a href="http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u11-windows-i586-p.exe?BundledLineItemUUID=7R5IBe.ms04AAAEem.tX3uQi&amp;OrderID=IP5IBe.mZV4AAAEeketX3uQi&amp;ProductID=DY5IBe.ogAkAAAEdcjBGb7Et&amp;FileName=/jdk-6u11-windows-i586-p.exe">下载地址在这里</a>。我给出的链接是JDK 6 Update 11 for Win版本。</p>
<p>先安装JRE（或者JDK），然后再安装NetBeans <a href="http://sexywp.com/tags/ide" class="st_tag internal_tag" rel="tag" title="标签 IDE 下的日志">IDE</a> 6.5。下面的图是NetBeans装好启动后的样子。</p>
<p><a href="http://picasaweb.google.com/lh/photo/VM7-kFI4WBZdSutP-wArPg?feat=embedwebsite"><img src="http://lh6.ggpht.com/_QYicOeu89Bk/SXNb1hh4a7I/AAAAAAAABBU/cfCq3tgTPc0/s400/NetBeans-02.png" /></a></p>
<h3>将WordPress导入到NetBeans中</h3>
<p>要开发WordPress的插件和主题，需要将整个WordPress作为项目导入到NetBeans中。</p>
<p><a href="http://picasaweb.google.com/lh/photo/VdQQf2p0P-5QqGY1AHJuBQ?feat=embedwebsite"><img src="http://lh6.ggpht.com/_QYicOeu89Bk/SXNb11gLmJI/AAAAAAAABBc/QSYA8anbB2Q/s400/NetBeans-03.png" /></a></p>
<p>步骤1：选择项目。“<strong>文件->新建项目</strong>”，然后选择PHP项目里的“<strong>基于现有源代码的PHP应用程序</strong>”。</p>
<p><a href="http://picasaweb.google.com/lh/photo/_huaRF-0nzBtKkX57MHESA?feat=embedwebsite"><img src="http://lh4.ggpht.com/_QYicOeu89Bk/SXNb2AhYMPI/AAAAAAAABBk/gY9mJReyGm8/s400/NetBeans-04.png" /></a></p>
<p>步骤2：名称和位置。在源文件夹中填入本地WordPress所在的目录。填入项目名称，可随意。其他如上图所示即可。</p>
<p><a href="http://picasaweb.google.com/lh/photo/72StQpojQH-gZu8N1eTTsw?feat=embedwebsite"><img src="http://lh6.ggpht.com/_QYicOeu89Bk/SXNb2KbK0GI/AAAAAAAABBs/dpvS7jvyI9M/s400/NetBeans-05.png" /></a></p>
<p>步骤3：运行配置。填入项目URL即可，为了在本地调试，一般会填入本地地址如http://localhost/wp27/。其他如上图所示。</p>
<h3>使用XDebug进行调试</h3>
<p>NetBeans支持PHP的调试。调试功能需要XDebug的支持，这是一个PHP扩展，你的服务器上可能已经装了，也可能没有装，不过，安装起来非常方便，对于Windows下的用户来说，只是下载一个DLL文件，然后拷贝到指定的目录即可。</p>
<ol>
<li>到<a href="http://www.xdebug.org/">这里</a>下载XDebug，注意匹配DLL与PHP的版本号。在链接里的网页上，点击obtaining，进入下载页面，鼠标放在下载链接上，可以在状态栏看到将要下载的文件名。php_xdebug-2.0.x-5.x.x-xxx.dll，后面一个是PHP的版本号，要与你安装的版本相符合。（PHP版本可以用phpinfo()来查看）</li>
<li>下载后，将DLL文件拷贝到PHP扩展文件夹，一般是/php/ext/下面。</li>
<li>修改php.ini文件，这个文件的所在一般取决你php是怎么安装的，可能在system32里（bin安装的用户），也可能在php根目录下（使用zip安装的），也可能在apache/bin/目录里（使用xampp的用户），注意，一定要找到起作用的那个php.ini，这个也可以在phpinfo()里面看。添加下面的代码。</li>
<div class="hl-surround"><div class="hl-main"><span style="color: Gray;">[xdebug]<br />zend_extension_ts=&quot;D:/xamp/php/php5.2.5/ext/php_xdebug.dll&quot;<br />xdebug.remote_enable=On<br />xdebug.remote_host=&quot;localhost&quot;<br />xdebug.remote_port=9000<br />xdebug.remote_handler=&quot;dbgp&quot;</span></div></div>
<li>注意：上面的代码段，可能php.ini里已经有了，而是被注释掉了，那么你去掉上述那几行字的注释就可以了。另一个注意点，[xdebug]段的配置和[zend]段的配置不能共存，否则apache启动不了，添加了上述代码，如果启动不了apache，那么查找是否存在[zend]段的配置，然后注释掉，我是XAMPP安装的环境，就碰到了这个问题。</li>
<li>重启WebServer。</li>
</ol>
<p>做过上述操作后，NetBeans就可以感知到调试器的存在了。</p>
<h3>一般项目开发</h3>
<p>我们已经将wp2.7的所有文件都导入到了NetBeans里面，那么具体开发一个插件项目，或者主题项目的时候，我们可以在项目面板上，将某个插件的根目录，或者某个主题的根目录使用如下方法添加到收藏夹，以后就在收藏夹面板下工作即可。</p>
<p><a href="http://picasaweb.google.com/lh/photo/hhddQGqFo5spU-RHEYu5EA?feat=embedwebsite"><img src="http://lh6.ggpht.com/_QYicOeu89Bk/SXQm5QcgZgI/AAAAAAAABCI/LschHqVw95s/s400/NetBeans-06.png" /></a></p>
<p>收藏夹完全可以充当项目开发面板的工作。下图就是添加后的效果。</p>
<p><a href="http://picasaweb.google.com/lh/photo/yxGkDHD97csGUsjQq-1wsw?feat=embedwebsite"><img src="http://lh4.ggpht.com/_QYicOeu89Bk/SXQm5R7KO3I/AAAAAAAABCQ/eCJGK5dmT44/s400/NetBeans-07.png" /></a></p>
<h3>配置项目运行</h3>
<p>一般，调试主题或者插件，都是某个特定的页面，比如归档页面，静态页面，或者某个单篇日志页面。如果只是主页，那么默认的设置即可了，如果不是主页，那么需要指定启动参数。大家可能习惯了修改永久链接后的WP的页面地址了，但是那个在调试环境下行不通，必须还原到query string的模式。</p>
<p><a href="http://picasaweb.google.com/lh/photo/h1f6Q97r497VcvVsjDqEiw?feat=embedwebsite"><img src="http://lh6.ggpht.com/_QYicOeu89Bk/SXQm5s9b7WI/AAAAAAAABCY/3Q46QF5Ep90/s288/NetBeans-08.png" /></a></p>
<p>从上图菜单中打开对话框，配置方式如下：</p>
<p><a href="http://picasaweb.google.com/lh/photo/h3NjHTgKkJieuN0igO050w?feat=embedwebsite"><img src="http://lh5.ggpht.com/_QYicOeu89Bk/SXQm51I5xvI/AAAAAAAABCg/xKcJIjLmt5Q/s400/NetBeans-09.png" /></a></p>
<p>注意上图中红色框框里的部分，这个例子就是指定显示id为289的页面或者日志。</p>
<p>设置好运行设置，调试时也会使用这个参数。</p>
<p>调试的时候从调试菜单进去，打开调试对话框，如果只需要调试PHP的话，选第一项，如果还需要调试Javascript的话，选第二项，可以选择你喜欢的浏览器。（有些平台上不能选，Win上面没有问题）</p>
<p><a href="http://picasaweb.google.com/lh/photo/oiZKeAf0OYTcBYbDGQC_vw?feat=embedwebsite"><img src="http://lh4.ggpht.com/_QYicOeu89Bk/SXQr9cJq2pI/AAAAAAAABC4/VKmLbv8P5Lw/s400/NetBeans-10.png" /></a></p>
<p>使用FF，初次选择Javascript调试，会要求安装一个FF插件，装上即可。</p>
<p>好了，作为一个简要的介绍，就写到这里了。</p>
<p>后记：上述内容，并非完全翻译，只是遵循了原文的条理，大部分内容都是我个人的感受和体验，当然，图也是我自己重新截取的。NetBeans作为一款PHP的开发工具，与Eclipse版本的ZendStudio相比，更加的平易近人，比较简单，没有很多复杂的选项，与UEStudio相比，智能化更强，集成的功能更丰富，而且可以和浏览器联调。</p>
<p>这两天，都在使用NetBeans作为环境开发插件，觉得真的很不错。尤其是在WP下，NetBeans会自动对所有代码文件建立索引，你在某个函数上单击，该函数会被高亮，然后用Ctrl+B或者右键菜单，可以直接跳到函数的声明，非常的方便。仅有的一个小缺点是，NetBeans无法对PHP内建函数使用有区别的高亮颜色，不过大家对PHP的内建函数应该也比较熟悉了，再加上，你在内建函数上Ctrl+B，也可以跳到一个类似C语言H文件的文件里，可以直接查看这个内建函数的函数头和说明，都省了查阅手册的时间，也算是弥补了那个小缺点。</p>
<p>还有一点我比较欣赏的，就是NetBeans支持代码重构，可以自动格式化，支持javadoc格式的注释风格，使用这个编辑器可以创建非常优美的注释格式。最后，这个基于java的IDE当然也是跨平台的，以后可以一直用下去了，嘿嘿~~</p>
<p>赶快试试吧！祝大家新年好运~~</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="[WP开发环境]在NetBeans中配置FTP" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-ftp-in-netbeans.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">[WP开发环境]在NetBeans中配置FTP</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（08）---构建一个WordPress插件用户面板" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-08.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/26/9637574.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（08）---构建一个WordPress插件用户面板</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--(02)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-02.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--(02)</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress:插件开发API（Plugin API）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-plugin-api.htm&from=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress:插件开发API（Plugin API）</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/debug" title="debug" rel="tag">debug</a>, <a href="http://sexywp.com/tags/development" title="development" rel="tag">development</a>, <a href="http://sexywp.com/tags/ide" title="IDE" rel="tag">IDE</a>, <a href="http://sexywp.com/tags/netbeans" title="NetBeans" rel="tag">NetBeans</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/use-netbeans-to-develop-wp.htm/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>使用Google AJAX Libraries API替换WordPress自带的js库</title>
		<link>http://sexywp.com/replace-the-wp-js-lib-by-googleapi.htm</link>
		<comments>http://sexywp.com/replace-the-wp-js-lib-by-googleapi.htm#comments</comments>
		<pubDate>Sat, 18 Oct 2008 09:09:53 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[advanced topics]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[usage]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=249</guid>
		<description><![CDATA[为了使用方便，WordPress系统内部已经带有了很多的js类库，几乎涵盖了目前市面上流行的所有类库。包括jQuery，prototype，scriptaculous，thickbox等等等等，这些类库用到的重要的插件，也带了不少，到底有多少呢？大家可以去/wp-includes/js目录下查看。

WordPress自带的这些js类库有个弊端，就是基本上都没有经过minify和zip（这两部操作的作用，就是将js代码的体积，尽可能减到最小，以加快下载速度），所以引用WordPress自己的js类库，往往会浪费很多流量（比如，没有zip过的jquery有30KB，prototype有122KB，而压缩过后，jquery只有17KB，prototype只有28KB）。

<span class="readmore"><a href="http://sexywp.com/replace-the-wp-js-lib-by-googleapi.htm" title="使用Google AJAX Libraries API替换WordPress自带的js库">Keep Reading --- 1758 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p><img src="http://lh6.ggpht.com/_QYicOeu89Bk/SRKlFRbGXUI/AAAAAAAAA2Q/AwVseiUy1sE/s288/googlecode.png" alt="google code logo" style="float:left;margin:10px 15px" /><br />
为了使用方便，WordPress系统内部已经带有了很多的js类库，几乎涵盖了目前市面上流行的所有类库。包括jQuery，prototype，scriptaculous，thickbox等等等等，这些类库用到的重要的插件，也带了不少，到底有多少呢？大家可以去/wp-includes/js目录下查看。</p>
<p>WordPress自带的这些js类库有个弊端，就是基本上都没有经过minify和zip（这两部操作的作用，就是将js代码的体积，尽可能减到最小，以加快下载速度），所以引用WordPress自己的js类库，往往会浪费很多流量（比如，没有zip过的jquery有30KB，prototype有122KB，而压缩过后，jquery只有17KB，prototype只有28KB）。</p>
<p><span id="more-249"></span><br />
<h3>我是否使用了类库？</h3>
<p>WordPress是一个灵活的系统，用户可以通过插件扩展系统的功能，所以，一个博客上是否使用了某个类库，取决于你博客用到的所有的插件对类库的使用情况。如果你想看看自己到底使用了哪些，你可以用一个简便的办法，就是查看源文件。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">&lt;script type='text/javascript' src='http://localhost/wp25/wp-includes/js/jquery/jquery.js?ver=1.2.3'&gt;&lt;/script&gt;</li></ol></div>
<p>看上面的代码，是我模板中的一段代码，类似这个样子的就是对类库的引用了。这是我的本地调试系统，使用的是wp2.5.1，引用到了jQuery类库，版本1.2.3。</p>
<p>如果你看到了类似“xxxxxxxxxxxxxwp-includesjsxxxxxxxx?ver=xxxxxx”的字符串，那么，你的博客里，调用了类库。</p>
<h3>使用Google AJAX Libraries API</h3>
<p>什么是Google AJAX Libraries API（GALA）？使用它有什么好处？简单来说，Google是个很牛X的公司，很乐意做好事，它专门优化了这些类库，包括代码精简，压缩，然后用高性能地服务器来Host这些类库，供用到的网站调用，帮助这些网站节省流量。我爱水煮鱼写了个小短文，介绍过这个，大家可以看看（<a href="http://fairyfish.net/2008/05/29/google-ajax-libraries-api/">点这里</a>）。Google为什么做这种事情？好吧，这个问题，我不知道。</p>
<h3>怎样用GALA来替换WordPress自带的类库？</h3>
<p>关于这一点，首先我想说说WordPress对于引用脚本的一些机制，那就是scripts loader。这是个什么东西呢？一句话：对于博客使用到的所有脚本，进行统一的管理的一个装置。这个装置是怎么管理的呢？首先，所有的脚本登记注册，包括名称，路径，版本号，依赖关系，一一详细记录。然后，是对脚本的调用，通过这套系统来调用。最后，由系统负责把所有需要用到的脚本，无重复的，满足依赖关系的，满足前后顺序的，有条不紊的加入到你的最终的博客页面里面。怎么样？是不是非常酷？<strong>不过呢，总是有“不过”，这种秩序高度依赖模板作者和插件作者的自觉性。</strong></p>
<p>好吧，我们的方法不得不建立在所有的模板作者和插件作者都自觉使用scripts loader系统的基础上。在这种情况下，一个模板或者插件使用到某个类库，会使用wp_enqueue_script函数来调用需要的类库，使用这个方法，一般不会直接指明类库的路径，只是说明类库的版本号和依赖关系（因为，WP默认就会给所有wp-includes/js目录下的类库进行登记register）。</p>
<p>发现又废了很多话，到这里，我们的替换方法，已经呼之欲出了，因为所有的类库引用都是对已登记的类库的调用（建立在我的假设之上），所以，我如果想要替换，那么只要替换登记在册的那个名单就OK了，完全跳过了去修改每个有可能引用到类库的插件这种繁琐的事情。而且，WordPress确实提供了能够替换那个名单的方法。使用wp_deregister_script可以注销一个脚本，然后使用wp_register_script可以重新注册一个脚本。用这个办法，我们可以把wp自己注册的脚本给注销掉，然后换成GALA的，重新注册，就OK了。</p>
<p>根据WordPress的源代码显示，所有类库的引用，是在最后页面生成的时候才真正进行的，准确一点并且专业一点来说，是在wp_head这个action发生的时候，对类库的引用才通过wp_print_scripts函数写入到页面里面。我们的替换动作只要在此之前完成就OK，所以，我们把替换这件事情，写到functions.php里面，当然，更好的做法，是使用一个单独的插件里。</p>
<p>具体的写法，我曾经在侠姐的文章里见过，大家可以去看看，我就不想进行重复劳动了。<a href="http://www.e-xia.com/2008/06/js_call_in_wordpress/">《wordpress里js文件的调用》from 轶侠的网上小窝</a></p>
<p>有没有学习写插件的小朋友写个干这个事情的插件呢？亲爱的读者，如果你写了，请告诉我，我会把你的作品列在下面的。</p>
<p>Updated:</p>
<p>经由侠姐提出，如果直接替换掉WP自带的js类库可能会在后台造成冲突而导致某些功能失灵（比如Simple Tags的标签推荐功能，详情可见讨论），不得不在使用的做出一定的修正。</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"><br /></span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">replace the jQuery instance with google api</span><span style="color: #ffa500;"></span><span style="color: Gray;"><br /></span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">is_admin</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">wp_deregister_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">jquery</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">wp_register_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">jquery</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Green;">false</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">1.2.6</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">wp_enqueue_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">jquery</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Green;">false</span><span style="color: Gray;">, </span><span style="color: Green;">false</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">1.2.6</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: Olive;">}</span><span style="color: Gray;"><br /></span><span style="color: Blue;">?&gt;</span></div></div>
<p>通过is_admin()标签，可以将前后台区别对待。但是这种情况还不能涵盖所有的例外，如果某个插件正好引用了prototype或者jquery，并且正好利用了WP对齐进行的无冲突修正，那么以上方法可能导致部分功能失灵。有经验的用户可以酌情使用。</p>
<p>Updated2：</p>
<p>经小墨提醒，已经找到了一个这样的插件的实例了。我看了代码，是利用了两个hook，一个是我说过的wp_print_script，这个hook用来探测jQuery和prototype是否同时存在，然后解决冲突问题，另一个是script_loader_src，用来替换里面的src地址，并指向到google提供的js库。不过，我个人觉得，这个方法很可能还是不能完美解决后台的类库冲突问题，但是我没有验证过。</p>
<p>插件主页：</p>
<p>http://blog.clearskys.net/2008/05/28/<a href="http://sexywp.com/tags/google" class="st_tag internal_tag" rel="tag" title="标签 google 下的日志">google</a>-ajax-libraries-api-plugin/</p>

	标签：<a href="http://sexywp.com/tags/advanced-topics" title="advanced topics" rel="tag">advanced topics</a>, <a href="http://sexywp.com/tags/google" title="google" rel="tag">google</a>, <a href="http://sexywp.com/tags/usage" title="usage" rel="tag">usage</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/replace-the-wp-js-lib-by-googleapi.htm/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>WordPress插件开发实例--(02)</title>
		<link>http://sexywp.com/real-wp-plugins-02.htm</link>
		<comments>http://sexywp.com/real-wp-plugins-02.htm#comments</comments>
		<pubDate>Thu, 21 Aug 2008 03:16:14 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=222</guid>
		<description><![CDATA[插件源于需求。&#8212;&#8212;Charles

我有一个私人博客，目前使用的WordPress的development version，该版本可以提供WordPress的一键升级。各位WPer应该是有福了，不过呢，这个一键升级，却给我带来一点小麻烦。



<span class="readmore"><a href="http://sexywp.com/real-wp-plugins-02.htm" title="WordPress插件开发实例--(02)">Keep Reading --- 358 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>插件源于需求。&#8212;&#8212;Charles</p>
<p>我有一个私人博客，目前使用的WordPress的development version，该版本可以提供WordPress的一键升级。各位WPer应该是有福了，不过呢，这个一键升级，却给我带来一点小麻烦。</p>
<p><span id="more-222"></span>
<p>我选用了default主题，而这个主题是WP的一部分，所以，每当一键升级的时候，就会使得我自定义的样式被覆盖&gt;.&lt; ，太糟糕了。两次，粗心大意，我于是乎决定，开发个插件，摆平它！</p>
<p>其实很简单的啦。上次，我们使用了一个filter，还记得不，是the_content。这次，正好，我们就用到了一个action。这个action叫做wp_head，是在模板的header.php加载接近结束时候触发的，具体位置视模板不同而有所不同。但是，有一点是确定的，就是wp_head，会在&lt;/head&gt;标签之前被触发。</p>
<p>这个action的作用，就是专门在模板中添加插件需要使用的css或者javascript文件的。正好，我利用这个action，将我自己的自定义css文件给插入到当前使用的模板中。</p>
<p>贴点代码吧 <img src='http://sexywp.com/cc/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /> </p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"><br /></span><span style="color: #ffa500;">/*</span><span style="color: #ffa500;"><br />Plugin Name: Insert Custom CSS<br />Plugin URI: </span><span style="color: Blue;">http://sexywp.com/insert-custom-css.htm</span><span style="color: #ffa500;"><br />Description: This plugin will insert a custom css file to your current theme.<br />Version: 8.8.21<br />Author: Charles Tang<br />Author URI: </span><span style="color: Blue;">http://sexywp.com/</span><span style="color: #ffa500;"><br /></span><span style="color: #ffa500;">*/</span><span style="color: Gray;"><br />&nbsp;<br /></span><span style="color: #ffa500;">/*</span><span style="color: #ffa500;">&nbsp; <br />&nbsp;&nbsp; &nbsp;Copyright 2008&nbsp; Charles Tang&nbsp; (email : )<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;This program is free software; you can redistribute it and/or modify<br />&nbsp;&nbsp; &nbsp;it under the terms of the GNU General Public License as published by<br />&nbsp;&nbsp; &nbsp;the Free Software Foundation; either version 2 of the License, or<br />&nbsp;&nbsp; &nbsp;(at your option) any later version.<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;This program is distributed in the hope that it will be useful,<br />&nbsp;&nbsp; &nbsp;but WITHOUT ANY WARRANTY; without even the implied warranty of<br />&nbsp;&nbsp; &nbsp;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&nbsp; See the<br />&nbsp;&nbsp; &nbsp;GNU General Public License for more details.<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;You should have received a copy of the GNU General Public License<br />&nbsp;&nbsp; &nbsp;along with this program; if not, write to the Free Software<br />&nbsp;&nbsp; &nbsp;Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA&nbsp; 02111-1307&nbsp; USA<br /></span><span style="color: #ffa500;">*/</span><span style="color: Gray;"><br />&nbsp;<br /></span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">insert_custom_css</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: #00008b;">$css_url</span><span style="color: Gray;"> = </span><span style="color: Blue;">WP_CONTENT_URL</span><span style="color: Gray;"> . </span><span style="color: #8b0000;">'</span><span style="color: Red;">/plugins/insert-custom-css/style.css</span><span style="color: #8b0000;">'</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">echo</span><span style="color: Gray;"> </span><span style="color: #8b0000;">'</span><span style="color: Red;">&lt;link rel=&quot;stylesheet&quot; href=&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> . </span><span style="color: #00008b;">$css_url</span><span style="color: Gray;"> . </span><span style="color: #8b0000;">'</span><span style="color: Red;">&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">;<br /></span><span style="color: Olive;">}</span><span style="color: Gray;"><br /></span><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_head</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">insert_custom_css</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;<br /></span><span style="color: Blue;">?&gt;</span></div></div>
<p>很简短吧，真正的代码只有四行噢~~</p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/real-wp-plugins-02.htm/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（目录）</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-contents.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-contents.htm#comments</comments>
		<pubDate>Sun, 06 Jul 2008 03:33:58 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=114</guid>
		<description><![CDATA[隔了这么久，终于将这个系列文章都翻译完了，这么一遍走下来，实在觉得自己很浅薄，技术和语言水平都十分有限。恐怕也没有全部传达原作者的意图。

我打算陆续将该系列的文章校对一遍，并且打算将这个系列里面的例子改写成自己的例子，这样，我可以对文章有更准确的理解。



<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-contents.htm" title="插件开发全攻略（目录）">Keep Reading --- 308 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>隔了这么久，终于将这个系列文章都翻译完了，这么一遍走下来，实在觉得自己很浅薄，技术和语言水平都十分有限。恐怕也没有全部传达原作者的意图。</p>
<p>我打算陆续将该系列的文章校对一遍，并且打算将这个系列里面的例子改写成自己的例子，这样，我可以对文章有更准确的理解。</p>
<p><span id="more-114"></span></p>
<p>这里，我罗列一下这个系列文章的目录吧。英文名字就是原文，底下的中文名字就是译文。</p>
<ol>
<li><a href="http://www.devlounge.net/articles/how-to-write-a-wordpress-plugin-introduction">How to Write a WordPress Plugin - Introduction</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-01.htm">介绍</a></li>
<li><a href="http://www.devlounge.net/articles/seven-reasons-to-write-a-wordpress-plugin">Seven Reasons to Write a WordPress Plugin</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-02.htm">编写插件的七个理由</a></li>
<li><a href="http://www.devlounge.net/articles/how-to-get-ideas-for-wordpress-plugins">How to Get Ideas for WordPress Plugins</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-03.htm">怎样获得WordPress插件的创意</a></li>
<li><a href="http://www.devlounge.net/articles/structure-of-a-wordpress-plugin">Structure of a WordPress Plugin</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-04.htm">WordPress插件的结构</a></li>
<li><a href="http://www.devlounge.net/articles/wordpress-plugin-actions">WordPress Plugin Actions</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-05.htm">WordPress 插件Actions</a></li>
<li><a href="http://www.devlounge.net/articles/wordpress-plugin-filters">WordPress Plugin Filters</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-06.htm">WordPress插件Filter</a></li>
<li><a href="http://www.devlounge.net/articles/constructing-an-wordpress-plugin-admin-panel">Constructing a WordPress Plugin Admin Panel</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-07.htm">构造一个WordPress插件管理员面板</a></li>
<li><a href="http://www.devlounge.net/articles/constructing-a-wordpress-plugin-users-panel">Constructing a WordPress Plugin User&#8217;s Panel</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-08.htm">构建一个WordPress插件用户面板</a></li>
<li><a href="http://www.devlounge.net/articles/wordpress-plugins-and-database-interaction">WordPress Plugins and Database Interaction</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-09.htm">WordPress插件和数据库交互</a></li>
<li><a href="http://www.devlounge.net/articles/using-javascript-and-css-with-your-wordpress-plugin">Using JavaScript and CSS with your WordPress Plugin</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-10.htm">在你的WordPress插件中使用Javascript和CSS</a></li>
<li><a href="http://www.devlounge.net/articles/using-ajax-with-your-wordpress-plugin">Using AJAX with your WordPress Plugin</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-11.htm">在你的WP插件中使用AJAX</a></li>
<li><a href="http://www.devlounge.net/articles/releasing-and-promoting-your-wordpress-plugin">Releasing and Promoting Your WordPress Plugin</a></li>
<li><a href="http://sexywp.com/how-to-write-a-wp-plugin-12.htm">发布并推广你的WordPress插件</a></li>
</ol>
<p>原来的目录页面在：<a href="http://www.devlounge.net/extras/how-to-write-a-wordpress-plugin">这里</a></p>
<p>还提供PDF版本的下载哦。</p>
<p><a href="http://www.box.net/shared/n7urk9zuxi">中文版PDF下载（2008年12月22日11:57:51）</a></p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-contents.htm/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略(11)---在你的WP插件中使用AJAX</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-11.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-11.htm#comments</comments>
		<pubDate>Tue, 01 Jul 2008 05:41:23 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=106</guid>
		<description><![CDATA[越来越多的插件开始使用AJAX技术。我个人并没有在大多数的插件中看到过AJAX，但是使用AJAX来完成某个任务对你的插件来说可能是必要的。这篇文章将像你展示怎样在你的插件中使用AJAX。

这篇文章将在上一篇文章《在插件中添加js和css》的基础上继续。



<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-11.htm" title="插件开发全攻略(11)---在你的WP插件中使用AJAX">Keep Reading --- 852 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>越来越多的插件开始使用AJAX技术。我个人并没有在大多数的插件中看到过AJAX，但是使用AJAX来完成某个任务对你的插件来说可能是必要的。这篇文章将像你展示怎样在你的插件中使用AJAX。</p>
<p>这篇文章将在上一篇文章<a href="http://sexywp.com/how-to-write-a-wp-plugin-09.htm">《在插件中添加js和css》</a>的基础上继续。</p>
<p><span id="more-106"></span></p>
<h3>建立一个新的PHP文件</h3>
<p>Devlounge Plugin Series插件已经有了如下的目录结构了：</p>
<ul>
<li>devloung-plugin-series
<ul>
<li>devlounge-plugin-series.php(main plugin file)</li>
<li>js
<ul>
<li>devlounge-plugin-series.js.php</li>
</ul>
</li>
<li>css
<ul>
<li>devlounge-plugin-series.css</li>
</ul>
</li>
<li>php
<ul>
<li>dl-plugin-ajax.php(新php文件)</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>注意，我的javascript文件的扩展名是<strong>php</strong>。我会在这篇文章后面解释这个变化的来历。</p>
<p>我已经建立了一个新的文件，并且把它放到了<strong>php</strong>文件夹中，并且命名为<strong>dl-plugin-ajax.php</strong>。我已经在这个文件中放了如下的代码：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">add_action</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: Green;">require_once</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">../../../../wp-config.php</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">showComments</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>这个段代码非常简单，并且仅为做AJAX调用而写。它确保了配置结构存在，从而我们可以调用类对象<strong>dl_pluginSeries</strong>，引用其他WordPress函数和变量。然而，<strong>showComments</strong>函数还没有创建，我们下一个议程就是来做这件事。</p>
<h3>定义showComments函数</h3>
<p><strong>showComments</strong>函数将放在我们的<strong>DevloungPluginSeries</strong>类中：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">showComments</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">global</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$wpdb</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: #00008b;">$devloungecomments</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$wpdb</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">get_row</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">SELECT count(comment_approved) comments_count FROM </span><span style="color: #00008b;">$wpdb</span><span style="color: Red;">-&gt;comments where comment_approved = '1' group by comment_approved</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: Blue;">ARRAY_A</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: Green;">echo</span><span style="color: Gray;">&nbsp;</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">You have </span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;"> . </span><span style="color: #00008b;">$devloungecomments</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">comments_count</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> . </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;"> comments on your blog</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>可能已经认出来了，这段代码在数据库交互这篇文章中出现过。此函数输出你博客上留言的数量。</p>
<h3>让JavaScript知道你的博客在哪里</h3>
<p>使用AJAX时，一个烦人的事情就是外部JavaScript文件不知道你博客安装路径是什么。我是通过在js后面添加php扩展名来处理这个问题的，因为这样，我就可以调用WordPress函数了。在<strong>addHeaderCode</strong>函数中，我把代码从：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_enqueue_script</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">wp_enqueue_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">devlounge_plugin_series</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Blue;">get_bloginfo</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wpurl</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> . </span><span style="color: #8b0000;">'</span><span style="color: Red;">/wp-content/plugins/devlounge-plugin-series/js/devlounge-plugin-series.js</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">prototype</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">0.1</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>换成：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_enqueue_script</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">wp_enqueue_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">devlounge_plugin_seriess</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Blue;">get_bloginfo</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wpurl</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> . </span><span style="color: #8b0000;">'</span><span style="color: Red;">/wp-content/plugins/devlounge-plugin-series/js/devlounge-plugin-series.js.php</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">prototype</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">0.3</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>我唯一改变的是一个版本号码，还有就是给JavaScript文件添加了一个php扩展名。</p>
<h3>编写JavaScript</h3>
<p>这段脚本的目的是找到博客的URL，调用PHP文件，然后返回结果给用户。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&lt;?</span><span style="color: Blue;">php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">add_action</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: Blue;">require_once</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">../../../../wp-config.php</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;?&gt;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">Event</span><span style="color: Gray;">.</span><span style="color: Blue;">observe</span><span style="color: Olive;">(</span><span style="color: Teal;">window</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">load</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Blue;">devloungePluginSeriesInit</span><span style="color: Gray;">, </span><span style="color: Green;">false</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">devloungePluginSeriesInit</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;    $</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">devlounge-link</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">.</span><span style="color: Blue;">onclick</span><span style="color: Gray;"> = </span><span style="color: Blue;">devloungePluginSeriesClick</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">devloungePluginSeriesClick</span><span style="color: Olive;">(</span><span style="color: Blue;">evt</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: Green;">var</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">url</span><span style="color: Gray;"> =  </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">&lt;?php bloginfo('wpurl') ?&gt;/wp-content/plugins/devlounge-plugin-series/php/dl-plugin-ajax.php</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: Green;">var</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">success</span><span style="color: Gray;"> = </span><span style="color: Green;">function</span><span style="color: Olive;">(</span><span style="color: Blue;">t</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span><span style="color: Blue;">devloungePluginSeriesClickComplete</span><span style="color: Olive;">(</span><span style="color: Blue;">t</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: Green;">var</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">myAjax</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">Ajax</span><span style="color: Gray;">.</span><span style="color: Blue;">Request</span><span style="color: Olive;">(</span><span style="color: Blue;">url</span><span style="color: Gray;">, </span><span style="color: Olive;">{</span><span style="color: Blue;">method</span><span style="color: Gray;">:</span><span style="color: #8b0000;">'</span><span style="color: Red;">post</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Blue;">onSuccess</span><span style="color: Gray;">:</span><span style="color: Blue;">success</span><span style="color: Olive;">}</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">false</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">devloungePluginSeriesClickComplete</span><span style="color: Olive;">(</span><span style="color: Blue;">t</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;    </span><span style="color: Blue;">alert</span><span style="color: Olive;">(</span><span style="color: Blue;">t</span><span style="color: Gray;">.</span><span style="color: Blue;">responseText</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li></ol></div></div>
<p>上述代码做了下面这些事情（记住，我们在使用Prototype）：</p>
<ul>
<li>确定配置结构是存在的，这样我们才能访问WordPress函数</li>
<li>在文档已经装载后，<strong>devloungePluginSeriesInit</strong>函数被调用了</li>
<li>给你添加到文章末尾的链接上绑定了一个事件。如果你忘了，现在可以加进去。简单地找到文章，然后添加这段代码：&lt;a href="#" id="devlounge-link"&gt;Get the Number of Blog Comments&lt;/a&gt;</li>
<li>找到PHP文件的绝对路径</li>
<li>调用PHP文件</li>
<li>将反馈输出给用户</li>
</ul>
<h3>结果</h3>
<p>下一步，我们假设你已经把那个链接添加好了。我们点击链接“<strong>Get the Number of Blog Comments</strong>”，脚本使用AJAX调用了<strong>DevlongePluginSeries</strong>类中的函数，并且以对话框的形式返回了结果。</p>
<p>就如你看到的那样，我的本地安装版本，并没有多少评论。</p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-11.htm/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（10）---在你的WordPress插件中使用Javascript和CSS</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-10.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-10.htm#comments</comments>
		<pubDate>Wed, 25 Jun 2008 13:24:04 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=100</guid>
		<description><![CDATA[现今的许多插件对javascript和层叠样式表依赖更多了。将你插件中的javascript和css放置到分离的文件中是非常重要的，那样做会使插件维护起来更加容易。此系列中的这个部分将介绍怎样在你的插件中加载javascript和CSS文件。



添加你的javascript

<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-10.htm" title="插件开发全攻略（10）---在你的WordPress插件中使用Javascript和CSS">Keep Reading --- 815 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>现今的许多插件对javascript和层叠样式表依赖更多了。将你插件中的javascript和css放置到分离的文件中是非常重要的，那样做会使插件维护起来更加容易。此系列中的这个部分将介绍怎样在你的插件中加载javascript和CSS文件。</p>
<p><span id="more-100"></span></p>
<h3>添加你的javascript</h3>
<p>你的插件可能需要装载prototype类库，或者一个自定义的脚本。这一节将向你展示几个WordPress函数，它们可以帮助你装载脚本，并且避免脚本冲突。</p>
<h4>wp_register_script函数</h4>
<p><strong>wp_register_script</strong>函数允许你注册要调用的脚本，并且允许你设定先决条件。比如说，如果你的脚本需要prototype事先加载，那么你可以通过这个函数来指定。</p>
<p>这里是<strong>wp_register_script</strong>函数的参数：<code>wp_register_script($handle,$src,$deps=array(),$ver=false);</code></p>
<ul>
<li><strong>handle</strong>是一个独一无二的名字，后面会用此名字引用你的脚本。这个参数是必须的。</li>
<li><strong>src</strong>是你的javascript文件的绝对路径。这个参数是必须的。</li>
<li><strong>deps</strong>是一个依赖数组。比如说，如果你的脚本需要使用prototype，你要把它罗列在这里。这个参数是可选的。</li>
<li><strong>ver</strong>是一个字符串，标明了脚本的版本。这个变量是可选的。</li>
</ul>
<p>举个例子，如果你有一个脚本要装载：<em>http://yourdomain.com/wp-content/<a href="http://sexywp.com/tags/plugins" class="st_tag internal_tag" rel="tag" title="标签 plugins 下的日志">plugins</a>/your-plugin-directory/js/script.js</em></p>
<p>让我们做一些假设：</p>
<ul>
<li>你希望handle的名字为“my_script_handle”。</li>
<li>你的脚本依赖于prototype类库</li>
<li>你的版本是1.0</li>
</ul>
<p>你将在你的插件代码初始化调用那个函数，或者在<strong>wp_head</strong> action之后调用：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">wp_register_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">my_script_handle</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">http://yourdomain.com/wp-content/plugins/your-plugin-directory/js/script.js</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">prototype</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
<h4>wp_enqueue_script函数</h4>
<p><strong>wp_enqueue_script</strong>函数除了<strong>src</strong>参数是可选的以外，其他与<strong>wp_register_script</strong>是一样的。如果提供一个<strong>src</strong>，入队函数会<em>自动地注册</em>脚本，因此使用<strong>wp_register_script</strong>函数并不是必须的。然而，<strong>wp_register_script</strong>函数允许你手动注册你的脚本，这样，你可以仅使用一次<strong>wp_enqueue_script</strong>函数就将你所有的脚本装载。</p>
<p>如果我们像上一个例子中那样调用脚本，那么看起来像下面的样子：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">wp_enqueue_script</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">my_script_handle</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">http://yourdomain.com/wp-content/plugins/your-plugin-directory/js/script.js</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">prototype</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
<h3>一个javascript的例子</h3>
<p>对于Devlounge Plugin Series插件，我们将添加一个javascript文件，后面的文章中会用它。使用这个文件的目的，就是为了说明怎样使用<strong>wp_enqueue_script</strong>函数。</p>
<ul>
<li>文件将会放下下列地址：http://yourdomain.com/wp-content/plugins/devlounge-plugin-series/js/devlounge-plugin-series.js</li>
<li>这个文件依赖于prototype</li>
<li>版本是1.0</li>
</ul>
<p>你可能会回忆起，这个系列文章早期的一篇文章中，我们添加了一个action叫<strong>wp_head</strong>。那个action添加后，会调用一个函数，叫做<strong>addHeaderCode</strong>。让我们来修改这个函数，添加我们新的javascript：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">function addHeaderCode() {</span></li>
<li><span style="color: Gray;">&nbsp;            if (function_exists('wp_enqueue_script')) {</span></li>
<li><span style="color: Gray;">&nbsp;                wp_enqueue_script('devlounge_plugin_series', get_bloginfo('wpurl') . '/wp-content/plugins/devlounge-plugin-series/js/devlounge-plugin-series.js', array('prototype'), '0.1');</span></li>
<li><span style="color: Gray;">&nbsp;            }</span></li>
<li><span style="color: Gray;">&nbsp;            $devOptions = $this-&gt;getAdminOptions();</span></li>
<li><span style="color: Gray;">&nbsp;            if ($devOptions['show_header'] == &quot;false&quot;) { return; }</span></li>
<li><span style="color: Gray;">&nbsp;            ?&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;!-- Devlounge Was Here --&gt;</span></li>
<li><span style="color: Gray;">&nbsp;            </span><span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;}</span></li></ol></div></div>
<p>上述代码的工作如下：</p>
<ul>
<li> 首先，检查<strong>wp_enqueue_script</strong>函数的存在性</li>
<li> 然后调用该函数 </li>
<li> 我们使用<strong> get_bloginfo('wpurl') </strong> 来得到WordPress安装根目录，然后手写路径中剩下的部分 </li>
</ul>
<h3>加载层叠样式表</h3>
<p>我已经往我的样式目录里面添加了一个新的样式表。这里是我们的一些前提：</p>
<ul>
<li> 这个文件存储在下列位置：http://yourdomain.com/wp-content/plugins/devlounge-plugin-series/css/devlounge-plugin-series.css </li>
<li> 我在这个CSS文件中指定了一个ID叫做#devlounge-link </li>
<li> <strong> 你已经添加了下面的代码 </strong> 在文章的末尾：&lt;a href="#" id="devlounge-link"&gt;取得博客留言的数量&lt;/a&gt;</li>
</ul>
<p>在样式表文件中，我已经添加了下面的ID：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">#devlounge-link</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">background-color:</span><span style="color: #00008b;">#006</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">color:</span><span style="color: #00008b;">#fff</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li></ol></div></div>
<p>在插件中添加样式表，就和在<strong>addHeaderCode</strong>函数中添加一行代码一样简单：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">function addHeaderCode() {</span></li>
<li><span style="color: Gray;">&nbsp;            echo '&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;' . get_bloginfo('wpurl') . '/wp-content/plugins/devlounge-plugin-series/css/devlounge-plugin-series.css&quot; /&gt;' . &quot;\n&quot;;</span></li>
<li><span style="color: Gray;">&nbsp;            if (function_exists('wp_enqueue_script')) {</span></li>
<li><span style="color: Gray;">&nbsp;                wp_enqueue_script('devlounge_plugin_series', get_bloginfo('wpurl') . '/wp-content/plugins/devlounge-plugin-series/js/devlounge-plugin-series.js', array('prototype'), '0.1');</span></li>
<li><span style="color: Gray;">&nbsp;            }</span></li>
<li><span style="color: Gray;">&nbsp;            $devOptions = $this-&gt;getAdminOptions();</span></li>
<li><span style="color: Gray;">&nbsp;            if ($devOptions['show_header'] == &quot;false&quot;) { return; }</span></li>
<li><span style="color: Gray;">&nbsp;            ?&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;!-- Devlounge Was Here --&gt;</span></li>
<li><span style="color: Gray;">&nbsp;            </span><span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;}</span></li></ol></div></div>
<p>在第2行，我只是简单地打印出了新的样式表。</p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-10.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（08）---构建一个WordPress插件用户面板</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-08.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-08.htm#comments</comments>
		<pubDate>Sun, 22 Jun 2008 10:16:20 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=98</guid>
		<description><![CDATA[将会有这么一种情况，你将有一个主要的管理面板，但是希望能够让独立的用户设定他们自己的偏好。在Devlounge Plugin Series这个例子中，我们添加了一个是否把文字添加到文章末尾的选项。然而，假如一个登录用户不希望看到这段文字呢？为什么不给他们一个选择，而且不影响到所有其他的用户呢？



这篇文章将会涉及到这个问题，让你可以添加你自己的用户面板。

<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-08.htm" title="插件开发全攻略（08）---构建一个WordPress插件用户面板">Keep Reading --- 1020 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>将会有这么一种情况，你将有一个主要的管理面板，但是希望能够让独立的用户设定他们自己的偏好。在Devlounge Plugin Series这个例子中，我们添加了一个是否把文字添加到文章末尾的选项。然而，假如一个登录用户不希望看到这段文字呢？为什么不给他们一个选择，而且不影响到所有其他的用户呢？</p>
<p><span id="more-98"></span></p>
<p>这篇文章将会涉及到这个问题，让你可以添加你自己的用户面板。</p>
<p><img src="http://lh5.ggpht.com/TangChao.ZJU/SF4i2dd9kRI/AAAAAAAAAdE/ZJZK2Lt6P-M/s800/users-panel.gif" style="border:none;clear:both;margin:15px auto;"/></p>
<h3>命名你的选项</h3>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">class</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">DevloungePluginSeries</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">var</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$adminOptionsName</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeriesAdminOptions</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">var</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$adminUsersName</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeriesAdminUsersOptions</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>第3行显示，我添加了一个成员函数，叫做<strong>adminUsersName</strong>。我给这个变量取了一个长而且独特的名字<strong>DevloungePluginSeriesAdminUsersOptions</strong>。</p>
<h3>设定你的缺省用户选项</h3>
<p>你将需要一个地方来初始化你的选项，尤其是当一个用户第一次激活了你的插件的时候。然而，这些选项在管理面板之外也应该起作用，不论用户是登录了还是没有登录。</p>
<p>这里是一个我引入到<strong>DevloungePluginSeries</strong>类中的函数：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Returns an array of user options</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">getUserOptions</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">global</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$user_email</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Green;">empty</span><span style="color: Olive;">(</span><span style="color: #00008b;">$user_email</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">get_currentuserinfo</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Green;">empty</span><span style="color: Olive;">(</span><span style="color: #00008b;">$user_email</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: #8b0000;">'</span><span style="color: #8b0000;">'</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$devOptions</span><span style="color: Gray;"> = </span><span style="color: Blue;">get_option</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">adminUsersName</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$devOptions</span><span style="color: Gray;"> = </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Green;">empty</span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #00008b;">$user_email</span><span style="color: Olive;">]</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #00008b;">$user_email</span><span style="color: Olive;">]</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">'</span><span style="color: Red;">true,true</span><span style="color: #8b0000;">'</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">update_option</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">adminUsersName</span><span style="color: Gray;">, </span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$devOptions</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>这个函数完成以下任务：</p>
<ul>
<li>检查用户是否已经登陆（3-7行）。这个检查仅需要查看变量user_email是否设定即可。</li>
<li>尝试找到以前存储在数据库中的选项（第8行）。</li>
<li>如果没有找到option，设定默认值（第9-15行）。</li>
<li>返回option供你使用</li>
</ul>
<h3>初始化管理用户option</h3>
<p>可以在任何时候调用getUserOptions来取得用户管理options。然而，那么插件第一次安装的时候呢？应该有某种函数被调用，以取得用户选项。我添加了下面这个函数到init函数:</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">init</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">getAdminOptions</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">getUserOptions</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>第3行调用了新函数getUserOptions。由于已经有了一个action调用了init函数，不需要额外的步骤了。</p>
<h3>怎样使管理面板和用户面板一起工作</h3>
<p>你会回想起上一篇关于<a href="http://sexywp.com/how-to-write-a-wp-plugin-07.htm">设定一个管理面板</a>的文章中，WordPress管理员可以设定文章末尾的内容，代码是否是否在头部显示，评论中的作者名字是否大写。而用户面板允许那些不是管理员的用户有能力设定他们是否希望这些options。</p>
<p>我们将允许用户决定，如果他们：</p>
<ul>
<li>想要内容在文章的末尾显示（仅当管理员启用了这个option）</li>
<li>想要评论作者的名字大写（仅当管理员启用了这个option）</li>
</ul>
<h3>设定用户面板函数</h3>
<p>我们要做的第一件事情就是编写一个函数来显示用户面板。函数名字为printAdminUsersPage。下一段代码将会读入我们早先设定的options并且检查一下是否有任何文章选项已经被提交。这一节中所有的代码都默认包含于printAdminUsersPage函数。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">//Prints out the admin page</span></li>
<li><span style="color: Gray;">&nbsp;function printAdminUsersPage() {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; global $user_email;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; if (empty($user_email)) {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; get_currentuserinfo();</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; }</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; $devOptions = $this-&gt;getUserOptions();</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; //Save the updated options to the database</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; if (isset($_POST['update_devloungePluginSeriesSettings']) &amp;&amp; isset($_POST['devloungeAddContent']) &amp;&amp; isset($_POST['devloungeAuthor'])) {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (isset($user_email)) {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $devOptions[$user_email] = $_POST['devloungeAddContent'] . &quot;,&quot; . $_POST['devloungeAuthor'];</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;updated&quot;&gt;&lt;p&gt;&lt;strong&gt;Settings successfully updated.&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">update_option</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">adminUsersName</span><span style="color: Gray;">, </span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; }</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Get the author options</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$devOptions</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #00008b;">$user_email</span><span style="color: Olive;">]</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$devOptions</span><span style="color: Gray;"> = </span><span style="color: Blue;">explode</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">,</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">sizeof</span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">)</span><span style="color: Gray;">&gt;= </span><span style="color: Maroon;">2</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$content</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: Maroon;">0</span><span style="color: Olive;">]</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$author</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">]</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上述代码：</p>
<ul>
<li>取回用户options（第7行）</li>
<li>存储发送的数据到数据库（第9-18行）</li>
<li>为用户读入用逗号分隔的变量</li>
</ul>
<p>下一段代码将会显示用户面板必须的HTML表单。所有的代码做的事情就是显示表单元素，并且读入已经取得的选项。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&lt;div class=wrap&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;form method=&quot;post&quot; action=&quot;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">echo</span><span style="color: Gray;"> </span><span style="color: #00008b;">$_SERVER</span><span style="color: Olive;">[</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">REQUEST_URI</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">]</span><span style="color: Gray;">; </span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">&quot;&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;h2&gt;Devlounge Plugin Series User Options&lt;/h2&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;h3&gt;Allow Content Added to the End of a Post?&lt;/h3&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;Selecting &quot;No&quot; will disable the content from being added into the end of a post.&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;&lt;label for=&quot;devloungeAddContent_yes&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeAddContent_yes&quot; name=&quot;devloungeAddContent&quot; value=&quot;true&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$content</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">true</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;"> /&gt; Yes&lt;/label&gt;&nbsp; &nbsp; &lt;label for=&quot;devloungeAddContent_no&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeAddContent_no&quot; name=&quot;devloungeAddContent&quot; value=&quot;false&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$content</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">false</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">/&gt; No&lt;/label&gt;&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;h3&gt;Allow Comment Authors to be Uppercase?&lt;/h3&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;Selecting &quot;No&quot; will leave the comment authors alone.&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;&lt;label for=&quot;devloungeAuthor_yes&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeAuthor_yes&quot; name=&quot;devloungeAuthor&quot; value=&quot;true&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$author</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">true</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;"> /&gt; Yes&lt;/label&gt;&nbsp; &nbsp; &lt;label for=&quot;devloungeAuthor_no&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeAuthor_no&quot; name=&quot;devloungeAuthor&quot; value=&quot;false&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$author</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">false</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">/&gt; No&lt;/label&gt;&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;div class=&quot;submit&quot;&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;input type=&quot;submit&quot; name=&quot;update_devloungePluginSeriesSettings&quot; value=&quot;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">Update Settings</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">&quot; /&gt;&lt;/div&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;/form&gt;</span></li>
<li><span style="color: Gray;">&nbsp; &lt;/div&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">End function printAdminUsersPage()</span></li></ol></div></div>
<h3>设定用户面板Action</h3>
<p>当<a href="http://sexywp.com/how-to-write-a-wp-plugin-07.htm">设定管理面板</a>的时候，我们定义了一个函数叫做DevloungePluginSeries_ap，以帮助初始化管理面板。我们现在将要再次求助于此函数来添加我们的用户面板。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Initialize the admin and users panel</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries_ap</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">DevloungePluginSeries_ap</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">global</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">add_options_page</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_options_page</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">Devlounge Plugin Series</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">Devlounge Plugin Series</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Maroon;">9</span><span style="color: Gray;">, </span><span style="color: Blue;">basename</span><span style="color: Olive;">(</span><span style="color: Green;">__FILE__</span><span style="color: Olive;">)</span><span style="color: Gray;">, </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">printAdminPage</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">add_submenu_page</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">add_submenu_page</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">profile.php</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">Devlounge Plugin Series User Options</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">,</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">Devlounge Plugin Series User Options</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: Maroon;">0</span><span style="color: Gray;">, </span><span style="color: Blue;">basename</span><span style="color: Olive;">(</span><span style="color: Green;">__FILE__</span><span style="color: Olive;">)</span><span style="color: Gray;">, </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">printAdminUsersPage</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>在第12行，你能看到一行代码：</p>
<ul>
<li>往profile.php页面中添加了一个子菜单</li>
<li>让一个用户级别高于或者等于0的用户访问用户面板</li>
<li>调用我们的printAdminUsersPage函数</li>
</ul>
<p>关于访问级别的（此例中为0）更详细的描述，可以参考<a href="http://codex.wordpress.org/User_Levels">用户级别</a>。</p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-08.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（07）---构造一个WordPress插件管理员面板</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-07.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-07.htm#comments</comments>
		<pubDate>Fri, 06 Jun 2008 08:26:49 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=89</guid>
		<description><![CDATA[任何需要用户输入（诸如改变一个变量）的插件，都需要某种管理面板。建立一个管理面板，并不是那么难的，所以，一个插件作者决定不创建管理面板，而是让用户自己去修改PHP代码的行为让我很是苦恼。让一个用户（TA的PHP知识可能是0）去修改代码通常来说不是一个好主意。本文将深入探讨成功地为你的插件创建管理面板，到底需要些什么。





<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-07.htm" title="插件开发全攻略（07）---构造一个WordPress插件管理员面板">Keep Reading --- 1657 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>任何需要用户输入（诸如改变一个变量）的插件，都需要某种管理面板。<a href="http://codex.wordpress.org/Adding_Administration_Menus">建立一个管理面板</a>，并不是那么难的，所以，一个插件作者决定不创建管理面板，而是让用户自己去修改PHP代码的行为让我很是苦恼。让一个用户（TA的PHP知识可能是0）去修改代码通常来说不是一个好主意。本文将深入探讨成功地为你的插件创建管理面板，到底需要些什么。</p>
<p><span id="more-89"></span></p>
<p><a href="http://picasaweb.google.com/TangChao.ZJU/Blog02/photo#5209476529229978866"><img src="http://lh5.ggpht.com/TangChao.ZJU/SEvHTWZ83PI/AAAAAAAAAck/PV2Chbk0YdI/s800/admin-panel.gif" style="border:none;clear:both;margin:10px auto;"/></a></p>
<h3>存储变量的地方</h3>
<p>当你想要给你的插件创建一个管理面板的时候，你首先会碰到的问题之一就是到底在哪里存储变量值。非常幸运，WordPress通过options使得这件事变得非常容易。我将会在后续的系列文章中解释options和数据库存储。现在来说，所有你需要做的事情就是点点你的头，然后跟着我的指导，把你自己的管理变量存储到WordPress数据库中。</p>
<p>通常我考虑到options的时候做的第一件事情就是，给我的管理options取一个独特的名字。我把这个名字以成员变量的形式存储在我的类中。在这个Devlounge Plugin Series插件的例子中，我把这个变量声明添加到<strong>DevloungePluginSeries</strong>类中。</p>
<h3>命名你的管理Options</h3>
<div class="hl-surround"><div class="hl-main"><span style="color: Green;">class</span><span style="color: Gray;"> </span><span style="color: Blue;">DevloungePluginSeries</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">var</span><span style="color: Gray;"> </span><span style="color: #00008b;">$adminOptionsName</span><span style="color: Gray;"> = </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeriesAdminOptions</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;"> </span><span style="color: Blue;">DevloungePluginSeries</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">constructor</span><span style="color: #ffa500;"></span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"></span></div></div>
<p>第2行显示了我存储我的成员变量的地方。我将我的变量命名为<strong>adminOptionsName</strong>并且给予它一个很长而且独特的值<strong>DevloungePluginSeriesAdminOptions</strong>。</p>
<h3>给你的管理Options设定缺省值</h3>
<p>你需要一个地方来初始化你的管理选项，尤其是当一个用户第一次激活你的插件的时候。然而，你还必须保证这些options在升级中是安全的，以防万一你决定将来添加更多的options。我使用的技巧是，提供一个专门的函数来调用你的管理options。你的插件的需求可能不一样，但是绝大多数的管理面板不会难以置信地复杂，所以一个函数对你的管理options来说，已经足够了。</p>
<p>下面这个函数是我插入到类DevloungePluginSeries中的：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Returns an array of admin options</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">getAdminOptions</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$devloungeAdminOptions</span><span style="color: Gray;"> = </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">show_header</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> =&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">true</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #8b0000;">'</span><span style="color: Red;">add_content</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> =&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">true</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #8b0000;">'</span><span style="color: Red;">comment_author</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> =&gt; </span><span style="color: #8b0000;">'</span><span style="color: Red;">true</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #8b0000;">'</span><span style="color: Red;">content</span><span style="color: #8b0000;">'</span><span style="color: Gray;"> =&gt; </span><span style="color: #8b0000;">'</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$devOptions</span><span style="color: Gray;"> = </span><span style="color: Blue;">get_option</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">adminOptionsName</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Green;">empty</span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">foreach</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Gray;"> </span><span style="color: Green;">as</span><span style="color: Gray;"> </span><span style="color: #00008b;">$key</span><span style="color: Gray;"> =&gt; </span><span style="color: #00008b;">$option</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #00008b;">$devloungeAdminOptions</span><span style="color: Olive;">[</span><span style="color: #00008b;">$key</span><span style="color: Olive;">]</span><span style="color: Gray;"> = </span><span style="color: #00008b;">$option</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">update_option</span><span style="color: Olive;">(</span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">adminOptionsName</span><span style="color: Gray;">, </span><span style="color: #00008b;">$devloungeAdminOptions</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$devloungeAdminOptions</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>这个函数做的事情是：</p>
<ul>
<li>给你的管理options赋默认值（3-6行） </li>
<li>尝试从数据库中找出以前存储过的值（第7行） </li>
<li>如果options曾经存储过，那么存储的值会覆盖默认值（8-11行） </li>
<li>options被存储到WordPress数据库中（第12行） </li>
<li>options被返回供你使用（第13行） </li>
</ul>
<h3>初始化管理Options</h3>
<p>getAdminOptions函数可以在任何时候调用来获得管理options。然而，当插件第一次安装的时候呢？应该有某个函数被调用也能获得管理options。我在DevloungePluginSeries类中添加了这个函数：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">init</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$this</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">getAdminOptions</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>短小简单。但是必须有一个action来调用这个函数。</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">activate_devlounge-plugin-series/devlounge-plugin-series.php</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,&nbsp; </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">init</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
<p>这个action有些复杂，但是很容易理清楚。下面是这个action做的事情：</p>
<ul>
<li>当一个插件被激活的时候你告诉它运行 </li>
<li>你给它主要的插件PHP文件，就是devlounge-plugin-series/devlounge-plugin-series.php。这当然是假设你把插件放到了wp-content/<a href="http://sexywp.com/tags/plugins" class="st_tag internal_tag" rel="tag" title="标签 plugins 下的日志">plugins</a>/目录中。 </li>
<li>你传递了一个引用给实例变量dl_pluginSeries并且调用了init函数。 </li>
</ul>
<p>所以，任何时候插件被激活，init函数都会被调用。</p>
<h3>管理面板怎样工作</h3>
<p>在我深入到创建实际的管理面板的代码的时候，描述一下管理面板的行为是有好处的。这里有一些你设定你管理面板的步骤：</p>
<ul>
<li>检查任何表单数据是否已经被提交。 </li>
<li>如果表单数据存在，输出提醒。 </li>
<li>显示管理面板Options。 </li>
</ul>
<p>在管理面板中，一个非常困扰你的问题可能是_e的使用。_e函数允许WordPress搜索你文本的本地化版本。这将帮助WordPress在将来翻译你的插件。这个函数的工作类似一个普通的echo，但是你传给它的是你的文本和一个标识变量（典型的是你的插件名称）。一个例子：</p>
<p><code>_e('Update Settings','DevloungePluginSeries');</code></p>
<p>这句代码和：</p>
<p><code>echo &quot;Update Settings&quot;;</code></p>
<p>是相同的。</p>
<h3>设置你的管理面板函数</h3>
<p>我们想要做的第一件事情就是设定一个函数，来真正地打印出一个管理面板。函数名字叫做printAdminPage。下一段代码将要读入我们早先设定的options并且检查是否所有的发布options已经被提交。这一段的所有代码假设写在printAdminPage函数中。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">//Prints out the admin page</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; function printAdminPage() {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $devOptions = $this-&gt;getAdminOptions();</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (isset($_POST['update_devloungePluginSeriesSettings'])) {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isset($_POST['devloungeHeader'])) {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $devOptions['show_header'] = $_POST['devloungeHeader'];</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isset($_POST['devloungeAddContent'])) {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $devOptions['add_content'] = $_POST['devloungeAddContent'];</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isset($_POST['devloungeAuthor'])) {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $devOptions['comment_author'] = $_POST['devloungeAuthor'];</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isset($_POST['devloungeContent'])) {</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $devOptions['content'] = apply_filters('content_save_pre', $_POST['devloungeContent']);</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; update_option($this-&gt;adminOptionsName, $devOptions);</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ?&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;div class=&quot;updated&quot;&gt;&lt;p&gt;&lt;strong&gt;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">Settings Updated.</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;} </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上面所有代码做的是装载options并且测试是否表单的每个部分都已经被正确提交。if语句并不是必须的，但是有的时候对于调试来说很有用。第一被测试的表单变量是update_devloungePluginSeriesSettings。这个变量被赋值给我们的&#8220;提交&#8221;按钮。如果它没有被设定，那么说明这个表单没有被提交。</p>
<p>就像说好的一样，在第16行，我使用了apply_filters函数来格式化内容，以便存入数据库。</p>
<p>下一段代码将会显示一个HTML表单，那是管理面板所必须的。它有一些复杂，所以我会这里概括一下。所有的代码做的事情，就是显示表单元素和读入options。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&lt;div class=wrap&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;form method=&quot;post&quot; action=&quot;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">echo</span><span style="color: Gray;"> </span><span style="color: #00008b;">$_SERVER</span><span style="color: Olive;">[</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">REQUEST_URI</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">]</span><span style="color: Gray;">; </span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">&quot;&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;h2&gt;Devlounge Plugin Series&lt;/h2&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;h3&gt;Content to Add to the End of a Post&lt;/h3&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;textarea name=&quot;devloungeContent&quot; style=&quot;width: 80%; height: 100px;&quot;&gt;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: Blue;">apply_filters</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">format_to_edit</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">content</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Olive;">)</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">&lt;/textarea&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;h3&gt;Allow Comment Code in the Header?&lt;/h3&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;Selecting &quot;No&quot; will disable the comment code inserted in the header.&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;&lt;label for=&quot;devloungeHeader_yes&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeHeader_yes&quot; name=&quot;devloungeHeader&quot; value=&quot;true&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">show_header</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">true</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;"> /&gt; Yes&lt;/label&gt;&nbsp; &nbsp; &lt;label for=&quot;devloungeHeader_no&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeHeader_no&quot; name=&quot;devloungeHeader&quot; value=&quot;false&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">show_header</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">false</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">/&gt; No&lt;/label&gt;&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;h3&gt;Allow Content Added to the End of a Post?&lt;/h3&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;Selecting &quot;No&quot; will disable the content from being added into the end of a post.&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;&lt;label for=&quot;devloungeAddContent_yes&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeAddContent_yes&quot; name=&quot;devloungeAddContent&quot; value=&quot;true&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">add_content</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">true</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;"> /&gt; Yes&lt;/label&gt;&nbsp; &nbsp; &lt;label for=&quot;devloungeAddContent_no&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeAddContent_no&quot; name=&quot;devloungeAddContent&quot; value=&quot;false&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">add_content</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">false</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">/&gt; No&lt;/label&gt;&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;h3&gt;Allow Comment Authors to be Uppercase?&lt;/h3&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;Selecting &quot;No&quot; will leave the comment authors alone.&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;p&gt;&lt;label for=&quot;devloungeAuthor_yes&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeAuthor_yes&quot; name=&quot;devloungeAuthor&quot; value=&quot;true&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">comment_author</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">true</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;"> /&gt; Yes&lt;/label&gt;&nbsp; &nbsp; &lt;label for=&quot;devloungeAuthor_no&quot;&gt;&lt;input type=&quot;radio&quot; id=&quot;devloungeAuthor_no&quot; name=&quot;devloungeAuthor&quot; value=&quot;false&quot; </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: #00008b;">$devOptions</span><span style="color: Olive;">[</span><span style="color: #8b0000;">'</span><span style="color: Red;">comment_author</span><span style="color: #8b0000;">'</span><span style="color: Olive;">]</span><span style="color: Gray;"> == </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">false</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">checked=&quot;checked&quot;</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">}</span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">/&gt; No&lt;/label&gt;&lt;/p&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;div class=&quot;submit&quot;&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;input type=&quot;submit&quot; name=&quot;update_devloungePluginSeriesSettings&quot; value=&quot;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">_e</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">Update Settings</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Blue;">?&gt;</span><span style="color: Gray;">&quot; /&gt;&lt;/div&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&lt;/form&gt;</span></li>
<li><span style="color: Gray;">&nbsp; &lt;/div&gt;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">End function printAdminPage()</span></li></ol></div></div>
<p>需要在上述代码中观察的是options的引用，和HTML和PHP是怎样集成的。</p>
<h3>设置管理面板Action</h3>
<p>现在，printAdminPage函数已经添加了，我们需要通过一个action调用它。首先函数必须被设定在正好在action的上面，在类的范围之外。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Initialize the admin panel</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries_ap</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">DevloungePluginSeries_ap</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">global</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">function_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">add_options_page</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_options_page</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">Devlounge Plugin Series</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">Devlounge Plugin Series</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Maroon;">9</span><span style="color: Gray;">, </span><span style="color: Blue;">basename</span><span style="color: Olive;">(</span><span style="color: Green;">__FILE__</span><span style="color: Olive;">)</span><span style="color: Gray;">, </span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">printAdminPage</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上面的代码做了下面这些事：</p>
<ul>
<li>创建了一个叫做DevloungePluginSeries_ap的函数。 </li>
<li>测试变量dl_pluginSeries是否存在（4-7行）。这个变量是我们的类的引用。 </li>
<li>一个叫做&#8220;Devlounge Plugin Series&#8221;的管理页面被初始化了，并且，我们的printAdminPage函数被引用了。（8-10行）。 </li>
</ul>
<p>add_options_page函数的调用方法为：</p>
<p>add_options_page(page_title,menu_title,access_level/capability,file,[function]);</p>
<p>访问级别（在这个例子中是9）在WordPress Codex的Users Levels page页面有详细的描述。</p>
<p>必须设置一个action来调用DevloungePluginSeries_ap函数：</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">admin_menu</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #8b0000;">'</span><span style="color: Red;">DevloungePluginSeries_ap</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-07.htm/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（06）---WordPress插件Filter</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-06.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-06.htm#comments</comments>
		<pubDate>Wed, 04 Jun 2008 10:48:18 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=86</guid>
		<description><![CDATA[Filter是一组使得你的插件可以插入来修改文字的函数。被修改的文字通常是要插入到数据库或者显示给终端用户看的。

WordPress Filter允许你修改几乎任何类型的显示文字，而且其功能十分强劲。通过Filter你可以修改文章，feed，怎么样在评论中的作者，还有很多，很多。

为了说明WordPress Filter的用处，我们会继续在已经存在的Devlounge Plugin Series代码上工作。

<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-06.htm" title="插件开发全攻略（06）---WordPress插件Filter">Keep Reading --- 828 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="http://codex.wordpress.org/Plugin_API/Filter_Reference">Filter</a>是一组使得你的插件可以插入来修改文字的函数。被修改的文字通常是要插入到数据库或者显示给终端用户看的。</p>
<p><a href="http://sexywp.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 WordPress 下的日志">WordPress</a> Filter允许你修改几乎任何类型的显示文字，而且其功能十分强劲。通过Filter你可以修改文章，feed，怎么样在评论中的作者，还有很多，很多。</p>
<p>为了说明WordPress Filter的用处，我们会继续在已经存在的Devlounge Plugin Series代码上工作。</p>
<p><span id="more-86"></span><br />
<h3>添加一个内容Filter</h3>
<p>有一个你可以使用的很Cool的Filter是'the_content'。这个filter在文章内容被显示在浏览器之前执行。我们将要添加一行文字到文章内容的末尾。</p>
<p>根据<a href="http://codex.wordpress.org/Plugin_API">WordPress插件API</a>，添加一个filter的格式为：<code>add_<a href="http://sexywp.com/tags/filter" class="st_tag internal_tag" rel="tag" title="标签 filter 下的日志">filter</a>('hook_name','your_<a href="http://sexywp.com/tags/filter" class="st_tag internal_tag" rel="tag" title="标签 filter 下的日志">filter</a>',[priority],[accepted_args]);</code></p>
<p>我们只需要往<strong>DevloungePluginSeries</strong>类中添加一个函数。让我叫它<strong>addContent</strong>。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">addContent</span><span style="color: Olive;">(</span><span style="color: #00008b;">$content</span><span style="color: Gray;">=</span><span style="color: #8b0000;">'</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$content</span><span style="color: Gray;">.=</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">&lt;p&gt;Devlounge Was Here&lt;/p&gt;</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$content</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>在上面的代码中，发生了以下的事件：</p>
<ul>
<li>上述函数会接受一个参数叫做<strong>content</strong> </li>
<li>如果调用时不传递参数，那么content会设定为默认值（空串） </li>
<li>参数<strong>content</strong>被附加了一行我们自定义的文本 </li>
<li>然后重新返回了content </li>
</ul>
<p>在向类添加了上述函数后，下一步要做的就是将它插入到'<strong>the_content</strong>'中，使得这个函数被调用。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Actions and Filters</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Actions</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_head</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">addHeaderCode</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,</span><span style="color: Maroon;">1</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Filters</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_filter</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">the_content</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">addContent</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>在这段代码的第6行你可以看到，添加了一个叫做'<strong>the_content</strong>'的filter，通过这个filter，我们的函数'<strong>addContent</strong>'会被调用。</p>
<p>如果插件启用，当一篇文章被显示的时候，文本&#8220;Devlounge Was Here&#8221;将会被显示到文章的末尾。</p>
<h3>添加一个作者Filter</h3>
<p>我在这里要展示另一个使用Filter的例子，我要展示一下怎么操纵显示一个评论的作者。我这里只是简单地让所有的作者名字都用大写显示。</p>
<p>我们只需要往<strong>DevloungePluginSeries</strong>类中添加一个函数。我们叫它<strong>authorUpperCase</strong>。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">authorUpperCase</span><span style="color: Olive;">(</span><span style="color: #00008b;">$author</span><span style="color: Gray;">=</span><span style="color: #8b0000;">'</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">strtoupper</span><span style="color: Olive;">(</span><span style="color: #00008b;">$author</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>在上述代码中，做了这些事情：</p>
<p>上述函数会接受一个参数，叫做<strong>author</strong></p>
<p>如果没有参数，会被设定成默认值</p>
<p><strong>author</strong>字符串会以大写的形式返回</p>
<p>在函数被添加到类后，下一步是将它插入到'<strong>get_comment_author</strong>'中使它被调用。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Actions and Filters</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Actions</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_head</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">addHeaderCode</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,</span><span style="color: Maroon;">1</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Filters</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_filter</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">the_content</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">addContent</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_filter</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">get_comment_author</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">authorUpperCase</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>像你在第7行看到的，我们添加了一个'<strong>get_comment-author</strong>' filter，然后，我们的函数'<strong>authorUpperCase</strong>'会被调用。</p>
<p>如果插件已经启用，并且一篇日志的评论是可见的，那么评论的作者名字会以大写显示。</p>
<h3>应用Filter</h3>
<p>使用Filter可以做的更强大的是，你可以动态地调用他们。没有必要每次运行都添加一次filter。你可以在任何时候在你的代码里面调用filter。</p>
<p><strong>apply_filters</strong>的格式是：apply_filter('filter name','you text');</p>
<p>你会在这个系列的后续文章中看到<strong>apply_filters</strong>的例子。</p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-06.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（05）---WordPress 插件Actions</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-05.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-05.htm#comments</comments>
		<pubDate>Tue, 03 Jun 2008 06:47:35 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=85</guid>
		<description><![CDATA[WordPress actions允许作为插件作者的你插入到WordPress应用中并且执行一段代码。一个Action的例子就是，你想要在一个用户发布完一篇文章或者留下一篇留言的时候执行一个动作。

一些我使用极其频繁的Action有：



<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-05.htm" title="插件开发全攻略（05）---WordPress 插件Actions">Keep Reading --- 479 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="http://codex.wordpress.org/Plugin_API#Actions">WordPress actions</a>允许作为插件作者的你插入到WordPress应用中并且执行一段代码。一个Action的例子就是，你想要在一个用户发布完一篇文章或者留下一篇留言的时候执行一个动作。</p>
<p>一些我使用极其频繁的Action有：</p>
<ul>
<li>admin_menu：允许你给你的插件设置一个管理面板。 </li>
<li>wp_head：允许你将代码插入到博客的&lt;head&gt;标签内。 </li>
</ul>
<p>  <span id="more-85"></span></p>
<h3>Action在行动</h3>
<p>当定义一个<a href="http://sexywp.com/how-to-write-a-wp-plugin-04.htm">WordPress插件的结构</a>的时，我为某些Action留下了一块地方。在这个例子中，我们将使得一段代码可以在WordPress博客中的&lt;head&gt;标签内运行。</p>
<p>首先，我们需要在<strong>DevloungePluginSeries</strong>类中添加一个函数：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">addHeaderCode</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &lt;!-- </span><span style="color: Blue;">Devlounge</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">Was</span><span style="color: Gray;"> </span><span style="color: Blue;">Here</span><span style="color: Gray;">--&gt;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上面一段代码的作用是输出HTML注释。相当简单，但是你实际上可以输出任何东西。为了调用这个函数，我们要添加一个Action。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Actions and Filters</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Actions</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Blue;">add_action</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">wp_head</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: Green;">array</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;">,</span><span style="color: #8b0000;">'</span><span style="color: Red;">addHeaderCode</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;">,</span><span style="color: Maroon;">1</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Filters</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>从<a href="http://codex.wordpress.org/Plugin_API">WordPress插件API</a>中我们可以知道，add_action的结构如下：<code>add_<a href="http://sexywp.com/tags/action" class="st_tag internal_tag" rel="tag" title="标签 action 下的日志">action</a>('hook_name','your_function_name',[priority],[accepted_args]);</code></p>
<p>由于我们是在一个类的内部调用一个函数，我们传递给Action一个数组，里面包含我们的类对象的引用（dl_pluginSeries）和我们想要调用的函数名（addHeaderCode）。我们已经给我们的插件设定了一个优先级为1，数字越小，执行时间越靠前。</p>
<h3>运行代码</h3>
<p>如果Devlounge Plugin Series插件被启用了，使用【查看-&gt;源文件】应该可以在你的博客的源码中看到注释&#8220;Devlounge was here&#8221;。</p>
<h3>移除Action</h3>
<p>如果你的插件动态地添加Action，你也可以使用remove_action来动态地移除action。用法如下：</p>
<p><code>remove_action('action_hook','action_function')。</code></p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-05.htm/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（04）---WordPress插件的结构</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-04.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-04.htm#comments</comments>
		<pubDate>Sun, 01 Jun 2008 11:32:47 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=72</guid>
		<description><![CDATA[开发一个WordPress插件的一个更重要的方面，是你怎样设计它的结构。本文将研究几个关于设计插件结构的提示，以帮助你组织你的插件资源，避免名字冲突。每一个插件作者的插件的结构都不尽相同，所以这些提示只是我的个人偏好。我将首先简单地描述一下一个WordPress插件是怎样工作的，然后介绍一个插件的结构。

WordPress插件怎样工作

在将一个插件放入到wp-content/plugins/目录后，插件应该自动的处于可以安装的状态。

<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-04.htm" title="插件开发全攻略（04）---WordPress插件的结构">Keep Reading --- 776 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>开发一个WordPress插件的一个更重要的方面，是你怎样设计它的结构。本文将研究几个关于设计插件结构的提示，以帮助你组织你的插件资源，避免名字冲突。每一个插件作者的插件的结构都不尽相同，所以这些提示只是我的个人偏好。我将首先简单地描述一下一个WordPress插件是怎样工作的，然后介绍一个插件的结构。</p>
<h3>WordPress插件怎样工作</h3>
<p>在将一个插件放入到wp-content/<a href="http://sexywp.com/tags/plugins" class="st_tag internal_tag" rel="tag" title="标签 plugins 下的日志">plugins</a>/目录后，插件<a href="http://codex.wordpress.org/Managing_Plugins">应该自动的处于可以安装的状态</a>。</p>
<p>当一个插件被&#8220;启用&#8221;，等同于告知WordPress将你的代码装载到&#8220;每&#8221;个页面（包括管理页面）。这也就是为什么当你启用了很多的插件的时候，你的WordPress可能非常慢的原因，这是由它所引入的代码的量决定的。</p>
<p><span id="more-72"></span></p>
<p>从你的插件被启用，WordPress自动将你的代码装载后开始，你可以利用<a href="http://codex.wordpress.org/Plugin_API">WordPress插件API</a>。你还可以使用<a href="http://codex.wordpress.org/Template_Tags">WordPress模板标签</a>或者创建你自己的函数。</p>
<p>如果你计划开发一个改变文章内容或者评论的插件，我建议你读一下<a href="http://codex.wordpress.org/The_Loop">WordPress loop</a>。<a href="http://sexywp.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 WordPress 下的日志">WordPress</a> loop是一个显示你的文章的循环。有些模板标签在这个循环外面无法工作，所以，你准确地知道你代码在哪里执行是非常必要的。你可通过使用<a href="http://codex.wordpress.org/Plugin_API#Actions">Actions</a>和<a href="http://codex.wordpress.org/Plugin_API#Filters">Filters</a>来控制这一点，这将会在将来的文章中解释。</p>
<h3>文件夹结构</h3>
<p>所有的WordPress插件都会被安装到wp-content/plugins目录中。有些插件作者的插件只包含一个文件，但是我推荐你总是创建一个文件夹来保存你的插件。</p>
<p>典型地，我会把我的插件放在如下的目录结构中：</p>
<ul>
<li>插件文件夹名称（你插件的名字，没有空格或者特殊字符）
<ul>
<li>插件PHP文件 </li>
<li>js文件夹（存放javascript文件） </li>
<li>css文件夹（存放样式表文件） </li>
<li>php文件夹（存放其他的PHP文件） </li>
</ul>
</li>
</ul>
<p>举例来说，这是一个我创建的样例结构：</p>
<ul>
<li>devlounge-plugin-series
<ul>
<li>devlounge-plugin-series.php </li>
<li>js </li>
<li>css </li>
<li>php </li>
</ul>
</li>
</ul>
<p>在devlounge-plugin-series文件夹中，我将只包含主要的PHP文件，把其他的文件都放到他们各自属于的文件夹中。这个结构将帮助其他插件作者在查看你的代码的时候，能够分辨哪个是主要的插件文件，哪些是支持插件正常工作的附属文件。</p>
<p>WordPress还建议将图片放到一个文件夹中，并且包含一个readme文件在你的插件中。</p>
<h3>主要插件文件</h3>
<p>当你开始编写一个插件的时候，前面七行用来描述你的插件。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">/*</span></li>
<li><span style="color: #ffa500;">&nbsp;Plugin Name: Your Plugin Name Here</span></li>
<li><span style="color: #ffa500;">&nbsp;Plugin URI: Your Plugin URI</span></li>
<li><span style="color: #ffa500;">&nbsp;Version: Current Plugin Version</span></li>
<li><span style="color: #ffa500;">&nbsp;Author: Who Are You?</span></li>
<li><span style="color: #ffa500;">&nbsp;Description: What does your plugin do？</span></li>
<li><span style="color: #ffa500;">&nbsp;</span><span style="color: #ffa500;">*/</span></li></ol></div></div>
<p>第3行是让你命名你的插件的。第4行是向用户指出插件所在的网址的。第5行让你指定当前的版本。第6行让你设定插件的作者。第7行是对插件的描述。</p>
<p>下面展示的是一个已经填写完毕的范例：</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">/*</span></li>
<li><span style="color: #ffa500;">&nbsp;Plugin Name: Devlounge Plugin Series</span></li>
<li><span style="color: #ffa500;">&nbsp;Plugin URI: </span><span style="color: Blue;">http://www.devlounge.net/</span></li>
<li><span style="color: #ffa500;">&nbsp;Version: v1.00</span></li>
<li><span style="color: #ffa500;">&nbsp;Author: Ronald Huereca</span></li>
<li><span style="color: #ffa500;">&nbsp;Description: A sample plugin for a Devlounge series.</span></li>
<li><span style="color: #ffa500;">&nbsp;</span><span style="color: #ffa500;">*/</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>下面展示的是插件在WordPress插件面板上出现的截图。</p>
<p><img style="border:none;margin:10px auto;clear:both;" src="http://lh3.ggpht.com/TangChao.ZJU/SEKLOyGpJbI/AAAAAAAAAbE/XMn77sNe0LM/s800/htwawp4-1.gif" /></p>
<h3>设定一个类结构</h3>
<p>开发一个插件，并不需要你对<a href="http://www.onlamp.com/pub/a/php/2002/07/18/php_foundations.html">PHP类</a>了若指掌，但是如果你真的很熟悉，那会很有帮助。为了避免与其他的WordPress插件发生名字冲突，一个类结构是必须的。如果别人在插件当中使用了和你一样的函数名，那么就会发生一个错误，WordPress可能会无法响应直到你删除那个插件。</p>
<p>为了避免名字冲突，所有的插件都使用一个PHP类结构是急需的。这里有一些&#8220;骨架&#8221;代码，可以帮助你创建一个类结构。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">class_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">class</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">DevloungePluginSeries</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">DevloungePluginSeries</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"> </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">constructor</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">End Class DevloungePluginSeries</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上述代码的含义是，首先检查是否有一个名叫DevloungePluginSeries的类存在。如果这个类不存在，那么创建这个类。</p>
<h3>初始化你的类</h3>
<p>下面的代码将会初始化你的类。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">class_exists</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">DevloungePluginSeries</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">DevloungePluginSeries</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上面的代码检查是否类DevloungePluginSeries已经存在了。如果已经存在，那么一个变量$dl_pluginSeries将会被创建，并且会使用一个DevloungePluginSeries类的对象给它赋值。</p>
<p>设置Actions和Filters</p>
<p>下面的代码段是用来放置WordPress Actions和Filters的地方（我会在后续的文章中详细讲）。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Gray;">&nbsp;</span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Actions and Filters</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Green;">isset</span><span style="color: Olive;">(</span><span style="color: #00008b;">$dl_pluginSeries</span><span style="color: Olive;">)</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Actions</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">Filters</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">?&gt;</span></li></ol></div></div>
<p>上述代码首先确认$dl_pluginSeries是否已经被设定。如果设定了（仅当类存在的时候），那么就会设定合适的actions和filters。</p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-04.htm/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（02）---编写插件的七个理由</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-02.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-02.htm#comments</comments>
		<pubDate>Thu, 29 May 2008 02:29:31 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=95</guid>
		<description><![CDATA[当写作《插件开发全攻略》系列文章的时候，我想，首先罗列一些为什么WordPress用户想要编写一个WordPress插件的理由是有好处的。

下面罗列了为什么一个WordPress用户应该考虑编写一个WordPress插件的七个理由。



<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-02.htm" title="插件开发全攻略（02）---编写插件的七个理由">Keep Reading --- 1161 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>当写作《插件开发全攻略》系列文章的时候，我想，首先罗列一些为什么WordPress用户想要编写一个<a href="http://wordpress.org/extend/plugins/">WordPress插件</a>的理由是有好处的。</p>
<p>下面罗列了为什么一个WordPress用户应该考虑编写一个WordPress插件的七个理由。</p>
<p><span id="more-52"></span></p>
<ol>
<li>
<h3>你喜欢一个插件的创意，但是不喜欢这个插件的实现方式</h3>
<p>无论是在<a href="http://weblogtoolscollection.com/">Weblog Tools Collection</a>还是在官方的<a href="http://wordpress.org/development/2007/03/plugin-directory/">WordPress插件目录</a>或者<a href="http://wp-plugins.net/">WordPress插件数据库</a>寻找插件，你将不可避免的找到一个插件，能够满足你的需求，但是只能在某种程度上满足你的需求。</p>
<p>你很喜欢这个插件的创意，但是却并不是那么喜欢插件作者使用的实现方法。为什么不创建你自己的分立的版本来实现你最初的那个创意呢？</p>
</li>
<li>
<h3>你想修改已经存在的插件的代码</h3>
<p>有时候，一个插件的输出需要修改一下，或者你想要的某个功能正好没有。虽然你可以尝试说服插件作者来添加你要的特性，但是插件作者通常都非常忙或者他们不喜欢你的建议。一个插件作者要为一个免费插件提供支持，维护需要付出很多努力。有时候，一个插件很可能已经没有任何人去维护它了。</p>
<p>在插件作者不能满足你的需求的这种情况下，就全靠你自己采取主动来修改存在的插件代码了。如果你的工作做得足够好并且做了足够多的修改，你可以再次发布这个插件，只要原来这个插件发布于与<a href="http://www.gnu.org/licenses/gpl.html">GPL相兼容的许可</a>就行。</p>
<p>通常当我安装或者测试一个新的插件的时候，我要做的第一件事情，就是查看一下代码，看看有什么我可以修改的，有什么我不可以修改的，我有可能往里面添加什么或者拿掉什么。</p>
</li>
<li>
<h3>你想要扩展一个插件</h3>
<p>有时候一个插件本身很好，但是你想要在它的基础上建立并且发布你自己的版本。比如说，你可能认为一个插件在使用了AJAX后会工作得更好，或者添加更多的钩子以使它能够与其他插件兼容。你可能想要给它添加一个管理面板使得你不需要深入到代码里去修改输出。</p>
<p>就想前面提出的一样，如果一个插件是兼容GPL许可的，你可以自由地发布你自己的版本。</p>
</li>
<li>
<h3>你想要可移植的主题代码</h3>
<p>对于像我们这样选择自己从零开始创建主题的玩家，你可能会发现你自己在很多地方重用着一段代码。编写你自己的插件，组合所有的代码小片段使得你可以像使用模板标签一样来使用那些代码，不是更好吗？</p>
<p>模板标签的美丽就在于你可以一次又一次地在你的主题或者任何一个你将来要创建的主题中使用它们。并且，你只需要在一个地方修改这些代码，而不是很多处地方。</p>
</li>
<li>
<h3>你是一个主题设计者</h3>
<p>如果你是一个WordPress模板设计者，我可能会劝说你，符合逻辑的下一步是成为一个插件作者。编写插件将使得你对于WordPress的行为有更进一步的了解，接着，你就可以扩展那些你已经发布的模板的功能了。</p>
</li>
<li>
<h3>你想要赚钱</h3>
<p>一个好的插件作者通常可以因为他的工作而获得回报。一些插件作者也可以获得捐赠或者为提供额外的支持或者咨询而收取费用。</p>
</li>
<li>
<h3>你想获得链接</h3>
<p>当我发布<a href="http://www.raproject.com/">Reader Appreciation Project</a>的时候，我的其中一个目的就是快速建立传入链接。我知道的最好的方法就是写一些WordPress插件并且提高它们的功能。我的其中一个插件（<a href="http://www.raproject.com/ajax-edit-comments/">WP Ajax Edit Comments</a>）竟然非常地流行，目前已经为我带来了超过100个传入链接了。</p>
</li>
</ol>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-02.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>插件开发全攻略（01）---介绍</title>
		<link>http://sexywp.com/how-to-write-a-wp-plugin-01.htm</link>
		<comments>http://sexywp.com/how-to-write-a-wp-plugin-01.htm#comments</comments>
		<pubDate>Wed, 28 May 2008 07:15:11 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[translate]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=93</guid>
		<description><![CDATA[对于许多WordPress用户来说，插件是必须的。WordPress 插件使得那些只有很少或者没有编程能力的用户可以扩展他们博客的功能。插件的形式多种多样，在WordPress中，插件几乎可以做任何事情。

即便是WordPress这样一个优秀的独立应用程序，仍旧有许多方面有缺憾。用户所要求的越来越多的WordPress所应该具有的特性，都很可能被开发成插件。此外，还有很多没有实现的创意，而且，每一天还有更多的创意被提出。

在已经发布了三款插件之后（不包括我自己写给自己用的那些），我意识到了一些WordPress的局限性，我希望能够分享一些我已经学到的（我仍旧在学）关于创建WordPress插件的一些经验。最终，我将会开始写一个系列，专门讨论编写你自己的WordPress插件的过程中遇到的各种各样的问题。这个系列将会从非常基础的话题开始，并且假设你的插件知识是零基础。

<span class="readmore"><a href="http://sexywp.com/how-to-write-a-wp-plugin-01.htm" title="插件开发全攻略（01）---介绍">Keep Reading --- 1007 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>对于许多<a href="http://wordpress.org">WordPress</a>用户来说，插件是必须的。<a href="http://wordpress.org/extend/plugins/">WordPress 插件</a>使得那些只有很少或者没有编程能力的用户可以扩展他们博客的功能。插件的形式多种多样，在WordPress中，插件几乎可以做任何事情。</p>
<p>即便是WordPress这样一个优秀的独立应用程序，仍旧有许多方面有缺憾。用户所要求的越来越多的WordPress所应该具有的特性，都很可能被开发成插件。此外，还有很多没有实现的创意，而且，每一天还有更多的创意被提出。</p>
<p>在已经发布了三款插件之后（不包括我自己写给自己用的那些），我意识到了一些WordPress的局限性，我希望能够分享一些我已经学到的（我仍旧在学）关于创建WordPress插件的一些经验。最终，我将会开始写一个系列，专门讨论编写你自己的WordPress插件的过程中遇到的各种各样的问题。这个系列将会从非常基础的话题开始，并且假设你的插件知识是零基础。</p>
<h3>这个系列是为谁准备的？</h3>
<p>这个系列是为了任何一个好奇或者想要学习怎样编写他们自己的WordPress插件的用户撰写的。这个系列的读者应该有中级程度的PHP知识，知道一点点JavaScript，并且有相当的CSS知识。</p>
<p>这个插件系列将会使主题模板设计者受益，还有那些想要修补插件代码的人，还有那些想从零开始编写自己的插件的人。</p>
<p><span id="more-53"></span></p>
<h3>完成工作必备利器</h3>
<p>使用任何文本编辑器都可以写插件。这里是一些我个人使用的创建插件的工具。</p>
<ul>
<li>Dreamweaver </li>
<li>Firefox </li>
<li><a href="http://www.joehewitt.com/software/firebug/">Firebug（Firefox的插件）</a></li>
<li><a href="http://chrispederick.com/work/web-developer/">Web Developer（Firefox的插件）</a></li>
<li><a href="http://sourceforge.net/projects/xampp/">XAMPP</a>和一个本地安装的<a href="http://wordpress.org">WordPress</a></li>
</ul>
<p>这个系列假设你使用的是WordPress 2.1.x或者更新的版本。</p>
<h3>代码范例</h3>
<p>我所使用的所有的代码在每篇文章的结论一节都提供下载。我会随着内容推进，逐步完善我的代码，所以每一份下载都会不同。我将会创建一个实际上什么都做不了的插件，但是足够向你展示一个插件工作的基础了。</p>
<p>由于这个系列里的每篇文章都是在上一篇的基础之上，所以推荐按照顺序来阅读这个系列里面的文章。</p>
<p>我极力建议你使用本地WordPress来安装调试测试插件，而不是在一个你用来发表你的文章的正规的WordPress上。</p>
<h3>话题</h3>
<p>我计划从非常基础的内容开始，然后快速推进到更加核心的WordPress插件函数的内容。这个系列不会关注插件开发中太过细节的东西，但是希望能够给你一个很好的开始开发你自己的插件的基础。如果你有任何问题或者建议，请留言，或者使用<a href="http://www.devlounge.net/contact">Devlounge Contact Form</a>插件给我发送Email（译者：也可以给我留言）。我请你不要依赖<a href="http://www.devlounge.net/">Devlounge</a>或者支持，而是使用<a href="http://wordpress.org/support/">WordPress支持论坛</a>。</p>
<h3>技术</h3>
<p>我在我的代码范例中使用的某些技术可能不是最好的代码表达方式。你可能会对我没有使用许多的便捷写法而有所微词。我在这里提前抱歉。每个人有不同的编码风格。</p>
<p>只要是插件技术，结构，行为，或者其他讨厌的东西，如果有更好的方式被我忽略了，那么我非常乐意倾听。</p>

	标签：<a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/plugins" title="plugins" rel="tag">plugins</a>, <a href="http://sexywp.com/tags/translate" title="translate" rel="tag">translate</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/how-to-write-a-wp-plugin-01.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress:插件开发API（Plugin API）</title>
		<link>http://sexywp.com/wordpress-plugin-api.htm</link>
		<comments>http://sexywp.com/wordpress-plugin-api.htm#comments</comments>
		<pubDate>Sat, 10 May 2008 09:05:28 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[docs]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=82</guid>
		<description><![CDATA[Plugin API

介绍

本文当主要介绍WordPress插件开发者可以使用的API Hook，以及如何使用它们。

<span class="readmore"><a href="http://sexywp.com/wordpress-plugin-api.htm" title="WordPress:插件开发API（Plugin API）">Keep Reading --- 2988 words totally</a></span>]]></description>
			<content:encoded><![CDATA[<h2>Plugin API</h2>
<h3>介绍</h3>
<p>本文当主要介绍<a href="http://wordpress.org/" title="WP">WordPress</a>插件开发者可以使用的API Hook，以及如何使用它们。</p>
<p>本文假设您已经阅读了《<a href="http://codex.wordpress.org/Writing_a_Plugin" title="Writing a Plugin">Writing a Plugin</a>》（这篇文章概览了如何写一个插件）。本文主要介绍API Hook，也称作Filter和Action，<a href="http://wordpress.org/" title="WP">WordPress</a>使用这些函数来使您的插件起作用。</p>
<p>注意：本文的内容适用于WordPress1.2+。</p>
<p><span id="more-82"></span></p>
<h3>Hook，Action和Filter</h3>
<p>Hook是<a href="http://sexywp.com/cata/wp" title="Becoming Charles-WP">WordPress</a>提供的一种机制，帮助您将您的插件加入到<a href="http://wordpress.org/" title="WP">WordPress</a>中；也即，在您的插件中，通过调用一些系统函数，使得您的插件可以运作起来。一共有两种Hook：</p>
<ol>
<li><a href="http://sexywp.com/tags/action" class="st_tag internal_tag" rel="tag" title="标签 action 下的日志">Action</a>：Action是<a href="http://wordpress.org/" title="WP">WordPress</a>内核在运行到某个特定的点的，或者某个特定的事件发生的时候执行的。您可以通过使用Action API让您的插件中的一个或者多个函数在这些特定的点执行。</li>
<li><a href="http://sexywp.com/tags/filter" class="st_tag internal_tag" rel="tag" title="标签 filter 下的日志">Filter</a>：Filter是<a href="http://sexywp.com/cata/wp" title="Becoming Charles-WP">WordPress</a>在将一段文本加入到数据库，或者发送给浏览器之前处理不同种类的文本用的。您的插件可以通过使用Filter API，让一个或者多个函数在这些时刻运行，以处理特定类型的文本。</li>
</ol>
<p>有的时候，您可以使用Action和Filter达到相同的目的。比如说，您希望你的插件可以更改一段日志的文本，您可能会往<code>publish_post</code>中添加一个Action函数（这段文字在被加入到数据库之前被修改了），或者往 <code>the_content</code>中添加一个Filter函数（这段文字在被发送给浏览器显示之前，被更改了）。</p>
<h3>Action</h3>
<p>Action由<a href="http://sexywp.com/tags/wordpress" title="Becoming Charles-WP">WordPress</a>中发生的一些特定的事件所触发，比如发布一篇日志，更改主题，或者在管理面板显示一个页面。您的插件可以通过执行一个PHP函数来响应事件，实现以下几个目的：</p>
<ul>
<li>修改数据库数据</li>
<li>发送Email信息</li>
<li>修改将要在浏览器上呈现的内容（管理员看到的或者访客看到的）</li>
</ul>
<p>要达到上述的目的，需要遵循的步骤为（下文有详细的描述）：</p>
<ol>
<li>在您的插件文件中，创建一个在某个事件发生时，需要运行的PHP函数。</li>
<li>通过调用<code>add_action</code>函数，将您的函数插入到<a href="http://wordpress.org/" title="WP">WordPress</a>中。</li>
<li>将您的插件文件放到插件目录下，然后激活它。</li>
</ol>
<h4>创建一个Action 函数</h4>
<p>在您的插件中创建一个Action的第一个步骤是创建一个能响应Action的函数，并且将它写入到您的插件文件里（您的插件文件最后会被放到<em>content/<a href="http://sexywp.com/tags/plugins" class="st_tag internal_tag" rel="tag" title="标签 plugins 下的日志">plugins</a></em>目录）。举个例子，如果您想要您的朋友在您发表了新文章的时候收到一封邮件，您可以创建下述函数：</p>
<p><code><br />
function email_friends($post_ID) {<br />
$friends = ‘bob@example.org,susie@example.org’;<br />
mail($friends, "sally’s blog updated",<br />
‘I just put something on my blog: http://blog.example.com’);<br />
return $post_ID;<br />
}<br />
</code></p>
<p>对于大多数的Action来说，您的函数要接受一个单一参数（通常是日志或这评论的ID，这要视情况而定）。有些Action接受多于一个的参数，您可以查看WordPress的Action文档，或者直接查看WordPress源代码来取得第一手资料。除了一个参数外，您还可以访问WordPress的全局变量，并且调用其他WordPress函数或者您插件中的其他函数（或者其他插件中的函数）。</p>
<p><strong>注意</strong>：您要始终留意，是否WordPress本身或者其他的插件已经使用了您想用的那个函数的名字。关于这点，您可以查看<a href="http://codex.wordpress.org/Writing_a_Plugin#Avoiding_Function_Name_Collisions" title="Avoiding Function Name Collisions">避免函数名冲突</a>这篇文章来获取更详细的信息。</p>
<h4>Hook到WordPress</h4>
<p>当您定义好您的函数后，下一步就是将您的函数Hook或者注册到WordPress中。在您的插件文件中的全局空间中调用函数 add_action()就可以了：</p>
<pre xml:space="preserve">
add_action(’hook_name’, ‘your_filter’, [priority], [accepted_args]);
</pre>
<p>该函数中：</p>
<ul>
<li><code>hook_name</code>是WordPress提供的供hook用的函数名，也即您的函数将关联到的事件的名称。</li>
<li><code>your_function_name</code> 是您希望在<code>hook_name</code>指定的事件发生时执行的函数的名称。这可以是一个在WordPress中定义好的标准的函数，也可以是一个您自己定义的函数（比如上面提到的<code>email_friends</code>）</li>
<li><code>priority</code>是一个可选的整型参数，可以指定可以指定关联到某个特定的函数的执行顺序。默认值是10。数字较小的执行较早，如果优先级相同，则按照他们hook进来的顺序先后来执行。</li>
<li><code>accepted_args</code>是一个可选的整型参数，它定义了您的函数可以接受多少个参数，默认是1。这个参数很有用，因为有些事件发生的时候，可能会向您的函数传递多于一个的参数。这个参数是从WordPress 1.5.1后的版本才开始有的。</li>
</ul>
<p>继续前文的例子，我们可以将下面一行代码加入到插件的文件中：</p>
<pre xml:space="preserve">
add_filter(’comment_text’,'filter_profanity’);
</pre>
<p>相似的，您也可以将一个函数从Action中移除。你可以参考移除Action来获得详细的信息。</p>
<h4>安装和激活</h4>
<p>让您的插件奏效的最后一个步骤就是安装和激活和插件了。您写好的函数和对add_action的调用，必须放到同一个文件中，插件文件必须被装到wp-content/plugins目录中。一旦插件安装好，您需要访问管理面板来激活您的插件。</p>
<h4>目前已有的Action Hook</h4>
<p>参见<a href="http://codex.wordpress.org/Plugin_API/Action_Reference" title="Plugin API Action Reference">Plugin API/Action Reference</a>来查看WordPress中的当前的Action列表。</p>
<h3>Filter</h3>
<p>Filter是在WordPress执行过程中，传递数据时，在对数据采取某种行动（将数据写入到数据库或者发送给访客的浏览器）之前执行的。（当WordPress生成页面时）Filter就位于数据库和浏览器之间，（当WordPress向数据库添加日志和评论时）Filter就位于浏览器和数据库之间。WordPress中的绝大多数的输入和输出过程都要通过至少一个Filter。WordPress自己有一些默认的Filter，您可以在插件中使用自己的Filter。</p>
<p>将您自己的Filter添加到WordPress中，遵循以下几个步骤：</p>
<ul>
<li>创建一个PHP函数来过滤数据。</li>
<li>通过调用add_filter将这个Filter添加到WordPress中。</li>
<li>将您的PHP函数写入到一个插件文件中，激活它。</li>
</ul>
<h4>创建一个Filter函数</h4>
<p>一个Filter函数把未经修改的数据作为输入，返回修改过的数据（或者有的时候返回的空值，表明这些数据应该被删除）。如果您的Filter没有修改数据，那么原始的数据必须被返回回去，以便于后续的插件可以继续它们的修改工作。</p>
<p>所以，在您的插件中创建一个Filter的第一步，就是创建一个PHP函数来执行过滤动作，并且，将这个函数写入到您的插件文件中去。再举个例子，如果您需要确定您的日志或者评论中没有出现违禁词汇，您可以定义一个全局变量，里面包含了全部的违禁词汇的列表，然后创建下面的PHP函数：</p>
<p><code><br />
function filter_profanity($content) {<br />
global $profanities;<br />
foreach($profanities as $profanity) {<br />
$content=str_ireplace($profanity,’{censored}’,$content);<br />
}<br />
return $content;<br />
}<br />
</code></p>
<p>注意：同样要小心您的函数的命名，不要和其他的WordPress函数和其他插件的函数冲突。</p>
<h4>将您的Filter Hook到WordPress</h4>
<p>在您的函数定义完毕后，下一步就是将您的函数"hook"或者说注册到WordPress中。在您的插件文件中，调用add_filter函数：</p>
<p><code><br />
add_filter(’hook_name’, ‘your_filter’, [priority], [accepted_args]);<br />
</code></p>
<p>其中：</p>
<ul>
<li><code>hook_name</code> 是WordPress提供的供hook的函数的名称，定义了您可以加入您自己的Filter的插入点。</li>
<li><code>your_filter</code>是您的filter函数的名称。这个函数可以是一个WordPress标准PHP函数，也即在WordPress内核中定义的函数，也可以使一个您自己定义的函数。</li>
<li><code>priority</code>是一个可选的整型参数，标明了注册到某个特定的filter中的函数的执行顺序。默认是10。较小的数字执行时较靠前。如果priority值相同，那么按照注册的先后顺序来执行。</li>
<li><code>accepted_args</code>是一个可选参数，用来标明您的函数能够接受的参数的个数，默认是1，某些hook可以像您的函数传递超过一个的参数。</li>
</ul>
<p>继续上面的例子，您可以使用下面的代码，让WordPress过滤您评论中的违禁词汇：</p>
<p><code><br />
add_filter(’comment_text’,'filter_profanity’);<br />
</code></p>
<p>您也可以使用<code>remove_filter()</code>函数来将一个Filter移除。</p>
<h4>安装和激活</h4>
<p>最后一个步骤就是使您的filter运作起来。你需要做的就是将您的插件文件放到<em><a href="http://sexywp.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 WordPress 下的日志">wordpress</a>/plugins</em>目录，然后到后台管理界面激活。</p>
<h4>目前WordPress中可以注册的Filter</h4>
<p>参见Plugin API/Filter Reference。</p>
<h4>例子</h4>
<p>下面是一个例子，是Ozh曾经在邮件列表中描述过的，该插件修改（或者说覆盖）了默认的<code>bloginfo()</code>函数。这需要修改内核函数的行为。</p>
<p><code><br />
add_filter(’bloginfo’, ‘mybloginfo’, 1, 2);<br />
add_filter(’bloginfo_url’, ‘mybloginfo’, 1, 2);</p>
<p>function mybloginfo($result=”, $show=”) {<br />
switch ($show) {<br />
case ‘wpurl’:<br />
$result = SITE_URL;<br />
break;<br />
case ‘<a href="http://sexywp.com/tags/template" class="st_tag internal_tag" rel="tag" title="标签 template 下的日志">template</a>_directory’:<br />
$result = TEMPL_DIR;<br />
break;<br />
default:<br />
}<br />
return $result;<br />
}<br />
</code></p>
<h3>移除Action和Filter</h3>
<p>在某些情况下，您可能会发现，您的插件需要禁用WordPress中的内建Action或者Filter之一，或者某个其它插件添加的函数。您可以通过调用<code>remove_filter(’filter_hook’,'filter_function’)</code>或者 <code>remove_action(’action_hook’,'action_function’)</code>来达到目的。</p>
<p>比如，<code>remove_action(’publish_post’,'generic_ping’);</code>可以在您发表日志的时候，阻止您的博客向外发送ping。</p>
<p>注意，如果一个hook不是使用默认的优先级（priority）注册到系统中，那么您必须在<code>remove_action()</code>中指定那个hook使用的优先级。一般来说还要注意，除非您很清楚那个函数在干什么并且为什么要那么做，请不要移除任何函数。</p>
<h3>缺省加载的Filter和Action</h3>
<p>最可靠的获知WordPress缺省加载了哪些Filter和Action的方法就是在其源代码中搜索<code>add_filter</code>和<code>add_action</code>函数的调用。</p>
<h4>WordPress 2.1</h4>
<p>在WordPress2.1中，绝大多数的Filter和Action的加载是在<em>wp-include/default-filters.php</em>文件中进行的。其他的在下列的文件中加载：</p>
<ul>
<li><tt>wp-admin/admin-ajax.php</tt></li>
<li><tt>wp-admin/admin-functions.php</tt></li>
<li><tt>wp-admin/custom-header.php</tt></li>
<li><tt>wp-admin/edit.php</tt></li>
<li><tt>wp-admin/index.php</tt></li>
<li><tt>wp-admin/options-permalink.php</tt></li>
<li><tt>wp-admin/upload-functions.php</tt></li>
<li><tt>wp-admin/upload.php</tt></li>
<li><tt>wp-includes/bookmark.php</tt></li>
<li><tt>wp-includes/general-template.php</tt></li>
<li><tt>wp-includes/kses.php</tt></li>
<li><tt>wp-includes/plugin.php</tt></li>
<li><tt>wp-includes/rewrite.php</tt></li>
<li><tt>wp-includes/template-loader.php</tt></li>
<li><tt>wp-includes/theme.php</tt></li>
</ul>
<h4>WordPress 2.5</h4>
<p>(以后我会完善这个部分)</p>
<h3>您可以覆盖的函数</h3>
<p>除了使用hook（action和filter），另一个插件修改Wordpress行为方式是覆盖WordPress的函数。实际上，有一小组函数，是WordPess希望被插件覆盖的。在所有的插件都已经启动后，如果他们还没有被覆盖的话，WordPress才启动这些函数。</p>
<p>这些函数在<em>wp-include/pluggable.php</em>文件中定义。这里有一个列表（WP2.1）。</p>
<ul>
<li><tt>set_current_user</tt></li>
<li><tt>wp_set_current_user</tt></li>
<li><tt>wp_get_current_user</tt></li>
<li><tt>get_currentuserinfo</tt></li>
<li><tt>get_userdata</tt></li>
<li><tt>update_user_cache</tt></li>
<li><tt>get_userdatabylogin</tt></li>
<li><tt>wp_mail</tt></li>
<li><tt>wp_login</tt></li>
<li><tt>is_user_logged_in</tt></li>
<li><tt>auth_redirect</tt></li>
<li><tt>check_admin_referer</tt></li>
<li><tt>wp_redirect</tt></li>
<li><tt>wp_get_cookie_login</tt></li>
<li><tt>wp_setcookie</tt></li>
<li><tt>wp_clearcookie</tt></li>
<li><tt>wp_notify_postauthor</tt></li>
<li><tt>wp_notify_moderator</tt></li>
<li><tt>wp_new_user_notification</tt></li>
<li><tt>wp_verify_nonce</tt></li>
<li><tt>wp_create_nonce</tt></li>
<li><tt>wp_salt</tt></li>
<li><tt>wp_hash</tt></li>
</ul>
<p><br/></p>

	标签：<a href="http://sexywp.com/tags/docs" title="docs" rel="tag">docs</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/wordpress-plugin-api.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

