/**
  * Test post creation fields
  *
  * @since 7.3
  */
 public function testPostCreationFields()
 {
     $slugs = array('single-line-text', 'name', 'paragraph-text', 'paragraph-text', 'email', 'checkboxes', 'radio', 'dropdown');
     $form_response = $this->_createForm(array(array('slug' => $slugs[0], 'type' => 'single-line-text', 'required' => true), array('slug' => $slugs[1], 'type' => 'name', 'required' => true), array('slug' => $slugs[2], 'type' => 'paragraph-text', 'required' => true), array('slug' => $slugs[3], 'type' => 'paragraph-text', 'required' => true), array('slug' => $slugs[4], 'type' => 'email', 'required' => true, 'confirm' => true), array('slug' => $slugs[5], 'type' => 'checkboxes', 'choices' => array(array('label' => 'tag1', 'value' => 'tag1', 'selected' => false), array('label' => 'tag2', 'value' => 'tag2', 'selected' => false), array('label' => 'tag3', 'value' => 'tag3', 'selected' => false)), 'required' => true), array('slug' => $slugs[6], 'type' => 'radio', 'choices' => array(array('label' => 'tag4', 'value' => 'tag4', 'selected' => false)), 'required' => true), array('slug' => $slugs[7], 'type' => 'dropdown', 'choices' => array(array('label' => 'tag5', 'value' => 'tag5', 'selected' => false)), 'required' => true)), array('postCreation' => true, 'postCreationType' => 'post', 'postCreationStatus' => 'publish', 'postFieldMappings' => array(array('postField' => 'post_title', 'formField' => $slugs[0] . '1', 'customFieldKey' => ''), array('postField' => 'custom_field', 'formField' => $slugs[1] . '2', 'customFieldKey' => 'name'), array('postField' => 'post_content', 'formField' => $slugs[2] . '3', 'customFieldKey' => ''), array('postField' => 'post_excerpt', 'formField' => $slugs[3] . '4', 'customFieldKey' => ''), array('postField' => 'custom_field', 'formField' => $slugs[4] . '5', 'customFieldKey' => 'email'), array('postField' => 'post_tag', 'formField' => $slugs[5] . '6', 'customFieldKey' => ''), array('postField' => 'post_tag', 'formField' => $slugs[6] . '7', 'customFieldKey' => ''), array('postField' => 'post_tag', 'formField' => $slugs[7] . '8', 'customFieldKey' => ''))));
     $_POST['form_id'] = $form_response->data['id'];
     $_POST['ccf_form'] = true;
     $_POST['form_nonce'] = wp_create_nonce('ccf_form');
     $_POST['ccf_field_' . $slugs[0] . '1'] = 'title';
     $_POST['ccf_field_' . $slugs[1] . '2'] = array('first' => 'taylor', 'last' => 'lovett');
     $_POST['ccf_field_' . $slugs[2] . '3'] = 'content';
     $_POST['ccf_field_' . $slugs[3] . '4'] = 'excerpt';
     $_POST['ccf_field_' . $slugs[4] . '5'] = array('email' => '*****@*****.**', 'confirm' => '*****@*****.**');
     $_POST['ccf_field_' . $slugs[5] . '6'] = array('tag1', 'tag2', 'tag3');
     $_POST['ccf_field_' . $slugs[6] . '7'] = 'tag4';
     $_POST['ccf_field_' . $slugs[7] . '8'] = 'tag5';
     add_action('ccf_post_creation', function ($post_creation_id, $form_id, $submission_id, $submission) {
         $this->post_creation = array('post_creation_id' => $post_creation_id, 'form_id' => $form_id, 'submission_id' => $submission_id, 'submission' => $submission);
     }, 10, 4);
     CCF_Form_Handler::factory()->submit_listen();
     $this->assertTrue(!empty($this->post_creation));
     $post = get_post($this->post_creation['post_creation_id']);
     $this->assertEquals('title', $post->post_title);
     $this->assertEquals('taylor lovett', get_post_meta($this->post_creation['post_creation_id'], 'name', true));
     $this->assertEquals('content', $post->post_content);
     $this->assertEquals('excerpt', $post->post_excerpt);
     $this->assertEquals('*****@*****.**', get_post_meta($this->post_creation['post_creation_id'], 'email', true));
     $tags = wp_get_post_tags($this->post_creation['post_creation_id']);
     $this->assertEquals(5, count($tags));
     $i = 1;
     foreach ($tags as $tag) {
         $this->assertEquals('tag' . $i, $tag->name);
         $i++;
     }
 }
 /**
  * Test notification multiple addresses
  *
  * @since 7.1
  */
 public function testNotificationMultipleAddresses()
 {
     $slug = 'single-line-text';
     $form_response = $this->_createForm(array(array('slug' => $slug, 'type' => 'single-line-text', 'required' => true)), array('notifications' => array(array('title' => 'one', 'content' => '', 'active' => true, 'addresses' => array(array('type' => 'custom', 'email' => '*****@*****.**', 'field' => ''), array('type' => 'custom', 'email' => '*****@*****.**', 'field' => '')), 'fromType' => 'default', 'fromAddress' => '', 'fromField' => '', 'subjectType' => 'field', 'subject' => '', 'subjectField' => '', 'fromNameType' => 'custom', 'fromName' => 'WordPress', 'fromNameField' => ''))));
     $_POST['form_id'] = $form_response->data['id'];
     $_POST['ccf_form'] = true;
     $_POST['form_nonce'] = wp_create_nonce('ccf_form');
     $_POST['ccf_field_' . $slug . '1'] = 'test';
     add_action('ccf_send_notification', function ($email, $subject, $notification_content, $notification_headers, $notification) {
         $this->notifications[] = array('email' => $email, 'subject' => $subject, 'content' => $notification_content, 'headers' => $notification_headers, 'notification' => $notification);
     }, 10, 5);
     CCF_Form_Handler::factory()->submit_listen();
     $this->assertEquals(2, count($this->notifications));
     $this->assertEquals('*****@*****.**', $this->notifications[0]['email']);
     $this->assertEquals('*****@*****.**', $this->notifications[1]['email']);
 }
    /**
     * Get paragraph-text field HTML, including any errors from the last form submission. if there is an
     * error the field will remember it's last submitted value.
     *
     * @param int $field_id
     * @param int $form_id
     * @since 6.0
     * @return string
     */
    public function paragraph_text($field_id, $form_id)
    {
        $slug = get_post_meta($field_id, 'ccf_field_slug', true);
        $label = get_post_meta($field_id, 'ccf_field_label', true);
        $value = get_post_meta($field_id, 'ccf_field_value', true);
        $placeholder = get_post_meta($field_id, 'ccf_field_placeholder', true);
        $required = get_post_meta($field_id, 'ccf_field_required', true);
        $class_name = get_post_meta($field_id, 'ccf_field_className', true);
        $description = get_post_meta($field_id, 'ccf_field_description', true);
        $errors = CCF_Form_Handler::factory()->get_errors($form_id, $slug);
        $all_errors = CCF_Form_Handler::factory()->get_errors($form_id);
        if (!empty($all_errors)) {
            if (apply_filters('ccf_show_last_field_value', true, $field_id)) {
                if (!empty($_POST['ccf_field_' . $slug])) {
                    $post_value = $_POST['ccf_field_' . $slug];
                }
            }
        }
        ob_start();
        ?>

		<div data-field-type="paragraph-text" data-field-slug="<?php 
        echo esc_attr($slug);
        ?>
" class="<?php 
        if (!empty($errors)) {
            ?>
field-error<?php 
        }
        ?>
 field <?php 
        echo esc_attr($slug);
        ?>
 paragraph-text field-<?php 
        echo (int) $field_id;
        ?>
 <?php 
        echo esc_attr($class_name);
        ?>
 <?php 
        if (!empty($required)) {
            ?>
field-required<?php 
        }
        ?>
">
			<label for="ccf_field_<?php 
        echo esc_attr($slug);
        ?>
">
				<?php 
        if (!empty($required)) {
            ?>
<span class="required">*</span><?php 
        }
        ?>
				<?php 
        echo esc_html($label);
        ?>
			</label>
			<textarea class="<?php 
        if (!empty($errors)) {
            ?>
field-error-input<?php 
        }
        ?>
 field-input" <?php 
        if (!empty($required)) {
            ?>
required aria-required="true"<?php 
        }
        ?>
 name="ccf_field_<?php 
        echo esc_attr($slug);
        ?>
" id="ccf_field_<?php 
        echo esc_attr($slug);
        ?>
" placeholder="<?php 
        echo esc_attr($placeholder);
        ?>
"><?php 
        if (!empty($post_value)) {
            echo esc_attr($post_value);
        } else {
            echo esc_attr($value);
        }
        ?>
</textarea>

			<?php 
        if (!empty($description)) {
            ?>
				<div class="field-description">
					<?php 
            echo esc_html($description);
            ?>
				</div>
			<?php 
        }
        ?>

			<?php 
        if (!empty($errors)) {
            ?>
				<div class="error"><?php 
            echo esc_html($errors['required']);
            ?>
</div>
			<?php 
        }
        ?>
		</div>

		<?php 
        return ob_get_clean();
    }
    /**
     * Return form HTML for a given form ID
     *
     * @param int $form_id
     * @since 6.0
     * @return string
     */
    public function get_rendered_form($form_id)
    {
        $form = get_post((int) $form_id);
        if (!$form) {
            return '';
        }
        $fields = get_post_meta($form_id, 'ccf_attached_fields', true);
        $pause = get_post_meta($form_id, 'ccf_form_pause', true);
        if (empty($fields)) {
            return '';
        }
        ob_start();
        if (!empty($pause)) {
            $pause_message = get_post_meta($form_id, 'ccf_form_pause_message', true);
            ?>

			<div class="ccf-form-pause form-id-<?php 
            echo (int) $form_id;
            ?>
">
				<?php 
            if (empty($pause_message)) {
                ?>
					<?php 
                esc_html_e('This form is paused right now. Check back later!', 'custom-contact-forms');
                ?>
				<?php 
            } else {
                ?>
					<?php 
                echo esc_html($pause_message);
                ?>
				<?php 
            }
            ?>
			</div>

			<?php 
        } elseif (!empty($_POST['ccf_form']) && !empty($_POST['form_id']) && $_POST['form_id'] == $form_id && empty(CCF_Form_Handler::factory()->errors_by_form[$form_id])) {
            $completion_message = get_post_meta($form_id, 'ccf_form_completion_message', true);
            ?>

			<div class="ccf-form-complete form-id-<?php 
            echo (int) $form_id;
            ?>
">
				<?php 
            if (empty($completion_message)) {
                ?>
					<?php 
                esc_html_e('Thank you for your submission.', 'custom-contact-forms');
                ?>
				<?php 
            } else {
                ?>
					<?php 
                echo esc_html($completion_message);
                ?>
				<?php 
            }
            ?>
			</div>

			<?php 
        } else {
            $contains_file = false;
            $fields_html = '';
            $conditionals = array();
            foreach ($fields as $field_id) {
                $field_id = (int) $field_id;
                $type = esc_attr(get_post_meta($field_id, 'ccf_field_type', true));
                $slug = get_post_meta($field_id, 'ccf_field_slug', true);
                $conditionals_enabled = get_post_meta($field_id, 'ccf_field_conditionalsEnabled', true);
                if (!empty($conditionals_enabled)) {
                    // Todo: escaping?
                    $field_conditionals = get_post_meta($field_id, 'ccf_attached_conditionals', true);
                    if (!empty($field_conditionals)) {
                        $new_conditionals = array('conditions' => $field_conditionals, 'conditionalType' => get_post_meta($field_id, 'ccf_field_conditionalType', true), 'conditionalFieldsRequired' => get_post_meta($field_id, 'ccf_field_conditionalFieldsRequired', true));
                        $conditionals[$slug] = $new_conditionals;
                    }
                }
                if ('file' === $type) {
                    $contains_file = true;
                }
                $fields_html .= apply_filters('ccf_field_html', CCF_Field_Renderer::factory()->render_router($type, $field_id, $form_id), $type, $field_id);
            }
            if (CCF_Field_Renderer::factory()->section_open) {
                $fields_html .= '</div>';
            }
            $theme = get_post_meta($form_id, 'ccf_form_theme', true);
            if (empty($theme)) {
                $theme = 'default';
            }
            ?>

			<div class="ccf-form-wrapper form-id-<?php 
            echo (int) $form_id;
            ?>
" data-form-id="<?php 
            echo (int) $form_id;
            ?>
">
				<form <?php 
            if ($contains_file) {
                ?>
enctype="multipart/form-data"<?php 
            }
            ?>
 class="ccf-form ccf-theme-<?php 
            echo esc_attr($theme);
            ?>
" method="post" action="" data-form-id="<?php 
            echo (int) $form_id;
            ?>
">

					<?php 
            $title = get_the_title($form_id);
            if (!empty($title) && apply_filters('ccf_show_form_title', true, $form_id)) {
                ?>
						<div class="form-title">
							<?php 
                echo $title;
                ?>
						</div>
					<?php 
            }
            ?>

					<?php 
            $description = get_post_meta($form_id, 'ccf_form_description', true);
            if (!empty($description) && apply_filters('ccf_show_form_description', true, $form_id)) {
                ?>
						<div class="form-description">
							<?php 
                echo esc_html($description);
                ?>
						</div>
					<?php 
            }
            ?>

					<?php 
            echo $fields_html;
            ?>

					<div class="form-submit">
						<input type="submit" class="btn btn-primary ccf-submit-button" value="<?php 
            echo esc_attr(get_post_meta($form_id, 'ccf_form_buttonText', true));
            ?>
">
						<img class="loading-img" src="<?php 
            echo esc_url(site_url('/wp-admin/images/wpspin_light.gif'));
            ?>
">
					</div>

					<script type="text/javascript">
					window.wp = window.wp || {};
					wp.ccf = wp.ccf || {};
					wp.ccf.conditionals = wp.ccf.conditionals || [];
					wp.ccf.conditionals[<?php 
            echo (int) $form_id;
            ?>
] = <?php 
            echo wp_json_encode($conditionals);
            ?>
;
					</script>

					<input type="hidden" name="form_id" value="<?php 
            echo (int) $form_id;
            ?>
">
					<input type="hidden" name="form_page" value="<?php 
            echo esc_url(untrailingslashit(site_url()) . $_SERVER['REQUEST_URI']);
            ?>
">
					<input type="text" name="my_information" style="display: none;">
					<input type="hidden"  name="ccf_form" value="1">
					<input type="hidden" name="form_nonce" value="<?php 
            echo wp_create_nonce('ccf_form');
            ?>
">
				</form>

				<iframe class="ccf-form-frame" id="ccf_form_frame_<?php 
            echo (int) $form_id;
            ?>
" name="ccf_form_frame_<?php 
            echo (int) $form_id;
            ?>
"></iframe>
			</div>

			<?php 
        }
        $form_html = ob_get_clean();
        return $form_html;
    }
