MailPoet'; printf( __('%s plugin requires %s plugin, Please activate %s first to using %s.', 'add-on-gravity-forms-mailpoet'), $name, $mp_link, $mp_link, $name ); ?>
$notice
"; } delete_option('gf_new_mailpoet_plugin_deferred_admin_notices'); } } register_deactivation_hook(__FILE__, 'gf_new_mailpoet_plugin_deactivation'); function gf_new_mailpoet_plugin_deactivation() { delete_option('gf_new_mailpoet_plugin_deferred_admin_notices'); } /** * Mailpoet class load */ use MailPoet\Models\Subscriber; use MailPoet\Models\Segment; /** * Add mailpoet list to choice. */ add_action('gform_predefined_choices','mailpoet_predefiend_list' ); function mailpoet_predefiend_list( $choices ) { $ret = array(); $segments = Segment::where_not_equal('type', Segment::TYPE_WP_USERS)->findArray(); foreach ($segments as $s_key => $s_val) { $ret['Mailpoet List'][] = $s_val['name'].'|'.$s_val['id']; } foreach ($choices as $key => $value) { $ret[$key] = $value; } return $ret; } /** * Set default input */ add_action( 'gform_editor_js_set_default_values', 'mailpoet_list_set_default' ); function mailpoet_list_set_default() { $segments = Segment::where_not_equal('type', Segment::TYPE_WP_USERS)->findArray(); $choice = '['; foreach ($segments as $key => $value) { $choice .= 'new Choice("'.$value["name"].'","'.$value["id"].'"), '; } $choice .= '];'; if ( empty($segments) ){ $choice = "[new Choice('List one'), new Choice('List two'), new Choice('Please set a list')];"; } ?> case "mailpoet": field.label = "Subscribe"; field.choices = = $choice; ?> break; id; $email = rgar( $entry, $email_id ); if ( empty($email) ){ return; } $subscriber = Subscriber::findOne( $email ); if ( false !== $subscriber ){ $segments = $subscriber->segments()->findArray(); if ( !empty($segments) ){ return; } } $subscriber_data = array( 'email' => $email ); // extract name $name_key = array_search('name', array_column($form['fields'], 'type')); if ( false === $name_key ){ $name_key = array_search('name', array_column(array_map('get_object_vars', $form['fields']), 'type')); } if ( is_integer( $name_key ) ){ $fname_id = array_search('First', array_column($form['fields'][$name_key]->inputs, 'label')); $fname_id = $form['fields'][$name_key]->inputs[$fname_id]['id']; $lname_id = array_search('Last', array_column($form['fields'][$name_key]->inputs, 'label')); $lname_id = $form['fields'][$name_key]->inputs[$lname_id]['id']; $first_name = rgar( $entry, $fname_id ); $last_name = rgar( $entry, $lname_id ); $subscriber_data['first_name'] = $first_name; $subscriber_data['last_name'] = $last_name; } // extract mailpoet list ids $mp_key = array_search('mailpoet', array_column($form['fields'], 'type')); if ( false === $mp_key ){ $mp_key = array_search('mailpoet', array_column(array_map('get_object_vars', $form['fields']), 'type')); } if ( !is_integer( $mp_key) ){ return; } $mp_id = (array) $form['fields'][$mp_key]; $mp_id = array_column($mp_id['inputs'], 'id'); $mp_list = []; foreach ($mp_id as $key => $value) { $lst = rgar( $entry, $value ); if ( !empty($lst) ){ if ( is_integer($lst) || is_numeric($lst) ){ $mp_list[] = $lst; } else { $list = Segment::where('name', $lst)->findArray(); if ( !empty($list) ){ $list = array_shift($list); $mp_list[] = isset($list['id']) ? $list['id'] : null; } } } } // subscribe to if ( !empty($mp_list) ){ Subscriber::subscribe( $subscriber_data , $mp_list ); } }