[wp-hackers] applying filters & plugins

miro at apollo.lv miro at apollo.lv
Fri Sep 24 21:56:22 UTC 2004


Hi

First of all I must admit I'm a fan of Textile, and tried both original 
Textile by Dean and other implementations (TextilePHP)..

Anyway, I like Jim and Lissa's 
<http://jimandlissa.com/project/textilephp> TextilePHP and wanted to 
make it pluggable to WP..

Since TextilePHP is a class, text formatting best is achieved by simply 
calling $text = textile::process($text).

but, there's one limitation in WP's /wp-includes/apply_filters() 
function which does not permit calling textile::process() as functions 
are called by $string = $function($string) and PHP does not allow to 
call methods witin initialized classes using $function(), even if 
$function = 'class::method'..

my idea is:

1) make WP call filter functions a little bit smarter - if methods are 
called within uninitialized classes (they contain ::), call them using 
call_user_func() function which allows method calling within class..

if (preg_match('/(\S*)::(\S*)/', $function, $reg)) {
	$string = call_user_func(array($reg[1], $reg[2]), $string);
} else {
	$string = $function($string);
}

2) in newly made plugin add these lines in the end of the file:

add_filter('the_content', 'textile::process', 6);
add_filter('the_excerpt', 'textile::process', 6);
add_filter('comment_text', 'textile:process', 6);

textile::process is an example..

3) doing it this way it's possible to easily add any complicated class 
which can parse text by invoking only one method.. no need to rewrite 
the whole class only to get out the methods of out of class (as it was 
done with textile1 and textile2 for WP)..





More information about the hackers mailing list