NF_MergeTags_Calcs

Class NF_MergeTags_Calcs.

Defined (1)

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

/includes/MergeTags/Calcs.php  
  1. final class NF_MergeTags_Calcs extends NF_Abstracts_MergeTags 
  2. protected $id = 'calcs'; 
  3.  
  4. protected $_default_group = FALSE; 
  5.  
  6. public function __construct() 
  7. parent::__construct(); 
  8. $this->title = __( 'Calculations', 'ninja-forms' ); 
  9. add_filter( 'ninja_forms_calc_setting', array( $this, 'replace' ) ); 
  10.  
  11. public function __call($name, $arguments) 
  12. return $this->merge_tags[ $name ][ 'calc_value' ]; 
  13.  
  14. public function set_merge_tags( $key, $value, $round = 2 ) 
  15. global $wp_locale; 
  16. $dec = $wp_locale->number_format['decimal_point']; 
  17. $sep = $wp_locale->number_format['thousands_sep']; 
  18. $callback = ( is_numeric( $key ) ) ? 'calc_' . $key : $key; 
  19.  
  20. try { 
  21. $value = str_replace($sep, '', $value); 
  22. $value = str_replace($dec, '.', $value); 
  23. $calculated_value = Ninja_Forms()->eos()->solve( $value ); 
  24. } catch( Exception $e ) { 
  25. $calculated_value = FALSE; 
  26.  
  27. $this->merge_tags[ $callback ] = array( 
  28. 'id' => $key,  
  29. 'tag' => "{calc:$key}",  
  30. // 'label' => __( '', 'ninja_forms' ),  
  31. 'callback' => $callback,  
  32. 'calc_value' => number_format( $calculated_value, $round, $dec, $sep ) 
  33. ); 
  34.  
  35. $callback .= '2'; 
  36.  
  37. $this->merge_tags[ $callback ] = array( 
  38. 'id' => $key,  
  39. 'tag' => "{calc:$key:2}",  
  40. // 'label' => __( '', 'ninja_forms' ),  
  41. 'callback' => $callback,  
  42. 'calc_value' => number_format( $calculated_value, 2, $dec, $sep ) 
  43. ); 
  44.  
  45. public function get_calc_value( $key ) 
  46. return $this->merge_tags[ $key ][ 'calc_value' ]; 
  47.  
  48. } // END CLASS NF_MergeTags_Calcs