File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -507,11 +507,8 @@ function do_action( $hook_name, ...$arg ) {
507507 $ wp_current_filter [] = $ hook_name ;
508508 }
509509
510- if ( empty ( $ arg ) ) {
510+ if ( array () === $ arg ) {
511511 $ arg [] = '' ;
512- } elseif ( is_array ( $ arg [0 ] ) && 1 === count ( $ arg [0 ] ) && isset ( $ arg [0 ][0 ] ) && is_object ( $ arg [0 ][0 ] ) ) {
513- // Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`.
514- $ arg [0 ] = $ arg [0 ][0 ];
515512 }
516513
517514 $ wp_filter [ $ hook_name ]->do_action ( $ arg );
Original file line number Diff line number Diff line change @@ -133,6 +133,26 @@ public function action2( $arg ) {
133133 return $ arg ;
134134 }
135135
136+ /**
137+ * @since 6.6.0
138+ */
139+ public function action3 ( array $ arg ) {
140+ $ current_filter = $ this ->current_filter ();
141+
142+ if ( $ this ->debug ) {
143+ dmp ( __FUNCTION__ , $ current_filter );
144+ }
145+
146+ $ this ->events [] = array (
147+ 'action ' => __FUNCTION__ ,
148+ 'hook_name ' => $ current_filter ,
149+ 'tag ' => $ current_filter , // Back compat.
150+ 'args ' => func_get_args (),
151+ );
152+
153+ return $ arg ;
154+ }
155+
136156 /**
137157 * @since UT (3.7.0)
138158 */
Original file line number Diff line number Diff line change @@ -96,6 +96,24 @@ public function test_has_action() {
9696 $ this ->assertFalse ( has_action ( $ hook_name ) );
9797 }
9898
99+ /**
100+ * One tag with array with 1 object to ensure it will stay an array and not become an object
101+ *
102+ * @covers ::do_action
103+ */
104+ public function test_action_args_1 () {
105+ $ a = new MockAction ();
106+ $ hook_name = __FUNCTION__ ;
107+ $ val = new stdClass ();
108+
109+ add_action ( $ hook_name , array ( $ a , 'action3 ' ) );
110+ do_action ( $ hook_name , array ( $ val ) );
111+
112+ $ call_count = $ a ->get_call_count ();
113+ $ argsvar = $ a ->get_args ();
114+ $ this ->assertSame ( array ( $ val ), array_pop ( $ argsvar ) );
115+ }
116+
99117 /**
100118 * One tag with multiple actions.
101119 *
You can’t perform that action at this time.
0 commit comments