Eric @ EricBess WebHome

一味思考而不行动,将在不知不觉中变得无意义

Chinese (Simplified) flagItalian flagKorean flagPortuguese flagEnglish flagGerman flagFrench flagSpanish flagJapanese flagArabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagCroat flagDanish flagFinnish flagHindi flagPolish flagRumanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flagSerbian flagSlovak flagSlovenian flagUkrainian flagVietnamese flag
By N2H

WordPress插件开发需熟知的4个函数

add_action、do_action、add_filter、apply_filters

*_action面向Web流,*_filter*面向数据流。add_*是用户用来挂接WordPress预留接口的函数。如果需要自己定义供他人挂接的扩展点,可以使用do_action,apply_filters来部署,通常不是要改造到骨头不会用上它们。

之所以谈到这个话题是因为文件上传类型限制引起的,搜遍整个网络,关于上传及过滤处理的并不多,其中找到一篇中文的博文,作者毫不客气直接修改WordPress内部源码文件。我想WordPress不至于如此吧,于是就产生了下面的代码片段:

Click to continue reading

01月 10th, 2008 Posted by eric | Wordpress Programming | no comments

How to build a custom profile page in Wordpress

(edit: this doesn't work in wordpress 2.2, below code was tested in wordpress 2.0, source: http://www.goudendouche.com)
Ok, now that I've got the custom register and login pages working, I also want a custom profile page. This is done in a different way from the register and login pages, but it's do-able.

First you'll need to make a custom page template for this, so in your theme dir, look for the file called page.php. Make a copy of this, and name it profilepage.php. In the beginning of the file, add the following lines of code:

< ?php
/*
Template Name: Profilepage
*/
 
//Next, look for lines that go like
 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
... some php and html code ...

And replace this whole bit with the following code:

Click to continue reading

03月 13th, 2006 Posted by admin | Wordpress Programming | no comments

action(wp_head)

add_action('wp_head',"function name")

功能:

向wp_head()输送html 头代码。

wp_head()的引用 [load]

例子:

pagenavi插件:HTML HEAD 插入信息

1
2
3
4
5
6
7
### Function: Page Navigation CSS
add_action('wp_head', 'pagenavi_css');
function pagenavi_css() {
	echo "\n".'<!-- Start Of Script Generated By WP-PageNavi 2.20 -->'."\n";
	echo '<link rel="stylesheet" href="'.get_option('siteurl').'/wp-content/plugins/pagenavi/pagenavi-css.css" type="text/css" media="screen" />'."\n";
	echo '<!-- End Of Script Generated By WP-PageNavi 2.20 -->'."\n";
}

HTML HEAD 插入结果:

1
2
3
<!-- Start Of Script Generated By WP-PageNavi 2.20 -->
<link rel="stylesheet" href="http://www.ericbess.com/ericblog/wp-content/plugins/pagenavi/pagenavi-css.css" type="text/css" media="screen" />
<!-- End Of Script Generated By WP-PageNavi 2.20 -->

Another DEMO:

1
2
3
4
5
6
7
8
9
    /****************************************************************************
     * add_js
     *    > Add the coolcode.js to the footer
     ****************************************************************************/
    function add_js() {
        echo '<script type="text/javascript" src="'
            . get_settings('home')
            . "/wp-content/plugins/coolcode/coolcode.js\"></script>\n";
    }

02月 26th, 1978 Posted by eric | Wordpress Programming | no comments

Page 2 of 2«12