From 93a7a9617f21c7649ef978dc68ff49cdc621d0c7 Mon Sep 17 00:00:00 2001
From: ryan <ryan@1a063a9b-81f0-0310-95a4-ce76da25c4cd>
Date: Fri, 8 Sep 2006 23:19:29 +0000
Subject: [PATCH] do_action and apply_filters arg passing sanity from mdawaffe.
 fixes #3116

git-svn-id: http://svn.automattic.com/wordpress/trunk@4177 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
 wp-includes/plugin.php | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php
index f4b5e3e1e6..462a3a14e7 100644
--- a/wp-includes/plugin.php
+++ b/wp-includes/plugin.php
@@ -26,7 +26,9 @@ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
 function apply_filters($tag, $string) {
 	global $wp_filter;
 
-	$args = array_slice(func_get_args(), 2);
+	$args = array($string);
+	for ( $a = 2; $a < func_num_args(); $a++ )
+		$args[] = func_get_arg($a);
 
 	merge_filters($tag);
 
@@ -37,18 +39,15 @@ function apply_filters($tag, $string) {
 		if ( !is_null($functions) ) {
 			foreach($functions as $function) {
 
-				$all_args = array_merge(array($string), $args);
 				$function_name = $function['function'];
 				$accepted_args = $function['accepted_args'];
 
-				if ( $accepted_args == 1 )
-					$the_args = array($string);
-				elseif ( $accepted_args > 1 )
-					$the_args = array_slice($all_args, 0, $accepted_args);
+				if ( $accepted_args > 0 )
+					$the_args = array_slice($args, 0, $accepted_args);
 				elseif ( $accepted_args == 0 )
 					$the_args = NULL;
 				else
-					$the_args = $all_args;
+					$the_args = $args;
 
 				$string = call_user_func_array($function_name, $the_args);
 			}
@@ -102,9 +101,13 @@ function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1)
 
 function do_action($tag, $arg = '') {
 	global $wp_filter;
-	$args = array($arg);
+	$args = array();
+	if ( is_array($arg) && 1 == count($arg) && is_object($arg[0]) ) // array(&$this)
+		$args[] =& $arg[0];
+	else
+		$args[] = $arg;
 	for ( $a = 2; $a < func_num_args(); $a++ )
-		$args[] = func_get_args($a);
+		$args[] = func_get_arg($a);
 
 	merge_filters($tag);
 
@@ -118,15 +121,12 @@ function do_action($tag, $arg = '') {
 				$function_name = $function['function'];
 				$accepted_args = $function['accepted_args'];
 
-				if ( $accepted_args == 1 ) {
-					$the_args = array($arg);
-				} elseif ( $accepted_args > 1 ) {
+				if ( $accepted_args > 0 )
 					$the_args = array_slice($args, 0, $accepted_args);
-				} elseif ( $accepted_args == 0 ) {
+				elseif ( $accepted_args == 0 )
 					$the_args = NULL;
-				} else {
+				else
 					$the_args = $args;
-				}
 
 				$string = call_user_func_array($function_name, $the_args);
 			}