From 9838608868cf461618a621954619fac721a85c66 Mon Sep 17 00:00:00 2001 From: rboren Date: Tue, 1 Feb 2005 06:20:54 +0000 Subject: [PATCH] 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 --- wp-blog-header.php | 2 +- wp-content/themes/classic/footer.php | 2 +- wp-content/themes/default/footer.php | 2 +- wp-includes/classes.php | 2 +- wp-includes/functions-post.php | 4 +- wp-includes/functions.php | 43 +++++++++++++++++----- wp-includes/template-functions-general.php | 2 +- wp-settings.php | 4 +- 8 files changed, 42 insertions(+), 19 deletions(-) diff --git a/wp-blog-header.php b/wp-blog-header.php index 3899ee745d..11ea874c9b 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -218,7 +218,7 @@ if ($pagenow == 'index.php') { } } elseif ( !isset($wp_template_redirect) ) { $wp_template_redirect = true; - do_action('template_redirect', ''); + do_action('template_redirect'); if ( is_feed() ) { include(ABSPATH . '/wp-feed.php'); exit; diff --git a/wp-content/themes/classic/footer.php b/wp-content/themes/classic/footer.php index 01d647e50a..2d5b2580e6 100644 --- a/wp-content/themes/classic/footer.php +++ b/wp-content/themes/classic/footer.php @@ -7,6 +7,6 @@ - + \ No newline at end of file diff --git a/wp-content/themes/default/footer.php b/wp-content/themes/default/footer.php index 8ab24e311f..ecd0b1819e 100644 --- a/wp-content/themes/default/footer.php +++ b/wp-content/themes/default/footer.php @@ -14,7 +14,7 @@ - + \ No newline at end of file diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 583b4f1361..6c977ac171 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -1139,7 +1139,7 @@ class WP_Rewrite { // Put them together. $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); return $this->rules; } diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index c86c89a8fc..efd92c8c7c 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -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) { global $wpdb; - do_action('wp_blacklist_check', ''); + do_action('wp_blacklist_check'); if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) { foreach ($chars[1] as $char) { @@ -449,7 +449,7 @@ function wp_new_comment( $commentdata, $spam = false ) { $time_lastcomment = mysql2date('U', $lasttime); $time_newcomment = mysql2date('U', $now_gmt); 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.') ); } } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index ed39a2dac8..a50f9a4df7 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -870,7 +870,7 @@ function is_new_day() { // Filters: these are the core of WP's plugin architecture -function apply_filters($tag, $string, $filter = true) { +function merge_filters($tag) { global $wp_filter; if (isset($wp_filter['all'])) { 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]); +} + +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) { if (!is_null($functions)) { foreach($functions as $function) { - if ($filter) - $string = call_user_func($function, $string); - else - call_user_func($function, $string); + $string = call_user_func_array($function, $args); } } } @@ -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 -function do_action($tag, $string) { - apply_filters($tag, $string, false); - return $string; +function do_action($tag, $arg = '') { + global $wp_filter; + + 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) { @@ -1064,7 +1087,7 @@ function update_user_cache() { } function wp_head() { - do_action('wp_head', ''); + do_action('wp_head'); } function is_single ($post = '') { diff --git a/wp-includes/template-functions-general.php b/wp-includes/template-functions-general.php index fc858ea140..9df7f73daf 100644 --- a/wp-includes/template-functions-general.php +++ b/wp-includes/template-functions-general.php @@ -54,7 +54,7 @@ function wp_register( $before = '
  • ', $after = '
  • ' ) { } function wp_meta() { - do_action('wp_meta', 1); + do_action('wp_meta'); } function bloginfo($show='') { diff --git a/wp-settings.php b/wp-settings.php index af4daf4a54..09b814846d 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -120,10 +120,10 @@ if ( !get_magic_quotes_gpc() ) { } function shutdown_action_hook() { - do_action('shutdown', ''); + do_action('shutdown'); } register_shutdown_function('shutdown_action_hook'); // Everything is loaded. -do_action('init', ''); +do_action('init'); ?> \ No newline at end of file