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);
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   ###
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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