*/
/* Describe what the code snippet does so you can remember later on */
//Adding a jquery code to the footer. This code fetch the list ids based on the checked values in the checkbox
add_action('wp_footer', 'fetchedKeyVal');
function fetchedKeyVal(){
?>
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' );
$count_list_array = count($list_array);
$mp_segments = $this->mailpoet_segments_data( $list_array );
//Make ready all attributes
$atts = array(
'class' => $tag->get_class_option( $class ),
'id' => $id,
'name' => $tag->name . '[]',
);
if ( ! $tag->has_option( 'subscriber-choice' ) ) {
$atts['value'] = ( $list_array ) ? implode( $list_array, ',' ) : '0';
}
$attributes = wpcf7_format_atts( $atts );
$sagments = Segment::where_not_equal( 'type', Segment::TYPE_WP_USERS )->findArray();
ob_start(); //Start buffer to return
?>
1 && $tag->has_option( 'subscriber-choice' ) ): ?>
$value ): ?>
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 __
/**
* Convert mailpoet list ids to list name;
*/
public function mailpoet_segments_data( $list_ids ) {
if ( empty( $list_ids ) || ! is_array( $list_ids ) ) {
return [];
}
$segments = Segment::where_not_equal( 'type', Segment::TYPE_WP_USERS )->findArray();
$ret = array();
foreach ( $list_ids as $key => $value ) {
$seg_key = array_search( $value, array_column( $segments, 'id' ) );
$ret[ $value ] = $segments[ $seg_key ]['name'];
}
return $ret;
} // End of mailpoet_segments_data
/**
* 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() {
?>