<?php
defined('ABSPATH') or die('No script kiddies please!!');
if ((!empty($form_details['general']['mailerlite_id']) || !empty($std_settings['mailerlite']['mailerlite_lists'])) && !empty($std_settings['mailerlite']['enable'])) {
    $post_parameters = array('email' => $form_data['std_email'], 'name' => $fname . ' ' . $lname);
    /**
     * Filters parameters being sent to Mailerlite
     *
     * @param array $post_parameters
     * @param array $form_data
     * @param array $form_details
     */
    $post_parameters = apply_filters('std_ml_post_parameters', $post_parameters, $form_data, $form_details);
    $settings_mailerlite_lists_obj = json_decode($std_settings['mailerlite']['mailerlite_lists']);
    $settings_mailerlite_lists = [];
    if (!empty($std_settings['mailerlite']['enable'])) {
        if (!empty($settings_mailerlite_lists_obj)) {
            foreach ($settings_mailerlite_lists_obj as $mailerlite_list) {
                $settings_mailerlite_lists[] = $mailerlite_list->id;
            }
        }
    }
    $mailerlite_lists = (!empty($form_details['general']['mailerlite_id'])) ? $form_details['general']['mailerlite_id'] : $settings_mailerlite_lists;
    if (!empty($mailerlite_lists)) {
        foreach ($mailerlite_lists as $mailerlite_id) {
            $this->subscribe_to_mailerlite($mailerlite_id, $post_parameters);
        }
    }
}
