Allow multiple args to be passed to apply_filters and do_action. Move some code into merge_filters. Use call_user_func_array so that args can be passed by reference. Provide a default for the second arg to do_action so that we do not have to put empty strings in the do_action calls. Bug 768. Hat tip: morganiq

git-svn-id: http://svn.automattic.com/wordpress/trunk@2184 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2005-02-01 06:20:54 +00:00
parent c407b7b457
commit 9838608868
8 changed files with 42 additions and 19 deletions

View File

@ -218,7 +218,7 @@ if ($pagenow == 'index.php') {
} }
} elseif ( !isset($wp_template_redirect) ) { } elseif ( !isset($wp_template_redirect) ) {
$wp_template_redirect = true; $wp_template_redirect = true;
do_action('template_redirect', ''); do_action('template_redirect');
if ( is_feed() ) { if ( is_feed() ) {
include(ABSPATH . '/wp-feed.php'); include(ABSPATH . '/wp-feed.php');
exit; exit;

View File

@ -7,6 +7,6 @@
</div> </div>
<?php do_action('wp_footer', ''); ?> <?php do_action('wp_footer'); ?>
</body> </body>
</html> </html>

View File

@ -14,7 +14,7 @@
<!-- Gorgeous design by Michael Heilemann - http://binarybonsai.com/kubrick/ --> <!-- Gorgeous design by Michael Heilemann - http://binarybonsai.com/kubrick/ -->
<?php /* "Just what do you think you're doing Dave?" */ ?> <?php /* "Just what do you think you're doing Dave?" */ ?>
<?php do_action('wp_footer', ''); ?> <?php do_action('wp_footer'); ?>
</body> </body>
</html> </html>

View File

@ -1139,7 +1139,7 @@ class WP_Rewrite {
// Put them together. // Put them together.
$this->rules = $page_rewrite + $root_rewrite + $comments_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite + $post_rewrite; $this->rules = $page_rewrite + $root_rewrite + $comments_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite + $post_rewrite;
do_action('generate_rewrite_rules', ''); do_action('generate_rewrite_rules', array(&$this));
$this->rules = apply_filters('rewrite_rules_array', $this->rules); $this->rules = apply_filters('rewrite_rules_array', $this->rules);
return $this->rules; return $this->rules;
} }

View File

@ -384,7 +384,7 @@ function user_can_edit_user($user_id, $other_user) {
function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) { function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {
global $wpdb; global $wpdb;
do_action('wp_blacklist_check', ''); do_action('wp_blacklist_check');
if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) { if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) {
foreach ($chars[1] as $char) { foreach ($chars[1] as $char) {
@ -449,7 +449,7 @@ function wp_new_comment( $commentdata, $spam = false ) {
$time_lastcomment = mysql2date('U', $lasttime); $time_lastcomment = mysql2date('U', $lasttime);
$time_newcomment = mysql2date('U', $now_gmt); $time_newcomment = mysql2date('U', $now_gmt);
if ( ($time_newcomment - $time_lastcomment) < 15 ) { if ( ($time_newcomment - $time_lastcomment) < 15 ) {
do_action('comment_flood_trigger', ''); do_action('comment_flood_trigger');
die( __('Sorry, you can only post a new comment once every 15 seconds. Slow down cowboy.') ); die( __('Sorry, you can only post a new comment once every 15 seconds. Slow down cowboy.') );
} }
} }

View File

@ -870,7 +870,7 @@ function is_new_day() {
// Filters: these are the core of WP's plugin architecture // Filters: these are the core of WP's plugin architecture
function apply_filters($tag, $string, $filter = true) { function merge_filters($tag) {
global $wp_filter; global $wp_filter;
if (isset($wp_filter['all'])) { if (isset($wp_filter['all'])) {
foreach ($wp_filter['all'] as $priority => $functions) { foreach ($wp_filter['all'] as $priority => $functions) {
@ -883,15 +883,22 @@ function apply_filters($tag, $string, $filter = true) {
} }
if (isset($wp_filter[$tag])) { if (isset($wp_filter[$tag]))
ksort($wp_filter[$tag]); ksort($wp_filter[$tag]);
}
function apply_filters($tag, $string) {
global $wp_filter;
$args = array($string) + array_slice(func_get_args(), 3);
merge_filters($tag);
if (isset($wp_filter[$tag])) {
foreach ($wp_filter[$tag] as $priority => $functions) { foreach ($wp_filter[$tag] as $priority => $functions) {
if (!is_null($functions)) { if (!is_null($functions)) {
foreach($functions as $function) { foreach($functions as $function) {
if ($filter) $string = call_user_func_array($function, $args);
$string = call_user_func($function, $string);
else
call_user_func($function, $string);
} }
} }
} }
@ -924,9 +931,25 @@ function remove_filter($tag, $function_to_remove, $priority = 10) {
// The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content // The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content
function do_action($tag, $string) { function do_action($tag, $arg = '') {
apply_filters($tag, $string, false); global $wp_filter;
return $string;
if ( is_array($arg) )
$args = $arg + array_slice(func_get_args(), 2);
else
$args = array($action) + array_slice(func_get_args(), 2);
merge_filters($tag);
if (isset($wp_filter[$tag])) {
foreach ($wp_filter[$tag] as $priority => $functions) {
if (!is_null($functions)) {
foreach($functions as $function) {
$string = call_user_func_array($function, $args);
}
}
}
}
} }
function add_action($tag, $function_to_add, $priority = 10) { function add_action($tag, $function_to_add, $priority = 10) {
@ -1064,7 +1087,7 @@ function update_user_cache() {
} }
function wp_head() { function wp_head() {
do_action('wp_head', ''); do_action('wp_head');
} }
function is_single ($post = '') { function is_single ($post = '') {

View File

@ -54,7 +54,7 @@ function wp_register( $before = '<li>', $after = '</li>' ) {
} }
function wp_meta() { function wp_meta() {
do_action('wp_meta', 1); do_action('wp_meta');
} }
function bloginfo($show='') { function bloginfo($show='') {

View File

@ -120,10 +120,10 @@ if ( !get_magic_quotes_gpc() ) {
} }
function shutdown_action_hook() { function shutdown_action_hook() {
do_action('shutdown', ''); do_action('shutdown');
} }
register_shutdown_function('shutdown_action_hook'); register_shutdown_function('shutdown_action_hook');
// Everything is loaded. // Everything is loaded.
do_action('init', ''); do_action('init');
?> ?>