Example #1
0
 /**
  * Primary class constructor.
  *
  * @since 1.0.0
  */
 public function __construct()
 {
     // Load form if found
     $form_id = isset($_GET['form_id']) ? absint($_GET['form_id']) : false;
     $this->form = wpforms()->form->get($form_id);
     $this->form_data = $this->form ? wpforms_decode($this->form->post_content) : false;
     // Bootstrap
     $this->init();
     // Load panel specific enqueus
     add_action('admin_enqueue_scripts', array($this, 'enqueues'), 15);
     // Primary panel button
     add_action('wpforms_builder_panel_buttons', array($this, 'button'), $this->order, 2);
     // Output
     add_action('wpforms_builder_panels', array($this, 'panel_output'), $this->order, 2);
 }
 /**
  * Determing if the user is viewing the overview page, if so, party on.
  *
  * @since 1.0.0
  */
 public function init()
 {
     // Check what page we are on
     $page = isset($_GET['page']) ? $_GET['page'] : '';
     // Only load if we are actually on the overview page
     if ($page == 'wpforms-overview') {
         // The overview page leverages WP_List_Table so we must load it
         if (!class_exists('WP_List_Table')) {
             require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
         }
         // Load the class that builds the overview table
         require_once WPFORMS_PLUGIN_DIR . 'includes/admin/overview/class-overview-table.php';
         // Preview page check
         wpforms()->preview->form_preview_check();
         add_action('admin_enqueue_scripts', array($this, 'enqueues'));
         add_action('wpforms_admin_page', array($this, 'output'));
         // Provide hook for add-ons
         do_action('wpforms_overview_init');
     }
 }
Example #3
0
 /**
  * Validates field on form submit.
  *
  * @since 1.0.0
  * @param int $field_id
  * @param array $field_submit
  * @param array $form_data
  */
 public function validate($field_id, $field_submit, $form_data)
 {
     $form_id = $form_data['id'];
     // Basic required check - If field is marked as required, check for entry data
     if (!empty($form_data['fields'][$field_id]['required']) && empty($field_submit)) {
         wpforms()->process->errors[$form_id][$field_id] = apply_filters('wpforms_required_label', __('This field is required', 'wpforms'));
     }
     // Check that email is valid format
     if (!empty($field_submit) && !is_email($field_submit)) {
         wpforms()->process->errors[$form_id][$field_id] = apply_filters('wpforms_valid_email_label', __('Please enter a valid email address.', 'wpforms'));
     }
 }
/**
 * Form Builder update next field ID.
 *
 * @since 1.2.9
 */
