diff --git a/lib/Util/Helpers.php b/lib/Util/Helpers.php index 16e0eaad7a..c9e6e64925 100644 --- a/lib/Util/Helpers.php +++ b/lib/Util/Helpers.php @@ -5,13 +5,14 @@ class Helpers { const DIVIDER = '***MailPoet***'; const LINK_TAG = 'link'; - static function replaceLinkTags($source, $link = false, $attributes = array()) { + static function replaceLinkTags($source, $link = false, $attributes = array(), $link_tag = false) { if(!$link) return $source; + $link_tag = ($link_tag) ? $link_tag : self::LINK_TAG; $attributes = array_map(function($key) use ($attributes) { return sprintf('%s="%s"', $key, $attributes[$key]); }, array_keys($attributes)); $source = str_replace( - '[' . self::LINK_TAG . ']', + '[' . $link_tag . ']', sprintf( '', join(' ', $attributes), @@ -19,7 +20,7 @@ class Helpers { ), $source ); - $source = str_replace('[/' . self::LINK_TAG . ']', '', $source); + $source = str_replace('[/' . $link_tag . ']', '', $source); return preg_replace('/\s+/', ' ', $source); } diff --git a/tests/unit/Util/HelpersTest.php b/tests/unit/Util/HelpersTest.php index 95df54d959..2fa5023f98 100644 --- a/tests/unit/Util/HelpersTest.php +++ b/tests/unit/Util/HelpersTest.php @@ -20,4 +20,11 @@ class HelpersTest extends MailPoetTest { expect(Helpers::replaceLinkTags($source, $link, $attributes)) ->equals('example link'); } + + function testItAcceptsCustomLinkTag() { + $source = '[custom_link_tag]example link[/custom_link_tag]'; + $link = 'http://example.com'; + expect(Helpers::replaceLinkTags($source, $link, array(), 'custom_link_tag')) + ->equals('example link'); + } } \ No newline at end of file