Need some help in PHP

by 3 replies
4
I am coding a wp plugin and when I am trying to use a library it is saying that some other plugin has declared that library and so I cannot redeclare that thing..

So i was jus wondering what needs to be done to overcome this problem....I can manage to play with this plugins but was just wondering how to approach this problem if I am gonna sell this plugin...I cannot ask my clients to uninstall some other plugin to get my plugin working so...

Any help would be really appreciated
#programming #php
  • I had this exact same problem when I started developing my auto-blogging plugin Roboblogger .

    Here's how I solved it:
    Code:
    if (!class_exists('Smarty')) //Template Engine
    {
      require_once(dirname(__FILE__) . '/vendor/plugins/Smarty-3.0.7/libs/Smarty.class.php');
    }
    The only thing I haven't figured out yet is how to make this work with specific versions (e.g. if another plugin uses Smarty 3.0.2 and I need at least Smarty 3.0.7). I haven't really had a need for this yet, so I'll guess I'll figure it out when I bump into this issue.
  • Banned
    Easiest way....Rename it
    Or you can rely on the class/functins already loaded and if it's a very common thing then that would be probibly best but if it's not it holds the risk that it's modified by the other developer and will not do what you expect it to do.

    I always have the names of my classes and functions started with the name of my plugin to make sure it won't clash with others and to overcome issues like these

    HtH
    Edwin
  • Renaming it could turn out to be a pain in the butt if there's a huge number of classes and/or functions. This is because the functions could use each other internally. If you rename it an it breaks, I would just use the class_exists() or function_exists() method.

Next Topics on Trending Feed

  • 4

    I am coding a wp plugin and when I am trying to use a library it is saying that some other plugin has declared that library and so I cannot redeclare that thing.. So i was jus wondering what needs to be done to overcome this problem....I can manage to play with this plugins but was just wondering how to approach this problem if I am gonna sell this plugin...I cannot ask my clients to uninstall some other plugin to get my plugin working so...