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\LogicExceptionthat 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.
The topic ‘Exception when multiple plugins use Twig’ is closed to new replies.