1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Docs] Testing for Active Plugins

Discussion in 'Developing Plugins' started by Nick, Mar 28, 2010.

  1. Nick

    Nick Well-Known Member

    Hotaru provides a built-in method for checking if another plugin is enabled. This is especially helpful if your own plugin depends on that plugin.

    PHP:
    $h->isActive('avatar'); // is the a plugin of type avatar enabled?

    $h->isActive('gravatar'); // is the Gravatar plugin enabled?
    At the top of every plugin is a comment block, and some plugins, such as Gravatar, include both a plugin folder and a plugin type, i.e.:

    PHP:
     nameGravatar
     
    descriptionEnables Gravatar avatars for users
     
    version0.8
     
    foldergravatar
     
    * class: Gravatar
     
    typeavatar
     
    requiresusers 1.1
    The isActive method in Hotaru.php takes a single parameter, e.g. "avatar" and returns true if there is a plugin with that type. If not, it then checks to see if there is a plugin with that folder name. If so, it returns true, otherwise false.

    This is useful when there are alternative plugins available. For example, different voting plugins are of the same type:

    PHP:
     nameVote
     
    descriptionAdds voting ability to posted stories.
     * 
    version1.5
     
    foldervote
     
    * class: Vote
     
    typevote
    PHP:
     nameUp Down Voting
     
    descriptionAdds voting ability to posted stories.
     * 
    version0.3
     
    folderupdown_voting
     
    * class: UpdownVoting
     
    typevote
    This way you can switch plugins without breaking anything that tests for a type "vote" plugin.
     

Share This Page