function wpforms_builder_increase_next_field_id()
{
    // Run a security check
    check_ajax_referer('wpforms-builder', 'nonce');
    // Check for permissions
    if (!current_user_can(apply_filters('wpforms_manage_cap', 'manage_options'))) {
        wp_send_json_error();
    }
    // Check for required items
    if (empty($_POST['form_id'])) {
        wp_send_json_error();
    }
    wpforms()->form->next_field_id(absint($_POST['form_id']));
    wp_send_json_success();
}
Example #5
0
 /**
  * Formats field.
  *
  * @since 1.0.0
  * @param int $field_id
  * @param array $field_submit
  * @param array $form_data
  */
 public function format($field_id, $field_submit, $form_data)
 {
     $name = !empty($form_data['fields'][$field_id]['label']) ? $form_data['fields'][$field_id]['label'] : '';
     $first = !empty($field_submit['first']) ? $field_submit['first'] : '';
     $middle = !empty($field_submit['middle']) ? $field_submit['middle'] : '';
     $last = !empty($field_submit['last']) ? $field_submit['last'] : '';
     if (is_array($field_submit)) {
         $value = array($first, $middle, $last);
         $value = array_filter($value);
         $value = implode(' ', $value);
     } else {
         $value = $field_submit;
     }
     wpforms()->process->fields[$field_id] = array('name' => sanitize_text_field($name), 'value' => sanitize_text_field($value), 'id' => absint($field_id), 'type' => $this->type, 'first' => sanitize_text_field($first), 'middle' => sanitize_text_field($middle), 'last' => sanitize_text_field($last));
 }
 /**
  * Deletes forms
  *
  * @since 1.0.0
  * @param array $ids
  * @return boolean
  */
 public function delete($ids = array())
 {
     // Check for permissions
     if (!current_user_can(apply_filters('wpforms_manage_cap', 'manage_options'))) {
         return false;
     }
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $ids = array_map('absint', $ids);
     foreach ($ids as $id) {
         $form = wp_delete_post($id, true);
         if (class_exists('WPForms_Entry_Handler')) {
             $entries = wpforms()->entry->delete_by('form_id', $id);
         }
         if (!$form) {
             return false;
         }
     }
     return true;
 }
            if (!defined('WPFORMS_PLUGIN_FILE')) {
                define('WPFORMS_PLUGIN_FILE', __FILE__);
            }
        }
        /**
         * Loads the plugin language files.
         *
         * @since 1.0.0
         */
        public function load_textdomain()
        {
            load_plugin_textdomain('wpforms', false, dirname(plugin_basename(__FILE__)) . '/languages/');
        }
    }
    /**
     * The function which returns the one WPForms instance.
     *
     * Use this function like you would a global variable, except without needing
     * to declare the global.
     *
     * Example: <?php $wpforms = wpforms(); ?>
     *
     * @since 1.0.0
     * @return object
     */
    function wpforms()
    {
        return WPForms::instance();
    }
    wpforms();
}
 /**
  * Formats and sanitizes field.
  *
  * @since 1.0.2
  * @param int $field_id
  * @param array $field_submit
  * @param array $form_data
  */
 public function format($field_id, $field_submit, $form_data)
 {
     $field = $form_data['fields'][$field_id];
     $dynamic = !empty($field['dynamic_choices']) ? $field['dynamic_choices'] : false;
     $name = sanitize_text_field($field['label']);
     $value_raw = sanitize_text_field($field_submit);
     $value = '';
     $data = array('name' => $name, 'value' => '', 'value_raw' => $value_raw, 'id' => absint($field_id), 'type' => $this->type);
     if ('post_type' == $dynamic && !empty($field['dynamic_post_type'])) {
         // Dynamic population is enabled using post type
         $data['dynamic'] = 'post_type';
         $data['dynamic_post_type'] = absint($value_raw);
         $source = $field['dynamic_post_type'];
         $post = get_post($value_raw);
         if (!is_wp_error($post) && !empty($post) && $source == $post->post_type) {
             $data['value'] = esc_html($post->post_title);
         }
     } elseif ('taxonomy' == $dynamic && !empty($field['dynamic_taxonomy'])) {
         // Dynamic population is enabled using taxonomy
         $data['dynamic'] = 'taxonomy';
         $data['dynamic_taxonomy'] = absint($value_raw);
         $source = $field['dynamic_taxonomy'];
         $term = get_term($value_raw, $source);
         if (!is_wp_error($term) && !empty($term)) {
             $data['value'] = esc_html($term->name);
         }
     } else {
         // Normal processing, dynamic population is off
         // If show_values is true, that means values posted are the raw values
         // and not the labels. So we need to get the label values.
         if (!empty($field['show_values']) && '1' == $field['show_values']) {
             foreach ($field['choices'] as $choice) {
                 if ($choice['value'] === $field_submit) {
                     $value = $choice['label'];
                     break;
                 }
             }
             $data['value'] = sanitize_text_field($value);
         } else {
             $data['value'] = $value_raw;
         }
     }
     // Push field details to be saved
     wpforms()->process->fields[$field_id] = $data;
 }
 /**
  * Fetch and setup the final data for the table
  *
  * @since 1.0.0
  */
 public function prepare_items()
 {
     // Process bulk actions if found
     $this->process_bulk_actions();
     // Setup the columns
     $columns = $this->get_columns();
     // Hidden columns (none)
     $hidden = array();
     // Define which columns can be sorted - form name, date
     $sortable = array('form_name' => array('title', false), 'created' => array('date', false));
     // Set column headers
     $this->_column_headers = array($columns, $hidden, $sortable);
     // Get forms
     $total = wp_count_posts('wpforms')->publish;
     $page = $this->get_pagenum();
     $order = isset($_GET['order']) ? $_GET['order'] : 'DESC';
     $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'ID';
     $per_page = $this->get_items_per_page('wpforms_forms_per_page', $this->per_page);
     $data = wpforms()->form->get('', array('orderby' => $orderby, 'order' => $order, 'nopaging' => false, 'posts_per_page' => $per_page, 'paged' => $page, 'no_found_rows' => false));
     // Giddy up
     $this->items = $data;
     // Finalize pagination
     $this->set_pagination_args(array('total_items' => $total, 'per_page' => $per_page, 'total_pages' => ceil($total / $per_page)));
 }
