| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly |
| 5 |
} |
| 6 |
|
| 7 |
class PH_Text_Substitution { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
|
| 11 |
$current_settings = get_option( 'propertyhive_template_assistant', array() ); |
| 12 |
|
| 13 |
if ( isset($current_settings['text_translations']) && is_array($current_settings['text_translations']) && !empty($current_settings['text_translations']) ) |
| 14 |
{ |
| 15 |
add_filter( 'gettext', array( $this, 'do_text_translation'), 20, 3 ); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
public function do_text_translation( $translated_text, $text, $domain ) |
| 20 |
{ |
| 21 |
if ( $domain != 'propertyhive' ) |
| 22 |
{ |
| 23 |
return $translated_text; |
| 24 |
} |
| 25 |
|
| 26 |
$current_settings = get_option( 'propertyhive_template_assistant', array() ); |
| 27 |
|
| 28 |
if ( isset($current_settings['text_translations']) && is_array($current_settings['text_translations']) && !empty($current_settings['text_translations']) ) |
| 29 |
{ |
| 30 |
foreach ( $current_settings['text_translations'] as $text_translation ) |
| 31 |
{ |
| 32 |
if ( isset($text_translation['search']) && $text_translation['search'] == $translated_text ) |
| 33 |
{ |
| 34 |
$translated_text = $text_translation['replace']; |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
return $translated_text; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
new PH_Text_Substitution(); |