*/ use MailPoet\Models\Segment; if(!class_exists('MailPoet_CF7_Integration')){ class MailPoet_CF7_Integration { /** * Initialize the class */ public static function init() { $_this_class = new self; return $_this_class; } /** * Constructor */ public function __construct() { // CF7 init add_action('wpcf7_init', array($this, 'cf7_init')); // Admin init add_action('admin_init', array($this, 'admin_init'), 20); // Form validation add_filter( 'wpcf7_validate_mailpoetsignup', array($this, 'mailpoetsignup_validation'), 10, 2 ); add_filter( 'wpcf7_validate_mailpoetsignup*', array($this, 'mailpoetsignup_validation'), 10, 2 ); }//End of __construct /** * Contact Form 7 init */ public function cf7_init() { //Add Mailpoet Signup tag wpcf7_add_form_tag( array('mailpoetsignup', 'mailpoetsignup*'), array($this, 'mailpoet_signup_form_tag'), array('name-attr' => true) ); }//End of cf7_init /** * HTML Output of Subscribe checkbox */ public function mailpoet_signup_form_tag($tag) { // Non AJAX Validation error $validation_error = wpcf7_get_validation_error($tag->name); $class = ''; //Form control span class $controls_class = wpcf7_form_controls_class($tag->type); // if there were errors, add class if( $validation_error ) $class .= ' wpcf7-not-valid'; //Checkbox Label $label = empty($tag->values) ? $this->__('Sign up for the newsletter') : array_shift($tag->values); //id attribute $id_option = $tag->get_id_option(); $id = empty($id_option) ? $tag->name : $id_option; //Array of list id $list_array = $tag->get_option('list', 'int'); //Make ready all attributes $atts = array( 'class' => $tag->get_class_option($class), 'id' => $id, 'name' => $tag->name, 'value' => ($list_array) ? implode($list_array, ',') : '0' ); $attributes = wpcf7_format_atts($atts); ob_start(); //Start buffer to return // should the label be inside the span? if($tag->has_option('label-inside-span')): //If Label Inside Span checked ?> has_option('default:on'), true); ?> /> has_option('default:on'), true); ?> /> has_option('label-inside-span') //Return all HTML output return ob_get_clean(); }//End of mailpoet_signup_form_tag /** * Translate text */ public function __($text) { return __($text, 'add-on-contact-form-7-mailpoet'); }//End of __ /** * Admin init */ public function admin_init() { //Add Tag generator button if(!class_exists('WPCF7_TagGenerator')) return; $tag_generator = WPCF7_TagGenerator::get_instance(); $tag_generator->add( 'mailpoetsignup', $this->__('Mailpoet Signup'), array($this, 'mailpoetsignup_tag_generator') ); }//End of admin_init /** * Tag Generator */ public function mailpoetsignup_tag_generator() { ?>
__('Mailpoet Signup Form.'); ?>
__('MailPoet Lists'); ?> findArray(); if(is_array($sagments)): foreach($sagments as $sagment): ?>

type; $name = $tag->name; $value = isset( $_POST[$name] ) ? (array) $_POST[$name] : array(); if ( $tag->is_required() && empty( $value ) ) { $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); } return $result; }//End of mailpoetsignup_validation }//End of class /** * Instentiate core class */ MailPoet_CF7_Integration::init(); }//End if