We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plug-In to call an extension function?

Development and Programming

wineknow's avatar
wineknow
15 posts
17 years ago
wineknow's avatar wineknow

From within a plug-in, is there anyway I can get a valid instantiated extension class handle? Long story short, I want to add a plugin to my CoolLocation geocode extension that will stuff everything into a SAEF form. All the settings etc and all in the extension and settings, So I just would like to call a function of my class to return the proper JS code.

alternatively, how do I instantiate an extension and have it get is current settings? -kevin

       
Brian M.'s avatar
Brian M.
529 posts
17 years ago
Brian M.'s avatar Brian M.

I’m not sure if this is the ‘correct’ way to do it - I’d love to hear other people’s thoughts. But I did just this recently with a plug-in that needed the settings of an extension.

What I did was make a function within the extension that simply returned the settings like so:

function reason () {
if($this->settings) {
                return $this->settings['closing'];
            } else {
                return false;
            }
}

In the activate_extension function of that extension I gave it a hook that I made up for the purpose - like so:

function activate_extension () {
        global $DB;
        
        $DB->query($DB->insert_string('exp_extensions', array('extension_id' => '',
                                                              'class'        => get_class($this),
                                                              'method'       => 'reason',
                                                              'hook'         => 'bfpl_closing_hook',
                                                              'settings'     => '',
                                                              'priority'     => 5,
                                                              'version'      => $this->version,
                                                              'enabled'      => 'y')));
    }

Then within the plug-in, I called that extension hook:

function closing()
    {
            global $TMPL, $EXT;
            $reason = $EXT->call_extension('bfpl_closing_hook');
            
            if($reason) {
                 $this->return_data = '' . $reason . '';
            } else {
                $this->return_data = $TMPL->tagdata;
            }
    }

Like I said I have no clue if this is the correct way of doing things, but it works… I’d love to hear if this is the right way of doing things or if there is a better way.

       
wineknow's avatar
wineknow
15 posts
17 years ago
wineknow's avatar wineknow

I just had completed the following before I received your post. Again, I have no idea if it is “proper” but it works in 1.6.1 for me. All this code can be anywhere within the plug-in.

global $TMPL, $FNS, $EXT, $REGX;
        
$class = 'CoolLocation_extension';
 $ext_hook = 'publish_form_new_tabs';
        
$path = PATH_EXT.'ext.'.$FNS->filename_security(strtolower($class)).EXT;

$settings_list = $EXT->extensions[$ext_hook];
 foreach ($settings_list as $setting_group) {
        
     if (isset($setting_group[$class])) {
         $seralized_settings = $setting_group[$class][1];
          break;
      }
}        

$settings = $REGX->array_stripslashes(unserialize($seralized_settings));
        
if (!class_exists($class)) {
            require $path;
 }
        
$myext = new $class($settings);
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.