0

I want to override function get_post() in class EM_Tickets of plugin Event Manager

class EM_Tickets extends EM_Object implements Iterator{
/**
 * Retrieve multiple ticket info via POST
 * @return boolean
 */
function get_post(){
    // something here

    return apply_filters('em_tickets_get_post', count($this->errors) == 0, $this);
    }
}

so I create my own plugin and put below codes but no luck, don't know why it's not working although I read and follow some manuals likes Is it possible to replace a function within a PHP class?

class EM_Tickets_Child extends EM_Tickets implements Iterator{

    public function get_post(){
        file_put_contents('log.txt', 'in child class', FILE_APPEND | LOCK_EX);
        //something here
    }           
}
Community
  • 1
  • 1
Phong Vy
  • 369
  • 5
  • 19

1 Answers1

0

You have a filter (apply_filters) on the original code. You just need to hook and create a function to override the returns value, no needs to extends the plugin class, but it's another way to do.

add_action('em_ticket_get_posts', array('Em_tickets', 'my_new_get_post), 10, 2);
Benoti
  • 2,170
  • 2
  • 14
  • 15
  • I haven't tried your suggest but I resolved it by adding a function with hook "add_action('em_tickets_get_post_pre', 'save_em_ticket_item');" into file functions of themes – Phong Vy Oct 21 '16 at 09:35