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_calc_setting', array( $this, 'replace' ) ); 
  16.  
  17. add_filter( 'ninja_forms_run_action_settings', array( $this, 'replace' ) ); 
  18. add_filter( 'ninja_forms_run_action_settings_preview', array( $this, 'replace' ) ); 
  19.  
  20. add_filter( 'ninja_forms_run_action_settings', array( $this, 'replace' ) ); 
  21. add_filter( 'ninja_forms_run_action_settings_preview', array( $this, 'replace' ) ); 
  22.  
  23. /** Manually trigger Merge Tag replacement */ 
  24. add_filter( 'ninja_forms_merge_tags', array( $this, 'replace' ) ); 
  25.  
  26. public function replace( $subject ) 
  27. if( is_array( $subject ) ) { 
  28. foreach( $subject as $i => $s ) { 
  29. $subject[ $i ] = $this->replace( $s ); 
  30. return $subject; 
  31.  
  32. preg_match_all("/{(.*?)}/", $subject, $matches ); 
  33.  
  34. if( empty( $matches[0] ) ) return $subject; 
  35.  
  36. foreach( $this->merge_tags as $merge_tag ) { 
  37. if( ! in_array( $merge_tag[ 'tag' ], $matches[0] ) ) continue; 
  38.  
  39. $replace = ( is_callable( array( $this, $merge_tag[ 'callback' ] ) ) ) ? $this->{$merge_tag[ 'callback' ]}() : ''; 
  40.  
  41. $subject = str_replace( $merge_tag[ 'tag' ], $replace, $subject ); 
  42.  
  43. return $subject; 
  44.  
  45. public function get_id() 
  46. return $this->id; 
  47.  
  48. public function get_title() 
  49. return $this->title; 
  50.  
  51. public function get_merge_tags() 
  52. return $this->merge_tags; 
  53.  
  54. public function is_default_group() 
  55. return $this->_default_group; 
  56.  
  57.  
  58. } // END CLASS NF_Abstracts_MergeTags