5

In the documentation the code to add enable extension hooks is like this

$data = array(
    'class'     => __CLASS__,
    'method'    => 'truncate_this',
    'hook'      => 'typography_parse_type_end',
    'settings'  => serialize($this->settings),
    'priority'  => 10,
    'version'   => $this->version,
    'enabled'   => 'y'
);

ee()->db->insert('extensions', $data);

So to add multiple hooks to one extension, then should I just simply repeat that code as many times as I wish??

$data1 = array(
  ...
);

ee()->db->insert('extensions', $data1);

$data2 = array(
  ...
);

ee()->db->insert('extensions', $data2);

1 Answer 1

10

Yes. For example....

    $hooks = array(
        "template_fetch_template" => "template_fetch_template",
        "typography_parse_type_end" => "typography_parse_type_end"
    );

    foreach ($hooks as $hook => $method) {
        $data = array(
            'class' => __CLASS__,
            'method' => $method,
            'hook' => $hook,
            'settings' => "",
            'priority' => 10,
            'version' => $this->version,
            'enabled' => 'y'
        );
        $this->EE->db->insert($this->EE->db->dbprefix . 'extensions', $data);
    }//###   End of foreach   ###

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.