| 1 |
<?php |
| 2 |
namespace EmailKit\Admin; |
| 3 |
|
| 4 |
defined("ABSPATH") || exit; |
| 5 |
|
| 6 |
class EmailKitHooks { |
| 7 |
|
| 8 |
|
| 9 |
public function __construct() |
| 10 |
{ |
| 11 |
|
| 12 |
add_filter('emailkit_shortcode_filter', [$this, 'replace'], 10, 2); |
| 13 |
} |
| 14 |
|
| 15 |
public function replace($input){ |
| 16 |
|
| 17 |
// Define the regular expression pattern |
| 18 |
$pattern = '/<span data-shortcode="{{([\w]+)}}">([\w]+)<\/span>/'; |
| 19 |
|
| 20 |
// Use preg_match_all to find all matches in the input |
| 21 |
preg_match_all($pattern, $input, $matches, PREG_SET_ORDER); |
| 22 |
|
| 23 |
// Loop through each match and replace the content inside the span tag |
| 24 |
foreach ($matches as $match) { |
| 25 |
$shortcode = $match[1]; // Content inside the data-shortcode attribute |
| 26 |
|
| 27 |
// Create the replacement string and replace the match in the input |
| 28 |
$replacement = '<span data-shortcode="{{' . $shortcode . '}}">{{' . strtolower($shortcode) . '}}</span>'; |
| 29 |
$input = str_replace($match[0], $replacement, $input); |
| 30 |
} |
| 31 |
|
| 32 |
return $input; |
| 33 |
} |
| 34 |
|
| 35 |
} |
| 36 |
|