require_once dirname(__FILE__) . '/classes/class-ccf-form-handler.php';
require_once dirname(__FILE__) . '/classes/class-ccf-upgrader.php';
require_once dirname(__FILE__) . '/classes/class-ccf-widget.php';
require_once dirname(__FILE__) . '/classes/class-ccf-export.php';
require_once dirname(__FILE__) . '/classes/class-ccf-ads.php';
require_once dirname(__FILE__) . '/classes/class-ccf-settings.php';
CCF_Custom_Contact_Forms::factory();
CCF_Constants::factory();
CCF_Form_CPT::factory();
CCF_Submission_CPT::factory();
CCF_Field_CPT::factory();
CCF_Choice_CPT::factory();
CCF_Form_Manager::factory();
CCF_Form_Renderer::factory();
CCF_Field_Renderer::factory();
CCF_Form_Handler::factory();
CCF_Upgrader::factory();
CCF_Export::factory();
CCF_Ads::factory();
CCF_Settings::factory();
/**
 * Setup the widget
 *
 * @since 6.4
 */
function ccf_register_widget()
{
    register_widget('CCF_Widget');
}
add_action('widgets_init', 'ccf_register_widget');
/**
    /**
     * Return form HTML for a given form ID
     *
     * @param int $form_id
     * @since 6.0
     * @return string
     */
    public function get_rendered_form($form_id)
    {
        $form = get_post((int) $form_id);
        if (!$form) {
            return '';
        }
        $fields = get_post_meta($form_id, 'ccf_attached_fields', true);
        $pause = get_post_meta($form_id, 'ccf_form_pause', true);
        if (empty($fields)) {
            return '';
        }
        ob_start();
        if (!empty($pause)) {
            $pause_message = get_post_meta($form_id, 'ccf_form_pause_message', true);
            ?>

			<div class="ccf-form-pause form-id-<?php 
            echo (int) $form_id;
            ?>
">
				<?php 
            if (empty($pause_message)) {
                ?>
					<?php 
                esc_html_e('This form is paused right now. Check back later!', 'custom-contact-forms');
                ?>
				<?php 
            } else {
                ?>
					<?php 
                echo esc_html($pause_message);
                ?>
				<?php 
            }
            ?>
			</div>

			<?php 
        } elseif (!empty($_POST['ccf_form']) && !empty($_POST['form_id']) && $_POST['form_id'] == $form_id && empty(CCF_Form_Handler::factory()->errors_by_form[$form_id])) {
            $completion_message = get_post_meta($form_id, 'ccf_form_completion_message', true);
            ?>

			<div class="ccf-form-complete form-id-<?php 
            echo (int) $form_id;
            ?>
">
				<?php 
            if (empty($completion_message)) {
                ?>
					<?php 
                esc_html_e('Thank you for your submission.', 'custom-contact-forms');
                ?>
				<?php 
            } else {
                ?>
					<?php 
                echo esc_html($completion_message);
                ?>
				<?php 
            }
            ?>
			</div>

			<?php 
        } else {
            $contains_file = false;
            $fields_html = '';
            foreach ($fields as $field_id) {
                $field_id = (int) $field_id;
                $type = esc_attr(get_post_meta($field_id, 'ccf_field_type', true));
                if ('file' === $type) {
                    $contains_file = true;
                }
                $fields_html .= apply_filters('ccf_field_html', CCF_Field_Renderer::factory()->render_router($type, $field_id, $form_id), $type, $field_id);
            }
            ?>

			<div class="ccf-form-wrapper form-id-<?php 
            echo (int) $form_id;
            ?>
" data-form-id="<?php 
            echo (int) $form_id;
            ?>
">
				<form <?php 
            if ($contains_file) {
                ?>
enctype="multipart/form-data"<?php 
            }
            ?>
 class="ccf-form" method="post" action="" data-form-id="<?php 
            echo (int) $form_id;
            ?>
">

					<?php 
            $title = get_the_title($form_id);
            if (!empty($title) && apply_filters('ccf_show_form_title', true, $form_id)) {
                ?>
						<div class="form-title">
							<?php 
                echo $title;
                ?>
						</div>
					<?php 
            }
            ?>

					<?php 
            $description = get_post_meta($form_id, 'ccf_form_description', true);
            if (!empty($description) && apply_filters('ccf_show_form_description', true, $form_id)) {
                ?>
						<div class="form-description">
							<?php 
                echo esc_html($description);
                ?>
						</div>
					<?php 
            }
            ?>

					<?php 
            echo $fields_html;
            ?>

					<div class="form-submit">
						<input type="submit" class="ccf-submit-button" value="<?php 
            echo esc_attr(get_post_meta($form_id, 'ccf_form_buttonText', true));
            ?>
">
						<img class="loading-img" src="<?php 
            echo esc_url(site_url('/wp-admin/images/wpspin_light.gif'));
            ?>
">
					</div>

					<input type="hidden" name="form_id" value="<?php 
            echo (int) $form_id;
            ?>
">
					<input type="hidden" name="form_page" value="<?php 
            echo esc_url(untrailingslashit(site_url()) . $_SERVER['REQUEST_URI']);
            ?>
">
					<input type="text" name="my_information" style="display: none;">
					<input type="hidden"  name="ccf_form" value="1">
					<input type="hidden" name="form_nonce" value="<?php 
            echo wp_create_nonce('ccf_form');
            ?>
">
				</form>

				<iframe onload="wp.ccf.iframeOnload( <?php 
            echo (int) $form_id;
            ?>
 );" class="ccf-form-frame" id="ccf_form_frame_<?php 
            echo (int) $form_id;
            ?>
" name="ccf_form_frame_<?php 
            echo (int) $form_id;
            ?>
"></iframe>
			</div>

			<?php 
        }
        $form_html = ob_get_clean();
        return $form_html;
    }
 /**
  * Test date/time field errors
  *
  * @since 6.4
  */
 public function testDateTime()
 {
     $slug = 'date';
     $form_response = $this->_createForm(array(array('slug' => $slug, 'type' => 'date', 'showDate' => true, 'showTime' => true, 'required' => true)));
     $_POST['form_id'] = $form_response->data['id'];
     $_POST['ccf_form'] = true;
     $_POST['form_nonce'] = wp_create_nonce('ccf_form');
     CCF_Form_Handler::factory()->submit_listen();
     $this->assertTrue(!empty(CCF_Form_Handler::factory()->errors_by_form[$form_response->data['id']][$slug . '1']['date_required']));
     $this->assertTrue(!empty(CCF_Form_Handler::factory()->errors_by_form[$form_response->data['id']][$slug . '1']['hour_required']));
     $this->assertTrue(!empty(CCF_Form_Handler::factory()->errors_by_form[$form_response->data['id']][$slug . '1']['minutes_required']));
     $this->assertTrue(!empty(CCF_Form_Handler::factory()->errors_by_form[$form_response->data['id']][$slug . '1']['am-pm_required']));
     CCF_Form_Handler::factory()->errors_by_form = array();
     $_POST['ccf_field_' . $slug . '1']['date'] = 'a';
     $_POST['ccf_field_' . $slug . '1']['hour'] = 'a';
     $_POST['ccf_field_' . $slug . '1']['minute'] = 'b';
     $_POST['ccf_field_' . $slug . '1']['am-pm'] = 'am';
     CCF_Form_Handler::factory()->submit_listen();
     $this->assertTrue(!empty(CCF_Form_Handler::factory()->errors_by_form[$form_response->data['id']][$slug . '1']['minute']));
     $this->assertTrue(!empty(CCF_Form_Handler::factory()->errors_by_form[$form_response->data['id']][$slug . '1']['hour']));
     $this->assertTrue(!empty(CCF_Form_Handler::factory()->errors_by_form[$form_response->data['id']][$slug . '1']['date']));
     CCF_Form_Handler::factory()->errors_by_form = array();
     $_POST['ccf_field_' . $slug . '1']['date'] = '10/1/1900';
     $_POST['ccf_field_' . $slug . '1']['hour'] = '10';
     $_POST['ccf_field_' . $slug . '1']['minute'] = '12';
     $_POST['ccf_field_' . $slug . '1']['am-pm'] = 'am';
     CCF_Form_Handler::factory()->submit_listen();
     $this->assertTrue(empty(CCF_Form_Handler::factory()->errors_by_form[$form_response->data['id']][$slug . '1']));
 }