/**
 * Update form template.
 *
 * @since 1.0.0
 */
function wpforms_update_form_template()
{
    // Run a security check
    check_ajax_referer('wpforms-builder', 'nonce');
    // Check for form title
    if (empty($_POST['form_id'])) {
        die(__('No form ID provided', 'wpforms'));
    }
    $data = wpforms()->form->get($_POST['form_id'], array('content_only' => true));
    $form_id = wpforms()->form->update($_POST['form_id'], $data, array('template' => $_POST['template']));
    if ($form_id) {
        $data = array('id' => $form_id, 'redirect' => add_query_arg(array('view' => 'fields', 'form_id' => $form_id), admin_url('admin.php?page=wpforms-builder')));
        wp_send_json_success($data);
    } else {
        die(__('Error updating form template', 'wpforms'));
    }
}
    /**
     * Load the appropriate files to build the page.
     *
     * @since 1.0.0
     */
    public function output()
    {
        $form_id = $this->form ? absint($this->form->ID) : '';
        $form_data = $this->form ? wpforms_decode($this->form->post_content) : false;
        ?>
		<div id="wpforms-builder">

			<div id="wpforms-builder-overlay">

				<div class="wpforms-builder-overlay-content">
					
					<i class="fa fa-cog fa-spin"></i>
					
					<span class="msg"><?php 
        _e('Loading', 'wpforms');
        ?>
</span>
				</div>

			</div>

			<form name="wpforms-builder" id="wpforms-builder-form" method="post" data-id="<?php 
        echo $form_id;
        ?>
">

				<input type="hidden" name="id" value="<?php 
        echo $form_id;
        ?>
">
				<input type="hidden" value="<?php 
        echo absint($form_data['field_id']);
        ?>
" name="field_id" id="wpforms-field-id">

				<!-- Toolbar -->
				<div class="wpforms-toolbar">

					<div class="wpforms-left">
						
						<img src="<?php 
        echo WPFORMS_PLUGIN_URL;
        ?>
/assets/images/logo-builder.png" alt="Sullie WPForms mascot">

					</div>

					<div class="wpforms-center">
						
						<?php 
        if ($this->form) {
            ?>

							<?php 
            _e('Now editing', 'wpforms');
            ?>
 <span class="wpforms-center-form-name wpforms-form-name"><?php 
            echo esc_html($this->form->post_title);
            ?>
</span>

						<?php 
        }
        ?>

					</div>

					<div class="wpforms-right">
						
						<?php 
        if ($this->form) {
            ?>

						<!--<a href="<?php 
            echo esc_url(wpforms()->preview->form_preview_url($form_id));
            ?>
" id="wpforms-preview" title="<?php 
            _e('Preview Form', 'wpforms');
            ?>
">
							<i class="fa fa-eye"></i> 
							<span class="text"><?php 
            _e('Preview', 'wpforms');
            ?>
</span>
						</a>-->
						
						<a href="#" id="wpforms-embed" title="<?php 
            _e('Embed Form', 'wpforms');
            ?>
">
							<i class="fa fa-code"></i> 
							<span class="text"><?php 
            _e('Embed', 'wpforms');
            ?>
</span>
						</a>
						
						<a href="#" id="wpforms-save" title="<?php 
            _e('Save Form', 'wpforms');
            ?>
">
							<i class="fa fa-check"></i> 
							<span class="text"><?php 
            _e('Save', 'wpforms');
            ?>
</span>
						</a>

						<?php 
        }
        ?>

						<a href="#" id="wpforms-exit" title="<?php 
        _e('Exit', 'wpforms');
        ?>
">
							<i class="fa fa-times"></i>
						</a>

					</div>

				</div>

				<!-- Panel toggle buttons -->
				<div class="wpforms-panels-toggle" id="wpforms-panels-toggle">
					
					<?php 
        do_action('wpforms_builder_panel_buttons', $this->form, $this->view);
        ?>

				</div>

				<div class="wpforms-panels">
					
					<?php 
        do_action('wpforms_builder_panels', $this->form, $this->view);
        ?>

				</div>

			</form>

		</div>
		<?php 
    }
