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

Accessing one plugin's methods from within another plugin

Development and Programming

RobJ25's avatar
RobJ25
39 posts
17 years ago
RobJ25's avatar RobJ25

Hi all,

Is it possible to access one plugin from within another? I don’t mean by nesting plugins within a template, but instead doing the work within the plugin code itself. It seems like the parse_type method of the typography class might do the job.

On a separate note, does anyone have any good advice on when a development situation calls for a module vs a plugin? It seems like this would be a good addition to the documentation.

Many thanks, as ever, Rob

       
BlackHelix's avatar
BlackHelix
226 posts
17 years ago
BlackHelix's avatar BlackHelix

You should be able to use one plugin inside another–depending on many things, of course. One, whether that plugin requires use of the TMPL or Template class. If so, you are likely out of luck–while you can access it, the other plugin will break.

But yes, since a plugin is a class, just test for like the Typography class. Assign a variable to represent the plugin, and then create the plugin class… and access it just like any other php class would, outside of EE.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

RobJ25,

Definately possible. Though how useful it will be to you depends greatly on how the plugin’s functions are written. If the plugin functionality is abstracted from the main function that interfaces wtih the TMPL class then it will work out fairly well. If not then it may not be of much use to you.

I outlined how you would call a Plugin class within a function in another thread

If you have any questions or need details feel free to ask.

Jamie

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

And to add to this. If you want the Typography class specifically you don’t need to call that from the Typography plugin. Call it straight from the source like the plugin itself does.

Jamie

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones
One, whether that plugin requires use of the TMPL or Template class. If so, you are likely out of luck–while you can access it, the other plugin will break

You’re going to need to elaborate on that Vanceone, as I’ve done that on a number of occasions.

       
BlackHelix's avatar
BlackHelix
226 posts
17 years ago
BlackHelix's avatar BlackHelix

Well, I’ll defer to you, of course, Derek. But my thinking was that if the plugin you are including is expecting to get data from the template class directly, and such data is not available, then it would return errors or nonsense.

Example: my custom member data plugin. It expects any number of parameters, which it gets from the TMPL class. I never provided a way to pass in parameters to the methods. So, to call my plugin directly from another plugin, module, etc just wouldn’t work, unless there is inside the TMPL class some parameters that can be passed to my plugin. I.e. I expect a “data” parameter–and if I don’t get one, my plugin just returns an empty string. I get my “data” parameter straight from the TMPL class. How would another module supply that parameter to my plugin?

Now, other plugins, etc. may not have that issue, and indeed, I can see a plugin that gets tag data from the TMPL class working anyway, as it just would get the same data as the calling class (I think), and go from there.

Or have I missed some fundamental concept? I think Jamie is talking about the same thing I am in this thread.

With my plugin, though, it wouldn’t be too hard to adjust so it would play nice with others.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Well your plugin methods can easily be modified to accept parameters. Just provide defaults when nothing is passed directly to the methods, which will be the case when it’s called from a tag.

function foo($bar = '', $bat = '')

But if you are referencing the global $TMPL object, it will not have changed from merely calling another class in another file.

pi.foo.php:

class Foo {
    
    function Foo()
    {
        if (! class_exists('Bar'))
        {
            require PATH_PI.'pi.bar'.EXT;
            
            $bar = new Bar;            
        }
    }
}

pi.bar.php:

class Bar {
    
    function Bar()
    {
        global $TMPL;
        
        print_r($TMPL);
    }
}

Tag in the template:

{exp:foo param_1="value_1" param_2="value_2"}
This is the tagdata.
{/exp:foo}
       

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.