[wp-trac] [WordPress Trac] #44638: Bug in do_action

WordPress Trac noreply at wordpress.org
Wed Jul 25 06:32:09 UTC 2018


#44638: Bug in do_action
--------------------------+-----------------------------
 Reporter:  Track77       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.9.7
 Severity:  major         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 {{{#!php
 <?php
 $user_id = 1928;

 class test_object {

         public $ID;

         public $plugin_id;

         public function __construct ( $_id, $_plugin_id ) {
                 $this->ID = $_id;
                 $this->plugin_id = $_plugin_id;
         }
 }

 $_object = new test_object( 53, 1 );

 $_products = array( 0 => $_object );

 $order = wc_get_order( 8619 );
 echo  print_r( $_products, true );

 add_action( '_add_items_to_order', 'fn_add_items_to_order' , 10, 3);

 function fn_add_items_to_order( $_products, $order, $user_id ) {
          echo print_r( $_products, true );
 }
 echo  '<br>do_action' . '<br>' ;
 do_action( '_add_items_to_order', $_products, $order, $user_id );

 echo  '<br> <br>apply_filters<br>'  ;
 apply_filters( '_add_items_to_order', $_products, $order, $user_id );
 }}}

 Result:

 {{{#!php
 <?php

 Array
 (
     [0] => test_object Object
         (
             [ID] => 53
             [plugin_id] => 1
         )

 )

 do_action:
 test_object Object
 (
     [ID] => 53
     [plugin_id] => 1
 )


 apply_filters:
 Array
 (
     [0] => test_object Object
         (
             [ID] => 53
             [plugin_id] => 1
         )
 )
 }}}

 PS.
 do_action works correct if array contains more than 1 item.

 Regards, Oleksandr Kramer

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44638>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list