]+' . '[.]' # conditionally match everything except for special characters after . . '(?:' . '\([\w\d]+\)|' . '(?:' . '[^`!()\[\]{};:\'".,<>«»“”‘’\s]|' . '(?:[:]\d+)?/?' . ')+' . ')' . ')\\1#'; preg_match_all($regex, $text, $links); $shortcodes = new Shortcodes();; $shortcodes = $shortcodes->extract($text, $limit = array('subscription')); return array_merge( array_unique($links[2]), $shortcodes ); } static function replace($text, $links = false) { $links = ($links) ? $links : self::extract($text); $processed_links = array(); foreach($links as $link) { $hash = Security::generateRandomString(5); $processed_links[] = array( 'hash' => $hash, 'url' => $link ); $encoded_link = sprintf( '%s/?mailpoet&endpoint=track&action=click&data=%s', home_url(), '[mailpoet_data]-'.$hash ); $link_regex = '/' . preg_quote($link, '/') . '/'; $text = preg_replace($link_regex, $encoded_link, $text); } return array($text, $processed_links); } }