Example #12
0
    /**
     * Displays the form for this widget on the Widgets page of the WP Admin area.
     *
     * @since 1.0.2
     * @param array $instance An array of the current settings for this widget
     */
    function form($instance)
    {
        // Merge with defaults
        $instance = wp_parse_args((array) $instance, $this->defaults);
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
">Title:</label>
			<input type="text" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" value="<?php 
        echo esc_attr($instance['title']);
        ?>
" class="widefat" />
		</p>
		<p>
			<label for="<?php 
        echo $this->get_field_id('form_id');
        ?>
">Form:</label>
			<select id="<?php 
        echo $this->get_field_id('form_id');
        ?>
" name="<?php 
        echo $this->get_field_name('form_id');
        ?>
" class="widefat">
				<?php 
        $forms = wpforms()->form->get();
        if (!empty($forms)) {
            foreach ($forms as $form) {
                printf('<option value="%d" %s>%s</option>', $form->ID, selected($instance['form_id'], $form->ID, false), esc_html($form->post_title));
            }
        } else {
            printf('<option value="">%s</option>', __('No forms', 'wpforms'));
        }
        ?>
			</select>
		</p>
		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('show_title');
        ?>
" name="<?php 
        echo $this->get_field_name('show_title');
        ?>
" <?php 
        checked('1', $instance['show_title']);
        ?>
>
			<label for="<?php 
        echo $this->get_field_id('show_title');
        ?>
"><?php 
        _e('Display form title', 'wpforms');
        ?>
</label>
			<br>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('show_desc');
        ?>
" name="<?php 
        echo $this->get_field_name('show_desc');
        ?>
" <?php 
        checked('1', $instance['show_desc']);
        ?>
>
			<label for="<?php 
        echo $this->get_field_id('show_desc');
        ?>
"><?php 
        _e('Display form description', 'wpforms');
        ?>
</label>
		</p>
		<?php 
    }
