<?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; apis</title>
	<atom:link href="http://sexywp.com/tags/apis/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>创建自己的filter</title>
		<link>http://sexywp.com/create-your-own-filter.htm</link>
		<comments>http://sexywp.com/create-your-own-filter.htm#comments</comments>
		<pubDate>Wed, 03 Sep 2008 15:31:31 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[advanced topics]]></category>
		<category><![CDATA[apis]]></category>
		<category><![CDATA[hooks]]></category>

		<guid isPermaLink="false">http://www.charlestang.cn/?p=232</guid>
		<description><![CDATA[我用这篇文章来简单介绍一下如何创建一个filter。



用简单的话来说，就是调用apply_filters函数。

<span class="readmore"><a href="http://sexywp.com/create-your-own-filter.htm" title="创建自己的filter">Keep Reading --- 512 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中的Hook机制" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fcreate-your-own-filter.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中的Hook机制</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%2Fcreate-your-own-filter.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="使用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%2Fcreate-your-own-filter.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主题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Ffree-wordpress-themes.htm&from=http%3A%2F%2Fsexywp.com%2Fcreate-your-own-filter.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/10603183.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主题</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="如何获得一个分类的ID" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-get-a-cat-id.htm&from=http%3A%2F%2Fsexywp.com%2Fcreate-your-own-filter.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;">如何获得一个分类的ID</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>我用这篇文章来简单介绍一下如何创建一个filter。</p>
<p><span id="more-232"></span></p>
<p>用简单的话来说，就是调用<code>apply_filters</code>函数。</p>
<p>然后，我们来复杂点说：</p>
<p>如果你调用了<code>apply_filters('my_own_message', $mess);</code>，那么，你就创建了一个名字为my_own_message的filter了。</p>
<p>那么这个my_own_message的含义是什么呢？按照我个人的理解来说，就是将来有一群接受一个参数$mess的函数，可以被调用。而且，就恰恰会在你调用apply_filters的地方被调用。</p>
<p>再举个不恰当的例子，就好像你是一个小朋友，你从你大款同学那里借了一个变形金刚，爱不释手，但是终于玩够了，要还了，又觉得还是不爽，这时候，你喊了一嗓子，“要玩变形金刚的排队过来玩，玩完还给那款爷”，小朋友们兴高采烈，但是秩序井然地过来玩了，当然，你们这么一坨人玩过了，那个玩意儿能完好无损的可能性也很小了，不是少了条胳臂缺了条腿，就是脸上多了两撇小胡子……最后，那可怜的变形金刚面目全非的回到了大款小朋友的手上……</p>
<p>你喊那一嗓子，就好像是apply_filters了，然后那些小朋友就是名字为“要玩变形金刚”这个filter上的函数，那个变形金刚就是那个传递给函数的参数，缺胳臂少腿，多了小胡子，就是这些filter们作用在变形金刚这个参数上的效果，最重要的是，这个变形金刚最终还给了那个大款小朋友，也即filter们必须要把拿来的东西返回去。</p>
<p>哈哈……又胡扯了一番……</p>
<p>举个例子：</p>
<p>下面是某主题的footer.php</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Gray;">&lt;div id=&quot;footer&quot;&gt;<br />&nbsp;&nbsp; &nbsp;&lt;p&gt;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;a href=&quot;http://wordpress.org/&quot;&gt;WordPress&lt;/a&gt; : &lt;a href=&quot;http://validator.w3.org/check?uri=referer&quot;&gt;xhtml&lt;/a&gt; : <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;br /&gt;&lt;a href=&quot;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Blue;">bloginfo</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">rss2_url</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;Entries (RSS)&lt;/a&gt;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;and &lt;a href=&quot;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Blue;">bloginfo</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">comments_rss2_url</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;Comments (RSS)&lt;/a&gt;.<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Blue;">print_extra_footer_message</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">注意这个函数</span><span style="color: #ffa500;"></span><span style="color: Blue;">?&gt;</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;!-- </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Green;">echo</span><span style="color: Gray;"> </span><span style="color: Blue;">get_num_queries</span><span style="color: Olive;">(</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Blue;">?&gt;</span><span style="color: Gray;"> queries. </span><span style="color: Blue;">&lt;?php</span><span style="color: Gray;"> </span><span style="color: Blue;">timer_stop</span><span style="color: Olive;">(</span><span style="color: Maroon;">1</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Blue;">?&gt;</span><span style="color: Gray;"> seconds. --&gt;<br />&nbsp;&nbsp; &nbsp;&lt;/p&gt;<br />&lt;/div&gt;</span></div></div>
<p>然后，这是某主题的functions.php节选</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;">print_extra_footer_message</span><span style="color: Olive;">(</span><span style="color: #00008b;">$message</span><span style="color: Gray;">=</span><span style="color: #8b0000;">'</span><span style="color: #8b0000;">'</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">echo</span><span style="color: Gray;">&nbsp; </span><span style="color: Blue;">apply_filters</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">extra_footer_message</span><span style="color: #8b0000;">'</span><span style="color: Gray;">,</span><span style="color: #00008b;">$message</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>好，我创建了一个filter了。</p>
<p>最后，思考题：</p>
<p>1. filter到底有什么用？</p>
<p>2. 对一个插件作者来说，filter意味着什么？</p>
<p>3. 对于一个主题作者来说，filter又意味着什么？</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中的Hook机制" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm&from=http%3A%2F%2Fsexywp.com%2Fcreate-your-own-filter.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中的Hook机制</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%2Fcreate-your-own-filter.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="使用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%2Fcreate-your-own-filter.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主题" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Ffree-wordpress-themes.htm&from=http%3A%2F%2Fsexywp.com%2Fcreate-your-own-filter.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/10603183.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主题</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="如何获得一个分类的ID" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-get-a-cat-id.htm&from=http%3A%2F%2Fsexywp.com%2Fcreate-your-own-filter.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;">如何获得一个分类的ID</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/advanced-topics" title="advanced topics" rel="tag">advanced topics</a>, <a href="http://sexywp.com/tags/apis" title="apis" rel="tag">apis</a>, <a href="http://sexywp.com/tags/hooks" title="hooks" rel="tag">hooks</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/create-your-own-filter.htm/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

