NF_Abstracts_ActionNewsletter

Class NF_Abstracts_ActionNewsletter.

Defined (1)

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

/includes/Abstracts/ActionNewsletter.php  
  1. abstract class NF_Abstracts_ActionNewsletter extends NF_Abstracts_Action 
  2. /** 
  3. * @var array 
  4. */ 
  5. protected $_tags = array( 'newsletter' ); 
  6.  
  7. /** 
  8. * @var string 
  9. */ 
  10. protected $_timing = 'normal'; 
  11.  
  12. /** 
  13. * @var int 
  14. */ 
  15. protected $_priority = '10'; 
  16.  
  17. protected $_settings = array(); 
  18.  
  19. protected $_transient = ''; 
  20.  
  21. protected $_transient_expiration = ''; 
  22.  
  23. protected $_setting_labels = array( 
  24. 'list' => 'List',  
  25. 'fields' => 'List Field Mapping',  
  26. 'groups' => 'Interest Groups',  
  27. ); 
  28.  
  29. /** 
  30. * Constructor 
  31. */ 
  32. public function __construct() 
  33. parent::__construct(); 
  34.  
  35. if( ! $this->_transient ) { 
  36. $this->_transient = $this->get_name() . '_newsletter_lists'; 
  37.  
  38. add_action( 'wp_ajax_nf_' . $this->_name . '_get_lists', array( $this, '_get_lists' ) ); 
  39.  
  40. $this->get_list_settings(); 
  41.  
  42. /** 
  43. * PUBLIC METHODS 
  44. */ 
  45.  
  46. public function save( $action_settings ) 
  47.  
  48.  
  49. public function process( $action_settings, $form_id, $data ) 
  50.  
  51.  
  52. public function _get_lists() 
  53. check_ajax_referer( 'ninja_forms_builder_nonce', 'security' ); 
  54.  
  55. $lists = $this->get_lists(); 
  56.  
  57. array_unshift( $lists, array( 'value' => 0, 'label' => '-', 'fields' => array(), 'groups' => array() ) ); 
  58.  
  59. $this->cache_lists( $lists ); 
  60.  
  61. echo wp_json_encode( array( 'lists' => $lists ) ); 
  62.  
  63. wp_die(); // this is required to terminate immediately and return a proper response 
  64.  
  65. /** 
  66. * PROTECTED METHODS 
  67. */ 
  68.  
  69. abstract protected function get_lists(); 
  70.  
  71. /** 
  72. * PRIVATE METHODS 
  73. */ 
  74.  
  75. private function get_list_settings() 
  76. $label_defaults = array( 
  77. 'list' => 'List',  
  78. 'fields' => 'List Field Mapping',  
  79. 'groups' => 'Interest Groups',  
  80. ); 
  81. $labels = array_merge( $label_defaults, $this->_setting_labels ); 
  82.  
  83. $prefix = $this->get_name(); 
  84.  
  85. $lists = get_transient( $this->_transient ); 
  86.  
  87. if( ! $lists ) { 
  88. $lists = $this->get_lists(); 
  89. $this->cache_lists( $lists ); 
  90.  
  91. if( empty( $lists ) ) return; 
  92.  
  93. $this->_settings[ $prefix . 'newsletter_list' ] = array( 
  94. 'name' => 'newsletter_list',  
  95. 'type' => 'select',  
  96. 'label' => $labels[ 'list' ] . ' <a class="js-newsletter-list-update extra"><span class="dashicons dashicons-update"></span></a>',  
  97. 'width' => 'full',  
  98. 'group' => 'primary',  
  99. 'value' => '0',  
  100. 'options' => array(),  
  101. ); 
  102.  
  103. $fields = array(); 
  104. foreach( $lists as $list ) { 
  105. $this->_settings[ $prefix . 'newsletter_list' ][ 'options' ][] = $list; 
  106.  
  107. //Check to see if list has fields array set. 
  108. if ( isset( $list[ 'fields' ] ) ) { 
  109.  
  110. foreach ( $list[ 'fields' ] as $field ) { 
  111. $name = $list[ 'value' ] . '_' . $field[ 'value' ]; 
  112. $fields[] = array( 
  113. 'name' => $name,  
  114. 'type' => 'textbox',  
  115. 'label' => $field[ 'label' ],  
  116. 'width' => 'full',  
  117. 'use_merge_tags' => array( 
  118. 'exclude' => array( 
  119. 'user', 'post', 'system', 'querystrings' 
  120. ); 
  121.  
  122. $this->_settings[ $prefix . 'newsletter_list_fields' ] = array( 
  123. 'name' => 'newsletter_list_fields',  
  124. 'label' => __( 'List Field Mapping', 'ninja-forms' ),  
  125. 'type' => 'fieldset',  
  126. 'group' => 'primary',  
  127. 'settings' => array() 
  128. ); 
  129.  
  130. $this->_settings[ $prefix . 'newsletter_list_groups' ] = array( 
  131. 'name' => 'newsletter_list_groups',  
  132. 'label' => __( 'Interest Groups', 'ninja-forms' ),  
  133. 'type' => 'fieldset',  
  134. 'group' => 'primary',  
  135. 'settings' => array() 
  136. ); 
  137.  
  138. private function cache_lists( $lists ) 
  139. set_transient( $this->_transient, $lists, $this->_transient_expiration );