Example #13
0
    /**
     * Modal window for inserting the form shortcode into TinyMCE.
     *
     * Thickbox is old and busted so we don't use that. Creating a custom view in
     * Backbone would make me pull my hair out. So instead we offer a small clean
     * modal that is based off of the WordPress insert link modal.
     *
     * @since 1.0.0
     */
    function shortcode_modal()
    {
        ?>
		<div id="wpforms-modal-backdrop" style="display: none"></div>
		<div id="wpforms-modal-wrap" style="display: none">
			<form id="wpforms-modal" tabindex="-1">
			<div id="wpforms-modal-title">
				<?php 
        _e('Insert Form', 'wpforms');
        ?>
	
				<button type="button" id="wpforms-modal-close"><span class="screen-reader-text"><?php 
        _e('Close', 'wpforms');
        ?>
</span></button>
		 	</div>
			<div id="wpforms-modal-inner">		
				<div id="wpforms-modal-options">
						<?php 
        $args = apply_filters('wpforms_modal_select', array());
        $forms = wpforms()->form->get('', $args);
        if (!empty($forms)) {
            printf('<p><label for="wpforms-modal-select-form">%s</label></p>', __('Select a form below to insert', 'wpforms'));
            echo '<select id="wpforms-modal-select-form">';
            foreach ($forms as $form) {
                printf('<option value="%d">%s</option>', $form->ID, esc_html($form->post_title));
            }
            echo '</select><br>';
            printf('<p class="wpforms-modal-inline"><input type="checkbox" id="wpforms-modal-checkbox-title"><label for="wpforms-modal-checkbox-title">%s</label></p>', __('Show form title', 'wpforms'));
            printf('<p class="wpforms-modal-inline"><input type="checkbox" id="wpforms-modal-checkbox-description"><label for="wpforms-modal-checkbox-description">%s</label></p>', __('Show form description', 'wpforms'));
        } else {
            echo '<p>';
            printf(__('Whoops, you haven\'t created a form yet. Want to <a href="%s">give it a go</a>?', 'wpforms'), admin_url('admin.php?page=wpforms-builder'));
            echo '</p>';
        }
        ?>
				</div>
			</div>
			<div class="submitbox">
				<div id="wpforms-modal-cancel">
					<a class="submitdelete deletion" href="#"><?php 
        _e('Cancel', 'wpforms');
        ?>
</a>
				</div>
				<?php 
        if (!empty($forms)) {
            ?>
				<div id="wpforms-modal-update">
					<button class="button button-primary" id="wpforms-modal-submit"><?php 
            _e('Add Form', 'wpforms');
            ?>
</button>
				</div>
				<?php 
        }
        ?>
			</div>
			</form>
		</div>
		<style style="text/css">
			#wpforms-modal-wrap {
				display: none;
				background-color: #fff;
				-webkit-box-shadow: 0 3px 6px rgba( 0, 0, 0, 0.3 );
				box-shadow: 0 3px 6px rgba( 0, 0, 0, 0.3 );
				width: 500px;
				height: 220px;
				overflow: hidden;
				margin-left: -250px;
				margin-top: -125px;
				position: fixed;
				top: 50%;
				left: 50%;
				z-index: 100105;
				-webkit-transition: height 0.2s, margin-top 0.2s;
				transition: height 0.2s, margin-top 0.2s;
			}
			#wpforms-modal-backdrop {
				display: none;
				position: fixed;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				min-height: 360px;
				background: #000;
				opacity: 0.7;
				filter: alpha(opacity=70);
				z-index: 100100;
			}
			#wpforms-modal {
				position: relative;
				height: 100%;
			}
			#wpforms-modal-title {
				background: #fcfcfc;
				border-bottom: 1px solid #dfdfdf;
				height: 36px;
				font-size: 18px;
				font-weight: 600;
				line-height: 36px;
				padding: 0 36px 0 16px;
				top: 0;
				right: 0;
				left: 0;
			}
			#wpforms-modal-close {
				color: #666;
				padding: 0;
				position: absolute;
				top: 0;
				right: 0;
				width: 36px;
				height: 36px;
				text-align: center;
				background: none;
				border: none;
				cursor: pointer;
			}
			#wpforms-modal-close:before {
				font: normal 20px/36px 'dashicons';
				vertical-align: top;
				speak: none;
				-webkit-font-smoothing: antialiased;
				-moz-osx-font-smoothing: grayscale;
				width: 36px;
				height: 36px;
				content: '\f158';
			}
			#wpforms-modal-close:hover,
			#wpforms-modal-close:focus {
				color: #2ea2cc;
			}
			#wpforms-modal-close:focus {
				outline: none;
				-webkit-box-shadow:
					0 0 0 1px #5b9dd9,
					0 0 2px 1px rgba(30, 140, 190, .8);
				box-shadow:
					0 0 0 1px #5b9dd9,
					0 0 2px 1px rgba(30, 140, 190, .8);
			}
			#wpforms-modal-inner{
				padding: 0 16px 50px;
			}
			#wpforms-modal-search-toggle:after {
				display: inline-block;
				font: normal 20px/1 'dashicons';
				vertical-align: top;
				speak: none;
				-webkit-font-smoothing: antialiased;
				-moz-osx-font-smoothing: grayscale;
				content: '\f140';
			}
			#wpforms-modal #wpforms-modal-options {
				padding: 8px 0 12px;
			}
			#wpforms-modal #wpforms-modal-options .wpforms-modal-inline {
				display:inline-block;
				margin: 0;
				padding: 0 20px 0 0;
			}
			#wpforms-modal-select-form {
				margin-bottom: 1em;
				max-width: 100%;
			}
			#wpforms-modal .submitbox {
				padding: 8px 16px;
				background: #fcfcfc;
				border-top: 1px solid #dfdfdf;
				position: absolute;
				bottom: 0;
				left: 0;
				right: 0;
			}
			#wpforms-modal-cancel {
				line-height: 25px;
				float: left;
			}
			#wpforms-modal-update {
				line-height: 23px;
				float: right;
			}
			#wpforms-modal-submit {
				float: right;
				margin-bottom: 0;
			}
			@media screen and ( max-width: 782px ) {
				#wpforms-modal-wrap {
					height: 280px;
					margin-top: -140px;
				}
				#wpforms-modal-inner {
					padding: 0 16px 60px;
				}
				#wpforms-modal-cancel {
					line-height: 32px;
				}
			}
			@media screen and ( max-width: 520px ) {
				#wpforms-modal-wrap {
					width: auto;
					margin-left: 0;
					left: 10px;
					right: 10px;
					max-width: 500px;
				}
			}
			@media screen and ( max-height: 520px ) {
				#wpforms-modal-wrap {
					-webkit-transition: none;
					transition: none;
				}
			}
			@media screen and ( max-height: 290px ) {
				#wpforms-modal-wrap {
					height: auto;
					margin-top: 0;
					top: 10px;
					bottom: 10px;
				}
				#wpforms-modal-inner {
					overflow: auto;
					height: -webkit-calc(100% - 92px);
					height: calc(100% - 92px);
					padding-bottom: 2px;
				}
			}
		</style>
		<?php 
    }
 /**
  * Formats and sanitizes field.
  *
  * @since 1.0.0
  * @param int $field_id
  * @param array $field_submit
  * @param array $form_data
  */
 public function format($field_id, $field_submit, $form_data)
 {
     if (is_array($field_submit)) {
         $field_submit = array_filter($field_submit);
         $field_submit = implode("\r\n", $field_submit);
     }
     $name = !empty($form_data['fields'][$field_id]['label']) ? sanitize_text_field($form_data['fields'][$field_id]['label']) : '';
     // Hack to keep line breaks
     $value = implode("\n", array_map('sanitize_text_field', explode("\n", $field_submit)));
     wpforms()->process->fields[$field_id] = array('name' => $name, 'value' => $value, 'id' => absint($field_id), 'type' => $this->type);
 }
 /**
  * Redirects user to a page or URL specified in the form confirmation settings.
  *
  * @since 1.0.0
  * @param array $form_data
  * @param string $hash
  */
 public function entry_confirmation_redirect($form_data = '', $hash = '')
 {
     $url = '';
     if (!empty($hash)) {
         $form_id = $this->validate_return_hash($hash);
         if (!$form_id) {
             return;
         }
         // Get form
         $form_data = wpforms()->form->get($form_id, array('content_only' => true));
     }
     // Redirect if needed, to either a page or URL, after form processing
     if (!empty($form_data['settings']['confirmation_type']) && $form_data['settings']['confirmation_type'] != 'message') {
         if ($form_data['settings']['confirmation_type'] == 'redirect') {
             $url = apply_filters('wpforms_process_smart_tags', $form_data['settings']['confirmation_redirect'], $form_data, $this->fields, $this->entry_id);
         }
         if ($form_data['settings']['confirmation_type'] == 'page') {
             $url = get_permalink((int) $form_data['settings']['confirmation_page']);
         }
     }
     if (!empty($form_data['id'])) {
         $form_id = $form_data['id'];
     } else {
         return;
     }
     if (!empty($url)) {
         $url = apply_filters('wpforms_process_redirect_url', $url, $form_id);
         wp_redirect(esc_url_raw($url));
         do_action('wpforms_process_redirect', $form_id);
         do_action("wpforms_process_redirect_{$form_id}", $form_id);
         exit;
     }
 }
 /**
  * reCAPTCHA output if configured.
  *
  * @since 1.0.0
  * @param array $form_data
  * @param object $form
  * @param mixed $title
  * @param mixed $description
  */
 public function recaptcha($form_data, $form, $title, $description, $errors)
 {
     // Check that recaptcha is configured in the settings
     $site_key = wpforms_setting('recaptcha-site-key', '');
     $secret_key = wpforms_setting('recaptcha-secret-key', '');
     if (empty($site_key) || empty($secret_key)) {
         return;
     }
     // Check that the recaptcha is configured for the specific form
     if (!isset($form_data['settings']['recaptcha']) || '1' != $form_data['settings']['recaptcha']) {
         return;
     }
     $d = '';
     $datas = apply_filters('wpforms_frontend_recaptcha', array('sitekey' => $site_key), $form_data);
     echo '<div class="wpforms-recaptcha-container">';
     foreach ($datas as $key => $data) {
         $d .= 'data-' . $key . '="' . esc_attr($data) . '" ';
     }
     echo '<div class="g-recaptcha" ' . $d . '></div>';
     if (!empty(wpforms()->process->errors[$form_data['id']]['recaptcha'])) {
         echo '<label id="wpforms-field_recaptcah-error" class="wpforms-error">' . esc_html(wpforms()->process->errors[$form_data['id']]['recaptcha']) . '</label>';
     }
     echo '</div>';
 }
