function constant_contact_retrieve_form($formid, $force_update = false, $unique_id = '', $lists = array()) { $_GET['cc_signup_count'] = empty($_GET['cc_signup_count']) ? 1 : $_GET['cc_signup_count']++; $formid = (int) $formid; $success = get_transient($unique_id); $success = !empty($success); $form = get_transient("cc_form_{$formid}"); // If it is an array and we are not forcing an update, return the data if (!empty($form) && !$success && !$force_update && !isset($_GET['asdasdas'])) { do_action('ctct_debug', 'Returning Cached Form #' . $formid, $form); // Basic form validation - make sure it's got basic if (preg_match('/kws_form/m', $form)) { return $form; } } $form = wp_get_cc_form($formid); if ($form && is_array($form)) { // Just the items we need, please. unset($form['_wp_http_referer'], $form['update-cc-form-nonce'], $form['meta-box-order-nonce'], $form['closedpostboxesnonce'], $form['save_form'], $form['page'], $form['form-name'], $form['action'], $form['form-style'], $form['presets'], $form['truncated_name']); } else { $form = array('formOnly' => true); } $form['output'] = 'html'; $form['time'] = time(); $form['verify'] = sha1($unique_id . $form['time']); $form['echo'] = true; $form['path'] = CC_FORM_GEN_URL; $form['cc_success'] = $success; $form['cc_signup_count'] = $_GET['cc_signup_count']; $form['cc_request'] = empty($_REQUEST['uniqueformid']) ? array() : $_REQUEST; $form['uniqueformid'] = $unique_id; $form['debug'] = current_user_can('manage_options') && isset($_GET['debug']); $form_html = new CTCT_Form_Designer_Output($form); return $form_html->html(); // Get the form from form.php $response = wp_remote_request(admin_url('admin-ajax.php'), array('method' => 'POST', 'timeout' => 20, 'body' => $form, 'sslverify' => false, 'compress' => true, 'local' => true)); do_action('ctct_debug', 'Requesting Form Data for Form #' . $formid, array('POST body' => $form, 'POST response:' => $response)); if (is_wp_error($response)) { do_action('ctct_log', $response, 'error'); if (current_user_can('manage_options')) { echo '<!-- Constant Contact API Error: `wp_remote_post` failed with this error: ' . $response->get_error_message() . ' -->'; } return false; } else { $form = $response['body']; if (empty($_POST) && !$success) { // Save the array into the cc_form_id transient with a 30 day expiration $set = set_transient("cc_form_{$formid}", $form, 60 * 60 * 24 * 30); if (!$set) { do_action('ctct_log', 'Setting cc_form_' . $formid . ' Transient failed', $form); } } return $form; } }