Title: Exception when multiple plugins use Twig
Last modified: November 12, 2018

---

# Exception when multiple plugins use Twig

 *  Resolved [iisisrael](https://wordpress.org/support/users/iisisrael/)
 * (@iisisrael)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/exception-when-multiple-plugins-use-twig/)
 * When other plugins autoload Twig, it causes `SocialSharing_Core_Module::registerTwigFunctions()`
   to be hit in a recursive fashion. Wrapping each of the calls to `$twig->addFunction()`
   in that method with a try / catch resolves the `\LogicException` that would otherwise
   result on the outer recursion.
 *     ```
       try {
           $twig->addFunction(
               new Twig_SimpleFunction(
                   'plugin_directory_url',
                   array($this, 'getPluginDirectoryUrl')
               )
           );
       }
       catch(\LogicException $e) {
           // Do nothing - function has already been added
       }
       ```
   
 * Rinse and repeat for “`get_posts`“, “`ucfirst`“, and “`wp_get_attachment_image_url`“.
 * Tangentially, your extension functions should really be namespaced, like “`ssbbs_plugin_directory_url`“,
   or you might bump heads with someone else who shares your preference for generic
   function names.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [iisisrael](https://wordpress.org/support/users/iisisrael/)
 * (@iisisrael)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/exception-when-multiple-plugins-use-twig/#post-10873558)
 * Actually, this is a result of the other plugin depending on a newer version of
   Twig (2.4.4), which has many classes extending base classes (after checking if
   the class has already been loaded), such as `Twig_SimpleFunction` extending `
   Twig_Function`. I disabled the other plugin, then copied the latest version of
   the Twig lib into this plugin, and the same exception was encountered.
 * Please play nicely with other plugins that use Twig and update!
 *  Plugin Author [supsystic](https://wordpress.org/support/users/supsysticcom/)
 * (@supsysticcom)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/exception-when-multiple-plugins-use-twig/#post-10874918)
 * Hello, [@iisisrael](https://wordpress.org/support/users/iisisrael/)
    Thank you
   for your feedback. It is extremely important for us that the plugins work correctly.
   We will definitely check this section of the code. Tell me which plugins you 
   checked our plugin for conflict?
 *  Thread Starter [iisisrael](https://wordpress.org/support/users/iisisrael/)
 * (@iisisrael)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/exception-when-multiple-plugins-use-twig/#post-10876336)
 * Hey [@supsysticcom](https://wordpress.org/support/users/supsysticcom/)! The other
   plugin is a proprietary one, so nothing in the WP repository. But like I said
   in my follow-up comment, if you update Twig, you’ll see the same exceptions without
   any other plugin installed. Once updated and working, it will not conflict with
   any other plugin using the latest Twig.
    -  This reply was modified 7 years, 6 months ago by [iisisrael](https://wordpress.org/support/users/iisisrael/).
 *  Plugin Author [supsystic](https://wordpress.org/support/users/supsysticcom/)
 * (@supsysticcom)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/exception-when-multiple-plugins-use-twig/#post-11015419)
 * Hello, [@iisisrael](https://wordpress.org/support/users/iisisrael/)
    We will 
   try to update the version of Twig, if at the time of development there are no
   critical conflicts.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Exception when multiple plugins use Twig’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/social-share-buttons-by-supsystic_dee2e2.
   svg)
 * [Social Share Buttons by Supsystic](https://wordpress.org/plugins/social-share-buttons-by-supsystic/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/social-share-buttons-by-supsystic/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/social-share-buttons-by-supsystic/)
 * [Active Topics](https://wordpress.org/support/plugin/social-share-buttons-by-supsystic/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/social-share-buttons-by-supsystic/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/social-share-buttons-by-supsystic/reviews/)

## Tags

 * [conflict](https://wordpress.org/support/topic-tag/conflict/)
 * [vendor](https://wordpress.org/support/topic-tag/vendor/)

 * 4 replies
 * 2 participants
 * Last reply from: [supsystic](https://wordpress.org/support/users/supsysticcom/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/exception-when-multiple-plugins-use-twig/#post-11015419)
 * Status: resolved