Example #17
0
/**
 * Log helper.
 *
 * @since 1.0.0
 * @param string $title
 * @param string $message
 * @param array $args
 */
function wpforms_log($title = '', $message = '', $args = array())
{
    // Require log title
    if (empty($title)) {
        return;
    }
    // Force logging everything when in debug mode
    if (!wpforms_debug()) {
        /**
         * Compare error levels to determine if we should log.
         * Current supported levels:
         * - Errors (error)
         * - Spam (spam)
         * - Entries (entry)
         * - Payments (payment)
         * - Providers (provider)
         * - Conditional Logic (conditional_logic)
         */
        $type = !empty($args['type']) ? (array) $args['type'] : array('error');
        $levels = get_option('wpforms_logging', array());
        $lvls = array_intersect($type, $levels);
        if (empty($lvls)) {
            return;
        }
    }
    // Meta
    if (!empty($args['form_id'])) {
        $meta = array('form' => absint($args['form_id']));
    } elseif (!empty($args['meta'])) {
        $meta = $args['meta'];
    } else {
        $meta = '';
    }
    // Parent
    $parent = !empty($args['parent']) ? $args['parent'] : 0;
    // Make arrays and objects look nice
    if (is_array($message) || is_object($message)) {
        $message = '<pre>' . print_r($message, true) . '</pre>';
    }
    // Create log entry
    wpforms()->logs->add($title, $message, $parent, $parent, $meta);
}
 /**
  * Tweak the page content for form preview page requests.
  *
  * @since 1.1.9
  * @param array $posts
  * @param object $query
  * @return array
  */
 public function form_preview_query($posts, $query)
 {
     // One last cap check, just for fun.
     if (!is_user_logged_in() || !current_user_can(apply_filters('wpforms_manage_cap', 'manage_options'))) {
         return $posts;
     }
     // Only target main query
     if (!$query->is_main_query()) {
         return $posts;
     }
     // If our queried object ID does not match the preview page ID, return early.
     $preview_id = absint(get_option('wpforms_preview_page'));
     $queried = $query->get_queried_object_id();
     if ($queried && $queried != $preview_id && isset($query->query_vars['page_id']) && $preview_id != $query->query_vars['page_id']) {
         return $posts;
     }
     // Get the form details
     $form = wpforms()->form->get(absint($_GET['form_id']), array('content_only' => true));
     if (!$form || empty($form)) {
         return $posts;
     }
     // Customize the page content
     $title = sanitize_text_field($form['settings']['form_title']);
     $shortcode = '[wpforms id="' . absint($form['id']) . '"]';
     $content = __('This is a preview of your form. This page not publically accessible.', 'wpforms');
     if (!empty($_GET['new_window'])) {
         $content .= ' <a href="javascript:window.close();">' . __('Close this window', 'wpforms') . '.</a>';
     }
     $posts[0]->post_title = $title . __(' Preview', 'wpforms');
     $posts[0]->post_content = $content . $shortcode;
     $posts[0]->post_status = 'public';
     return $posts;
 }