NF_Abstracts_MergeTags

Class NF_Abstracts_MergeTags.

Defined (1)

The class is defined in the following location(s).

/includes/Abstracts/MergeTags.php  
  1. abstract class NF_Abstracts_MergeTags 
  2. protected $id = ''; 
  3.  
  4. protected $title = ''; 
  5.  
  6. protected $merge_tags = array(); 
  7.  
  8. protected $_default_group = TRUE; 
  9.  
  10. public function __construct() 
  11. add_filter( 'kbj_test', array( $this, 'replace' ) ); 
  12.  
  13. add_filter( 'ninja_forms_render_default_value', array( $this, 'replace' ) ); 
  14.  
  15. add_filter( 'ninja_forms_run_action_settings', array( $this, 'replace' ) ); 
  16. add_filter( 'ninja_forms_run_action_settings_preview', array( $this, 'replace' ) ); 
  17.  
  18. add_filter( 'ninja_forms_calc_setting', array( $this, 'replace' ) ); 
  19.  
  20. /** Manually trigger Merge Tag replacement */ 
  21. add_filter( 'ninja_forms_merge_tags', array( $this, 'replace' ) ); 
  22.  
  23. public function replace( $subject ) 
  24. if( is_array( $subject ) ) { 
  25. foreach( $subject as $i => $s ) { 
  26. $subject[ $i ] = $this->replace( $s ); 
  27. return $subject; 
  28.  
  29. preg_match_all("/{(.*?)}/", $subject, $matches ); 
  30.  
  31. if( empty( $matches[0] ) ) return $subject; 
  32.  
  33. foreach( $this->merge_tags as $merge_tag ) { 
  34. if( ! in_array( $merge_tag[ 'tag' ], $matches[0] ) ) continue; 
  35.  
  36. if( ! isset($merge_tag[ 'callback' ])) continue; 
  37.  
  38. $replace = ( is_callable( array( $this, $merge_tag[ 'callback' ] ) ) ) ? $this->{$merge_tag[ 'callback' ]}() : ''; 
  39.  
  40. $subject = str_replace( $merge_tag[ 'tag' ], $replace, $subject ); 
  41.  
  42. return $subject; 
  43.  
  44. public function get_id() 
  45. return $this->id; 
  46.  
  47. public function get_title() 
  48. return $this->title; 
  49.  
  50. public function get_merge_tags() 
  51. return $this->merge_tags; 
  52.  
  53. public function is_default_group() 
  54. return $this->_default_group; 
  55.  
  56.  
  57. } // END CLASS NF_Abstracts_MergeTags