update
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
<p>
|
||||
<?php echo sprintf( __( 'To integrate with Ninja Forms, add the "Mailchimp" action to <a href="%s">one of your Ninja Forms forms</a>.', 'mailchimp-for-wp' ), admin_url( 'admin.php?page=ninja-forms' ) ); ?>
|
||||
<?php echo sprintf(__('To integrate with Ninja Forms, add the "Mailchimp" action to <a href="%s">one of your Ninja Forms forms</a>.', 'mailchimp-for-wp'), admin_url('admin.php?page=ninja-forms')); ?>
|
||||
</p>
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<?php
|
||||
|
||||
mc4wp_register_integration( 'ninja-forms', 'MC4WP_Ninja_Forms_Integration', true );
|
||||
mc4wp_register_integration('ninja-forms', 'MC4WP_Ninja_Forms_Integration', true);
|
||||
|
||||
if ( class_exists( 'Ninja_Forms' ) && method_exists( 'Ninja_Forms', 'instance' ) ) {
|
||||
$ninja_forms = Ninja_Forms::instance();
|
||||
add_filter('ninja_forms_register_fields', function ($fields) {
|
||||
if (class_exists(NF_Abstracts_Input::class)) {
|
||||
$fields['mc4wp_optin'] = new MC4WP_Ninja_Forms_Field();
|
||||
}
|
||||
return $fields;
|
||||
});
|
||||
|
||||
if ( isset( $ninja_forms->fields ) ) {
|
||||
$ninja_forms->fields['mc4wp_optin'] = new MC4WP_Ninja_Forms_Field();
|
||||
}
|
||||
|
||||
if ( isset( $ninja_forms->actions ) ) {
|
||||
$ninja_forms->actions['mc4wp_subscribe'] = new MC4WP_Ninja_Forms_Action();
|
||||
}
|
||||
}
|
||||
add_filter('ninja_forms_register_actions', function ($actions) {
|
||||
if (class_exists(NF_Abstracts_Action::class)) {
|
||||
$actions['mc4wp_subscribe'] = new MC4WP_Ninja_Forms_Action();
|
||||
}
|
||||
return $actions;
|
||||
});
|
||||
|
||||
@@ -1,149 +1,211 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MC4WP_Ninja_Forms_Action
|
||||
*/
|
||||
final class MC4WP_Ninja_Forms_Action extends NF_Abstracts_ActionNewsletter {
|
||||
class MC4WP_Ninja_Forms_Action extends NF_Abstracts_Action
|
||||
{
|
||||
protected $_name = 'mc4wp_subscribe';
|
||||
protected $_nicename = 'Mailchimp';
|
||||
protected $_tags = [ 'newsletter' ];
|
||||
protected $_timing = 'normal';
|
||||
protected $_priority = '10';
|
||||
protected $_settings = [];
|
||||
protected $_setting_labels = [
|
||||
'list' => 'List',
|
||||
'fields' => 'List Field Mapping',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = 'mc4wp_subscribe';
|
||||
public function __construct()
|
||||
{
|
||||
$this->_settings['double_optin'] = [
|
||||
'name' => 'double_optin',
|
||||
'type' => 'select',
|
||||
'label' => 'Use double opt-in?',
|
||||
'width' => 'full',
|
||||
'group' => 'primary',
|
||||
'value' => 1,
|
||||
'options' => [
|
||||
[
|
||||
'value' => 1,
|
||||
'label' => 'Yes',
|
||||
],
|
||||
[
|
||||
'value' => 0,
|
||||
'label' => 'No',
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->_settings['update_existing'] = [
|
||||
'name' => 'update_existing',
|
||||
'type' => 'select',
|
||||
'label' => 'Update existing subscribers?',
|
||||
'width' => 'full',
|
||||
'group' => 'primary',
|
||||
'value' => 0,
|
||||
'options' => [
|
||||
[
|
||||
'value' => 1,
|
||||
'label' => 'Yes',
|
||||
],
|
||||
[
|
||||
'value' => 0,
|
||||
'label' => 'No',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
add_action('wp_ajax_nf_' . $this->_name . '_get_lists', [$this, '_get_lists']);
|
||||
add_action('init', [$this, 'translate_props']);
|
||||
add_action('init', [$this, 'get_list_settings']);
|
||||
}
|
||||
|
||||
$this->_nicename = __( 'Mailchimp', 'mailchimp-for-wp' );
|
||||
$prefix = $this->get_name();
|
||||
public function translate_props()
|
||||
{
|
||||
$this->_settings['double_optin']['label'] = __('Use double opt-in?', 'mailchimp-for-wp');
|
||||
$this->_settings['update_existing']['label'] = __('Update existing subscribers?', 'mailchimp-for-wp');
|
||||
|
||||
unset( $this->_settings[ $prefix . 'newsletter_list_groups' ] );
|
||||
if (isset($this->_settings[ $this->get_name() . 'newsletter_list_fields' ])) {
|
||||
$this->_settings[ $this->get_name() . 'newsletter_list_fields' ]['label'] = __('List Field Mapping', 'mailchimp-for-wp');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_settings['double_optin'] = array(
|
||||
'name' => 'double_optin',
|
||||
'type' => 'select',
|
||||
'label' => __( 'Use double opt-in?', 'mailchimp-for-wp' ),
|
||||
'width' => 'full',
|
||||
'group' => 'primary',
|
||||
'value' => 1,
|
||||
'options' => array(
|
||||
array(
|
||||
'value' => 1,
|
||||
'label' => 'Yes',
|
||||
),
|
||||
array(
|
||||
'value' => 0,
|
||||
'label' => 'No',
|
||||
),
|
||||
),
|
||||
);
|
||||
/*
|
||||
* PUBLIC METHODS
|
||||
*/
|
||||
|
||||
$this->_settings['update_existing'] = array(
|
||||
'name' => 'update_existing',
|
||||
'type' => 'select',
|
||||
'label' => __( 'Update existing subscribers?', 'mailchimp-for-wp' ),
|
||||
'width' => 'full',
|
||||
'group' => 'primary',
|
||||
'value' => 0,
|
||||
'options' => array(
|
||||
array(
|
||||
'value' => 1,
|
||||
'label' => 'Yes',
|
||||
),
|
||||
array(
|
||||
'value' => 0,
|
||||
'label' => 'No',
|
||||
),
|
||||
),
|
||||
);
|
||||
public function save($action_settings)
|
||||
{
|
||||
}
|
||||
|
||||
// $this->_settings[ 'replace_interests' ] = array(
|
||||
// 'name' => 'replace_interests',
|
||||
// 'type' => 'select',
|
||||
// 'label' => __( 'Replace existing interest groups?', 'mailchimp-for-wp'),
|
||||
// 'width' => 'full',
|
||||
// 'group' => 'primary',
|
||||
// 'value' => 0,
|
||||
// 'options' => array(
|
||||
// array(
|
||||
// 'value' => 1,
|
||||
// 'label' => 'Yes',
|
||||
// ),
|
||||
// array(
|
||||
// 'value' => 0,
|
||||
// 'label' => 'No',
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
}
|
||||
public function process($action_settings, $form_id, $data)
|
||||
{
|
||||
if (empty($action_settings['newsletter_list']) || empty($action_settings['EMAIL'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* PUBLIC METHODS
|
||||
*/
|
||||
// find "mc4wp_optin" type field, bail if not checked.
|
||||
foreach ($data['fields'] as $field_data) {
|
||||
if ($field_data['type'] === 'mc4wp_optin' && empty($field_data['value'])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function save( $action_settings ) {
|
||||
}
|
||||
$list_id = $action_settings['newsletter_list'];
|
||||
$email_address = $action_settings['EMAIL'];
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
|
||||
public function process( $action_settings, $form_id, $data ) {
|
||||
if ( empty( $action_settings['newsletter_list'] ) || empty( $action_settings['EMAIL'] ) ) {
|
||||
return;
|
||||
}
|
||||
$merge_fields = $mailchimp->get_list_merge_fields($list_id);
|
||||
foreach ($merge_fields as $merge_field) {
|
||||
if (! empty($action_settings[ $merge_field->tag ])) {
|
||||
$merge_fields[ $merge_field->tag ] = $action_settings[ $merge_field->tag ];
|
||||
}
|
||||
}
|
||||
|
||||
// find "mc4wp_optin" type field, bail if not checked.
|
||||
foreach ( $data['fields'] as $field_data ) {
|
||||
if ( $field_data['type'] === 'mc4wp_optin' && empty( $field_data['value'] ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$double_optin = (int) $action_settings['double_optin'] !== 0;
|
||||
$update_existing = (int) $action_settings['update_existing'] === 1;
|
||||
$replace_interests = isset($action_settings['replace_interests']) && (int) $action_settings['replace_interests'] === 1;
|
||||
|
||||
$list_id = $action_settings['newsletter_list'];
|
||||
$email_address = $action_settings['EMAIL'];
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
do_action('mc4wp_integration_ninja_forms_subscribe', $email_address, $merge_fields, $list_id, $double_optin, $update_existing, $replace_interests, $form_id);
|
||||
}
|
||||
|
||||
$merge_fields = $mailchimp->get_list_merge_fields( $list_id );
|
||||
foreach ( $merge_fields as $merge_field ) {
|
||||
if ( ! empty( $action_settings[ $merge_field->tag ] ) ) {
|
||||
$merge_fields[ $merge_field->tag ] = $action_settings[ $merge_field->tag ];
|
||||
}
|
||||
}
|
||||
public function ajax_get_lists_handler()
|
||||
{
|
||||
check_ajax_referer('ninja_forms_builder_nonce', 'security');
|
||||
$lists = $this->get_lists();
|
||||
array_unshift($return, [ 'value' => 0, 'label' => '-', 'fields' => [], 'groups' => [] ]);
|
||||
echo wp_json_encode([ 'lists' => $return ]);
|
||||
wp_die();
|
||||
}
|
||||
|
||||
$double_optin = (int) $action_settings['double_optin'] !== 0;
|
||||
$update_existing = (int) $action_settings['update_existing'] === 1;
|
||||
$replace_interests = isset( $action_settings['replace_interests'] ) && (int) $action_settings['replace_interests'] === 1;
|
||||
private function get_lists()
|
||||
{
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
|
||||
do_action( 'mc4wp_integration_ninja_forms_subscribe', $email_address, $merge_fields, $list_id, $double_optin, $update_existing, $replace_interests, $form_id );
|
||||
}
|
||||
/** @var array $lists */
|
||||
$lists = $mailchimp->get_lists();
|
||||
$return = [
|
||||
[
|
||||
'label' => '-',
|
||||
'value' => 0,
|
||||
'fields' => [],
|
||||
]
|
||||
];
|
||||
|
||||
protected function get_lists() {
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
foreach ($lists as $list) {
|
||||
$list_fields = [];
|
||||
|
||||
/** @var array $lists */
|
||||
$lists = $mailchimp->get_lists();
|
||||
$return = array();
|
||||
foreach ($mailchimp->get_list_merge_fields($list->id) as $merge_field) {
|
||||
$list_fields[] = [
|
||||
'value' => $merge_field->tag,
|
||||
'label' => $merge_field->name,
|
||||
];
|
||||
}
|
||||
|
||||
foreach ( $lists as $list ) {
|
||||
$list_fields = array();
|
||||
// TODO: Add support for groups once base class supports this.
|
||||
$return[] = [
|
||||
'value' => $list->id,
|
||||
'label' => $list->name,
|
||||
'fields' => $list_fields,
|
||||
];
|
||||
}
|
||||
|
||||
foreach ( $mailchimp->get_list_merge_fields( $list->id ) as $merge_field ) {
|
||||
$list_fields[] = array(
|
||||
'value' => $merge_field->tag,
|
||||
'label' => $merge_field->name,
|
||||
);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
// TODO: Add support for groups once base class supports this.
|
||||
public function get_list_settings()
|
||||
{
|
||||
$label_defaults = [
|
||||
'list' => 'List',
|
||||
'fields' => 'List Field Mapping',
|
||||
];
|
||||
$labels = array_merge($label_defaults, $this->_setting_labels);
|
||||
$prefix = $this->get_name();
|
||||
$lists = $this->get_lists();
|
||||
|
||||
$return[] = array(
|
||||
'value' => $list->id,
|
||||
'label' => $list->name,
|
||||
'fields' => $list_fields,
|
||||
);
|
||||
}
|
||||
$this->_settings[ $prefix . 'newsletter_list' ] = [
|
||||
'name' => 'newsletter_list',
|
||||
'type' => 'select',
|
||||
'label' => $labels[ 'list' ] . ' <a class="js-newsletter-list-update extra"><span class="dashicons dashicons-update"></span></a>',
|
||||
'width' => 'full',
|
||||
'group' => 'primary',
|
||||
'value' => '0',
|
||||
'options' => [],
|
||||
];
|
||||
|
||||
return $return;
|
||||
}
|
||||
if (empty($lists)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = [];
|
||||
foreach ($lists as $list) {
|
||||
$this->_settings[ $prefix . 'newsletter_list' ][ 'options' ][] = $list;
|
||||
|
||||
//Check to see if list has fields array set.
|
||||
if (isset($list[ 'fields' ])) {
|
||||
foreach ($list[ 'fields' ] as $field) {
|
||||
$name = $list[ 'value' ] . '_' . $field[ 'value' ];
|
||||
$fields[] = [
|
||||
'name' => $name,
|
||||
'type' => 'textbox',
|
||||
'label' => $field[ 'label' ],
|
||||
'width' => 'full',
|
||||
'use_merge_tags' => [
|
||||
'exclude' => [
|
||||
'user', 'post', 'system', 'querystrings',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_settings[ $prefix . 'newsletter_list_fields' ] = [
|
||||
'name' => 'newsletter_list_fields',
|
||||
'label' => 'List Field Mapping',
|
||||
'type' => 'fieldset',
|
||||
'group' => 'primary',
|
||||
'settings' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +1,120 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
<?php
|
||||
|
||||
if (! defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class MC4WP_Ninja_Forms_Field
|
||||
*/
|
||||
class MC4WP_Ninja_Forms_Field extends NF_Abstracts_Input {
|
||||
class MC4WP_Ninja_Forms_Field extends NF_Abstracts_Input
|
||||
{
|
||||
protected $_name = 'mc4wp_optin';
|
||||
protected $_nicename = 'Mailchimp opt-in';
|
||||
protected $_section = 'misc';
|
||||
protected $_type = 'checkbox';
|
||||
protected $_icon = 'check-square-o';
|
||||
protected $_templates = 'checkbox';
|
||||
protected $_test_value = 0;
|
||||
protected $_settings = ['checkbox_default_value', 'checked_calc_value', 'unchecked_calc_value'];
|
||||
protected $_settings_exclude = ['default', 'placeholder', 'input_limit_set', 'checkbox_values'];
|
||||
|
||||
protected $_name = 'mc4wp_optin';
|
||||
/**
|
||||
* NF_Fields_Checkbox constructor.
|
||||
* @since 3.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
protected $_nicename = 'Mailchimp';
|
||||
$this->_settings['label_pos']['value'] = 'right';
|
||||
|
||||
protected $_section = 'misc';
|
||||
add_filter('ninja_forms_custom_columns', [$this, 'custom_columns'], 10, 2);
|
||||
add_action('init', [$this, 'translate_nicename']);
|
||||
}
|
||||
|
||||
protected $_type = 'checkbox';
|
||||
public function translate_nicename()
|
||||
{
|
||||
$this->_nicename = __('Mailchimp opt-in', 'mailchimp-for-wp');
|
||||
}
|
||||
|
||||
protected $_icon = 'check-square-o';
|
||||
/**
|
||||
* Admin Form Element
|
||||
* Display the checkbox on the edit submissions area.
|
||||
* @since 3.0
|
||||
*
|
||||
* @param $id Field ID.
|
||||
* @param $value Field value.
|
||||
* @return string HTML used for display of checkbox.
|
||||
*/
|
||||
public function admin_form_element($id, $value)
|
||||
{
|
||||
// If the checkboxes value is one...
|
||||
if (1 === (int) $value) {
|
||||
// ...this variable to checked.
|
||||
$checked = 'checked';
|
||||
} else {
|
||||
// ...else leave the variable empty.
|
||||
$checked = '';
|
||||
}
|
||||
|
||||
protected $_templates = 'checkbox';
|
||||
// Return HTML to be output to the submission edit page.
|
||||
return "<input type='hidden' name='fields[$id]' value='0' ><input type='checkbox' name='fields[$id]' value='1' id='' $checked>";
|
||||
}
|
||||
|
||||
protected $_test_value = 0;
|
||||
/**
|
||||
* Validate the field value.
|
||||
*
|
||||
* Overrides parent to handle checkbox-specific required validation,
|
||||
* since checkboxes submit '0' when unchecked which the parent considers valid.
|
||||
*
|
||||
* @since 4.9
|
||||
*
|
||||
* @param array $field The field data.
|
||||
* @param array $data The form data.
|
||||
* @return array Array of validation errors, empty if valid.
|
||||
*/
|
||||
public function validate($field, $data)
|
||||
{
|
||||
$errors = parent::validate($field, $data);
|
||||
|
||||
protected $_settings = array( 'checkbox_default_value', 'checked_calc_value', 'unchecked_calc_value' );
|
||||
if (isset($field['required']) && 1 == intval($field['required']) && empty($field['value'])) {
|
||||
$errors['slug'] = 'required-error';
|
||||
$errors['message'] = esc_html__('This field is required.', 'mailchimp-for-wp');
|
||||
}
|
||||
|
||||
protected $_settings_exclude = array( 'default', 'placeholder', 'input_limit_set', 'checkbox_values' );
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* NF_Fields_Checkbox constructor.
|
||||
* @since 3.0
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
/**
|
||||
* Custom Columns
|
||||
* Creates what is displayed in the columns on the submissions page.
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $value checkbox value
|
||||
* @param MC4WP_Ninja_Forms_Field $field field model.
|
||||
* @return $value string|void
|
||||
*/
|
||||
public function custom_columns($value, $field)
|
||||
{
|
||||
// If the field type is equal to checkbox...
|
||||
if ('mc4wp_optin' === $field->get_setting('type')) {
|
||||
// Backwards compatibility check for the new checked value setting.
|
||||
if (null === $field->get_setting('checked_value') && 1 === (int) $value) {
|
||||
return __('Checked', 'ninja-forms');
|
||||
} elseif (null === $field->get_setting('unchecked_value') && 0 === (int) $value) {
|
||||
return __('Unchecked', 'ninja-forms');
|
||||
}
|
||||
|
||||
$this->_nicename = __( 'Mailchimp opt-in', 'mailchimp-for-wp' );
|
||||
|
||||
$this->_settings['label_pos']['value'] = 'right';
|
||||
|
||||
add_filter( 'ninja_forms_custom_columns', array( $this, 'custom_columns' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Form Element
|
||||
* Display the checkbox on the edit submissions area.
|
||||
* @since 3.0
|
||||
*
|
||||
* @param $id Field ID.
|
||||
* @param $value Field value.
|
||||
* @return string HTML used for display of checkbox.
|
||||
*/
|
||||
public function admin_form_element( $id, $value ) {
|
||||
// If the checkboxes value is one...
|
||||
if ( 1 === (int) $value ) {
|
||||
// ...this variable to checked.
|
||||
$checked = 'checked';
|
||||
} else {
|
||||
// ...else leave the variable empty.
|
||||
$checked = '';
|
||||
}
|
||||
|
||||
// Return HTML to be output to the submission edit page.
|
||||
return "<input type='hidden' name='fields[$id]' value='0' ><input type='checkbox' name='fields[$id]' value='1' id='' $checked>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Columns
|
||||
* Creates what is displayed in the columns on the submissions page.
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $value checkbox value
|
||||
* @param MC4WP_Ninja_Forms_Field $field field model.
|
||||
* @return $value string|void
|
||||
*/
|
||||
public function custom_columns( $value, $field ) {
|
||||
// If the field type is equal to checkbox...
|
||||
if ( 'mc4wp_optin' === $field->get_setting( 'type' ) ) {
|
||||
// Backwards compatibility check for the new checked value setting.
|
||||
if ( null === $field->get_setting( 'checked_value' ) && 1 === (int) $value ) {
|
||||
return __( 'Checked', 'ninja-forms' );
|
||||
} elseif ( null === $field->get_setting( 'unchecked_value' ) && 0 === (int) $value ) {
|
||||
return __( 'Unchecked', 'ninja-forms' );
|
||||
}
|
||||
|
||||
// If the field value is set to 1....
|
||||
if ( 1 === (int) $value ) {
|
||||
// Set the value to the checked value setting.
|
||||
$value = $field->get_setting( 'checked_value' );
|
||||
} else {
|
||||
// Else set the value to the unchecked value setting.
|
||||
$value = $field->get_setting( 'unchecked_value' );
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
// If the field value is set to 1....
|
||||
if (1 === (int) $value) {
|
||||
// Set the value to the checked value setting.
|
||||
$value = $field->get_setting('checked_value');
|
||||
} else {
|
||||
// Else set the value to the unchecked value setting.
|
||||
$value = $field->get_setting('unchecked_value');
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +1,74 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
defined('ABSPATH') or exit;
|
||||
|
||||
/**
|
||||
* Class MC4WP_Ninja_Forms_Integration
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
class MC4WP_Ninja_Forms_Integration extends MC4WP_Integration {
|
||||
class MC4WP_Ninja_Forms_Integration extends MC4WP_Integration
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'Ninja Forms';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $description = 'Subscribe visitors from your Ninja Forms forms.';
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'Ninja Forms';
|
||||
/**
|
||||
* Add hooks
|
||||
*/
|
||||
public function add_hooks()
|
||||
{
|
||||
add_action('mc4wp_integration_ninja_forms_subscribe', [ $this, 'subscribe_from_ninja_forms' ], 10, 7);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $description = 'Subscribe visitors from your Ninja Forms forms.';
|
||||
public function subscribe_from_ninja_forms($email_address, $merge_fields, $list_id, $double_optin = true, $update_existing = false, $replace_interests = false, $form_id = 0)
|
||||
{
|
||||
// set options from parameters (coming from action)
|
||||
$orig_options = $this->options;
|
||||
$this->options['double_optin'] = $double_optin;
|
||||
$this->options['update_existing'] = $update_existing;
|
||||
$this->options['replace_interests'] = $replace_interests;
|
||||
$this->options['lists'] = [ $list_id ];
|
||||
|
||||
$data = $merge_fields;
|
||||
$data['EMAIL'] = $email_address;
|
||||
|
||||
/**
|
||||
* Add hooks
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_action( 'mc4wp_integration_ninja_forms_subscribe', array( $this, 'subscribe_from_ninja_forms' ), 10, 7 );
|
||||
}
|
||||
$this->subscribe($data, $form_id);
|
||||
|
||||
public function subscribe_from_ninja_forms( $email_address, $merge_fields, $list_id, $double_optin = true, $update_existing = false, $replace_interests = false, $form_id = 0 ) {
|
||||
// set options from parameters (coming from action)
|
||||
$orig_options = $this->options;
|
||||
$this->options['double_optin'] = $double_optin;
|
||||
$this->options['update_existing'] = $update_existing;
|
||||
$this->options['replace_interests'] = $replace_interests;
|
||||
$this->options['lists'] = array( $list_id );
|
||||
// revert to original options
|
||||
$this->options = $orig_options;
|
||||
}
|
||||
|
||||
$data = $merge_fields;
|
||||
$data['EMAIL'] = $email_address;
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_installed()
|
||||
{
|
||||
return class_exists('Ninja_Forms');
|
||||
}
|
||||
|
||||
$this->subscribe( $data, $form_id );
|
||||
/**
|
||||
* @since 3.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_ui_elements()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// revert to original options
|
||||
$this->options = $orig_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_installed() {
|
||||
return class_exists( 'Ninja_Forms' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_ui_elements() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $form_id
|
||||
* @return string
|
||||
*/
|
||||
public function get_object_link( $form_id ) {
|
||||
return '<a href="' . admin_url( sprintf( 'admin.php?page=ninja-forms&form_id=%d', $form_id ) ) . '">Ninja Forms</a>';
|
||||
}
|
||||
/**
|
||||
* @param int $form_id
|
||||
* @return string
|
||||
*/
|
||||
public function get_object_link($form_id)
|
||||
{
|
||||
return '<a href="' . admin_url(sprintf('admin.php?page=ninja-forms&form_id=%d', $form_id)) . '">Ninja Forms</a>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user