FieldOptIn.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Class NF_Abstracts_FieldOptIn
  4. *
  5. * Opt-In fields should extend this class.
  6. *
  7. * Supports:
  8. * - Checkbox value processing
  9. *
  10. * Planned Support:
  11. * - Single / Multiple Type Opt-In
  12. */
  13. abstract class NF_Abstracts_FieldOptIn extends NF_Abstracts_Input
  14. {
  15. protected $_name = 'optin';
  16. protected $_section = 'misc';
  17. protected $_parent_type = 'checkbox';
  18. protected $_templates = 'optin';
  19. protected $_settings = array( 'type', 'fieldset', 'checkbox_default_value' );
  20. protected $_settings_exclude = array( 'default', 'required', 'placeholder', 'input_limit_set', 'disable_input' );
  21. protected $_lists = array();
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. /*
  26. * Setup 'type' options for the opt-in field.
  27. */
  28. $this->_settings[ 'type' ][ 'options' ] = array(
  29. array(
  30. 'label' => __( 'Single', 'ninja-forms' ),
  31. 'value' => 'single',
  32. ),
  33. array(
  34. 'label' => __( 'Multiple', 'ninja-forms' ),
  35. 'value' => 'multiple',
  36. ),
  37. );
  38. /*
  39. * Add a refresh extra for the groups fieldset.
  40. */
  41. $this->_settings[ 'fieldset' ][ 'label' ] = __( 'Lists', 'ninja-forms' ) . ' <a href="#"><small>' . __( 'refresh', 'ninja-forms' ) . '</small></a>';
  42. $this->_settings[ 'fieldset' ][ 'deps' ] = array( 'type' => 'multiple' );
  43. /*
  44. * Hide the 'type' and 'fieldset' ('groups') settings until they are ready for use.
  45. */
  46. $this->_settings[ 'type' ][ 'group' ] = '';
  47. $this->_settings[ 'fieldset' ][ 'group' ] = '';
  48. }
  49. protected function addList( $name, $label )
  50. {
  51. $this->_settings[ 'fieldset' ][ 'settings' ][] = array(
  52. 'name' => $name,
  53. 'type' => 'toggle',
  54. 'label' => $label,
  55. 'width' => 'full',
  56. 'value' => ''
  57. );
  58. }
  59. protected function addLists( array $lists = array() )
  60. {
  61. if( empty( $lists ) ) return;
  62. foreach( $lists as $name => $label ){
  63. $this->addList( $name, $label );
  64. }
  65. }
  66. public function get_parent_type(){
  67. return $this->_parent_type;
  68. }
  69. }