field_table_name = $wpdb->prefix . 'visual_form_builder_fields'; $this->form_table_name = $wpdb->prefix . 'visual_form_builder_forms'; $this->entries_table_name = $wpdb->prefix . 'visual_form_builder_entries'; /* Make sure we are in the admin before proceeding. */ if ( is_admin() ) { /* Build options and settings pages. */ add_action( 'admin_menu', array( &$this, 'add_admin' ) ); add_action( 'admin_menu', array( &$this, 'save' ) ); add_action( 'wp_ajax_visual_form_builder_process_sort', array( &$this, 'visual_form_builder_process_sort_callback' ) ); add_action( 'admin_init', array( &$this, 'add_visual_form_builder_contextual_help' ) ); add_action( 'admin_init', array( &$this, 'export_entries' ) ); /* Load the includes files */ add_action( 'plugins_loaded', array( &$this, 'includes' ) ); /* Adds a Screen Options tab to the Entries screen */ add_action( 'admin_init', array( &$this, 'save_screen_options' ) ); add_filter( 'screen_settings', array( &$this, 'add_visual_form_builder_screen_options' ) ); /* Adds a Settings link to the Plugins page */ add_filter( 'plugin_action_links', array( &$this, 'visual_form_builder_plugin_action_links' ), 10, 2 ); /* Load the nav-menu CSS if we're on our plugin page */ if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'visual-form-builder' ) wp_admin_css( 'nav-menu' ); /* Add a database version to help with upgrades and run SQL install */ if ( !get_option( 'vfb_db_version' ) ) { update_option( 'vfb_db_version', $this->vfb_db_version ); $this->install_db(); } /* If database version doesn't match, update and run SQL install */ if ( get_option( 'vfb_db_version' ) != $this->vfb_db_version ) { update_option( 'vfb_db_version', $this->vfb_db_version ); $this->install_db(); } /* Load the jQuery and CSS we need if we're on our plugin page */ add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_scripts' ) ); add_action( 'load-settings_page_visual-form-builder', array( &$this, 'form_admin_css' ) ); } add_shortcode( 'vfb', array( &$this, 'form_code' ) ); add_action( 'init', array( &$this, 'email' ), 10 ); add_action( 'init', array( &$this, 'confirmation' ), 12 ); /* Add jQuery and CSS to the front-end */ add_action( 'wp_head', array( &$this, 'form_css' ) ); add_action( 'template_redirect', array( &$this, 'form_validation' ) ); } /** * Adds extra include files * * @since 1.2 */ public function includes(){ /* Load the Entries List class */ require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-list.php' ); /* Load the Entries Details class */ require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'class-entries-detail.php' ); } /** * Register contextual help. This is for the Help tab dropdown * * @since 1.0 */ public function add_visual_form_builder_contextual_help(){ $text = "

Getting Started

Form Item Configuration

Validation

Confirmation

Tips

"; add_contextual_help( 'settings_page_visual-form-builder', $text ); } /** * Adds the Screen Options tab to the Entries screen * * @since 1.2 */ public function add_visual_form_builder_screen_options($current){ global $current_screen; $options = get_option( 'visual-form-builder-screen-options' ); if ( $current_screen->id == 'settings_page_visual-form-builder' && isset( $_REQUEST['view'] ) && in_array( $_REQUEST['view'], array( 'entries' ) ) ){ $current = '
Show on screen
'; } return $current; } /** * Saves the Screen Options * * @since 1.2 */ public function save_screen_options(){ $options = get_option( 'visual-form-builder-screen-options' ); /* Default is 20 per page */ $defaults = array( 'per_page' => 20 ); /* If the option doesn't exist, add it with defaults */ if ( !$options ) update_option( 'visual-form-builder-screen-options', $defaults ); /* If the user has saved the Screen Options, update */ if ( isset( $_REQUEST['visual-form-builder-screen-options-apply'] ) && in_array( $_REQUEST['visual-form-builder-screen-options-apply'], array( 'Apply', 'apply' ) ) ) { $per_page = absint( $_REQUEST['visual-form-builder-screen-options']['per_page'] ); $updated_options = array( 'per_page' => $per_page ); update_option( 'visual-form-builder-screen-options', $updated_options ); } } /** * Runs the export_entries function in the class-entries-list.php file * * @since 1.4 */ public function export_entries() { $entries = new VisualFormBuilder_Entries_List(); /* If exporting all, don't pass the IDs */ if ( 'export-all' === $entries->current_action() ) $entries->export_entries(); /* If exporting selected, pick up the ID array and pass them */ elseif ( 'export-selected' === $entries->current_action() ) { $entry_id = ( is_array( $_REQUEST['entry'] ) ) ? $_REQUEST['entry'] : array( $_REQUEST['entry'] ); $entries->export_entries( $entry_id ); } } /** * Install database tables * * @since 1.0 */ static function install_db() { global $wpdb; $field_table_name = $wpdb->prefix . 'visual_form_builder_fields'; $form_table_name = $wpdb->prefix . 'visual_form_builder_forms'; $entries_table_name = $wpdb->prefix . 'visual_form_builder_entries'; /* Explicitly set the character set and collation when creating the tables */ $charset = ( defined( 'DB_CHARSET' && '' !== DB_CHARSET ) ) ? DB_CHARSET : 'utf8'; $collate = ( defined( 'DB_COLLATE' && '' !== DB_COLLATE ) ) ? DB_COLLATE : 'utf8_general_ci'; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); $field_sql = "CREATE TABLE $field_table_name ( field_id BIGINT(20) NOT NULL AUTO_INCREMENT, form_id BIGINT(20) NOT NULL, field_key VARCHAR(255) NOT NULL, field_type VARCHAR(25) NOT NULL, field_options TEXT, field_description TEXT, field_name VARCHAR(255) NOT NULL, field_sequence TINYINT DEFAULT '0', field_validation VARCHAR(25), field_required VARCHAR(25), field_size VARCHAR(25), UNIQUE KEY (field_id) ) DEFAULT CHARACTER SET $charset COLLATE $collate;"; $form_sql = "CREATE TABLE $form_table_name ( form_id BIGINT(20) NOT NULL AUTO_INCREMENT, form_key TINYTEXT NOT NULL, form_title TEXT NOT NULL, form_email_subject TEXT, form_email_to VARCHAR(255), form_email_from VARCHAR(255), form_email_from_name VARCHAR(255), form_email_from_override VARCHAR(255), form_email_from_name_override VARCHAR(255), form_success_type VARCHAR(25) DEFAULT 'text', form_success_message TEXT, UNIQUE KEY (form_id) ) DEFAULT CHARACTER SET $charset COLLATE $collate;"; $entries_sql = "CREATE TABLE $entries_table_name ( entries_id BIGINT(20) NOT NULL AUTO_INCREMENT, form_id BIGINT(20) NOT NULL, data TEXT NOT NULL, subject TEXT, sender_name VARCHAR(255), sender_email VARCHAR(25), emails_to VARCHAR(255), date_submitted VARCHAR(25), ip_address VARCHAR(25), UNIQUE KEY (entries_id) ) DEFAULT CHARACTER SET $charset COLLATE $collate;"; /* Create or Update database tables */ dbDelta( $field_sql ); dbDelta( $form_sql ); dbDelta( $entries_sql ); } /** * Queue plugin CSS for admin styles * * @since 1.0 */ public function form_admin_css(){ wp_enqueue_style( 'visual-form-builder-style', plugins_url( 'visual-form-builder' ) . '/css/visual-form-builder-admin.css' ); } /** * Queue plugin scripts for sorting form fields * * @since 1.0 */ public function form_admin_scripts() { wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'jquery-form-validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js', array( 'jquery' ), '', true ); wp_enqueue_script( 'form-elements-add', plugins_url( 'visual-form-builder' ) . '/js/visual-form-builder.js' , array( 'jquery', 'jquery-form-validation' ), '', true ); } /** * Queue form validation scripts * * @since 1.0 */ public function form_validation(){ wp_enqueue_script( 'jquery-form-validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js', array( 'jquery' ), '', true ); wp_enqueue_script( 'jquery-ui-core ', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js', array( 'jquery' ), '', true ); wp_enqueue_script( 'visual-form-builder-validation', plugins_url( 'visual-form-builder' ) . '/js/visual-form-builder-validate.js' , array( 'jquery', 'jquery-form-validation' ), '', true ); wp_enqueue_script( 'visual-form-builder-quicktags', plugins_url( 'visual-form-builder' ) . '/js/js_quicktags.js' ); } /** * Add form CSS to wp_head * * @since 1.0 */ public function form_css(){ echo apply_filters( 'visual-form-builder-css', '' ); echo apply_filters( 'vfb-date-picker-css', '' ); } /** * Add Settings link to Plugins page * * @since 1.8 * @return $links array Links to add to plugin name */ public function visual_form_builder_plugin_action_links($links, $file){ if ( $file == plugin_basename(__FILE__) ) $links[] = ''.__('Settings').''; return $links; } /** * Add options page to Settings menu * * * @since 1.0 * @uses add_options_page() Creates a menu item under the Settings menu. */ public function add_admin() { add_options_page( __('Visual Form Builder', 'visual-form-builder'), __('Visual Form Builder', 'visual-form-builder'), 'create_users', 'visual-form-builder', array( &$this, 'admin' ) ); } /** * Actions to save, update, and delete forms/form fields * * * @since 1.0 */ public function save() { global $wpdb; if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'visual-form-builder' && isset( $_REQUEST['action'] ) ) { switch ( $_REQUEST['action'] ) { case 'create_form' : $form_id = absint( $_REQUEST['form_id'] ); $form_key = sanitize_title( $_REQUEST['form_title'] ); $form_title = esc_html( $_REQUEST['form_title'] ); check_admin_referer( 'create_form-' . $form_id ); $newdata = array( 'form_key' => $form_key, 'form_title' => $form_title ); /* Set message to display */ $this->message = '

The ' . $form_title . ' form has been created.

'; /* Create the form */ $wpdb->insert( $this->form_table_name, $newdata ); /* Get form ID to add our first field */ $new_form_selected = $wpdb->insert_id; /* Setup the initial fieldset */ $initial_fieldset = array( 'form_id' => $wpdb->insert_id, 'field_key' => 'fieldset', 'field_type' => 'fieldset', 'field_name' => 'Fieldset', 'field_sequence' => 0 ); /* Add the first fieldset to get things started */ $wpdb->insert( $this->field_table_name, $initial_fieldset ); /* Redirect to keep the URL clean (use AJAX in the future?) */ wp_redirect( 'options-general.php?page=visual-form-builder&form=' . $new_form_selected ); exit(); break; case 'update_form' : $form_id = absint( $_REQUEST['form_id'] ); $form_key = sanitize_title( $_REQUEST['form_title'] ); $form_title = esc_html( $_REQUEST['form_title'] ); $form_subject = esc_html( $_REQUEST['form_email_subject'] ); $form_to = serialize( esc_html( $_REQUEST['form_email_to'] ) ); $form_from = esc_html( $_REQUEST['form_email_from'] ); $form_from_name = esc_html( $_REQUEST['form_email_from_name'] ); $form_from_override = esc_html( $_REQUEST['form_email_from_override'] ); $form_from_name_override = esc_html( $_REQUEST['form_email_from_name_override'] ); $form_success_type = esc_html( $_REQUEST['form_success_type'] ); /* Add confirmation based on which type was selected */ switch ( $form_success_type ) { case 'text' : $form_success_message = wp_richedit_pre( $_REQUEST['form_success_message_text'] ); break; case 'page' : $form_success_message = esc_html( $_REQUEST['form_success_message_page'] ); break; case 'redirect' : $form_success_message = esc_html( $_REQUEST['form_success_message_redirect'] ); break; } check_admin_referer( 'update_form-' . $form_id ); $newdata = array( 'form_key' => $form_key, 'form_title' => $form_title, 'form_email_subject' => $form_subject, 'form_email_to' => $form_to, 'form_email_from' => $form_from, 'form_email_from_name' => $form_from_name, 'form_email_from_override' => $form_from_override, 'form_email_from_name_override' => $form_from_name_override, 'form_success_type' => $form_success_type, 'form_success_message' => $form_success_message ); $where = array( 'form_id' => $form_id ); /* Update form details */ $wpdb->update( $this->form_table_name, $newdata, $where ); /* Loop through each field and update all at once */ if ( !empty( $_REQUEST['field_id'] ) ) { foreach ( $_REQUEST['field_id'] as $id ) { $field_name = ( isset( $_REQUEST['field_name-' . $id] ) ) ? esc_html( $_REQUEST['field_name-' . $id] ) : ''; $field_key = sanitize_title( $field_name ); $field_desc = ( isset( $_REQUEST['field_description-' . $id] ) ) ? esc_html( $_REQUEST['field_description-' . $id] ) : ''; $field_options = ( isset( $_REQUEST['field_options-' . $id] ) ) ? serialize( esc_html( $_REQUEST['field_options-' . $id] ) ) : ''; $field_validation = ( isset( $_REQUEST['field_validation-' . $id] ) ) ? esc_html( $_REQUEST['field_validation-' . $id] ) : ''; $field_required = ( isset( $_REQUEST['field_required-' . $id] ) ) ? esc_html( $_REQUEST['field_required-' . $id] ) : ''; $field_size = ( isset( $_REQUEST['field_size-' . $id] ) ) ? esc_html( $_REQUEST['field_size-' . $id] ) : ''; $field_data = array( 'field_key' => $field_key, 'field_name' => $field_name, 'field_description' => $field_desc, 'field_options' => $field_options, 'field_validation' => $field_validation, 'field_required' => $field_required, 'field_size' => $field_size ); $where = array( 'form_id' => $_REQUEST['form_id'], 'field_id' => $id ); /* Update all fields */ $wpdb->update( $this->field_table_name, $field_data, $where ); } } /* Set message to display */ $this->message = '

The ' . $form_title . ' form has been updated.

'; break; case 'delete_form' : $id = absint( $_REQUEST['form'] ); check_admin_referer( 'delete-form-' . $id ); /* Delete form and all fields */ $wpdb->query( $wpdb->prepare( "DELETE FROM $this->form_table_name WHERE form_id = %d", $id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE form_id = %d", $id ) ); /* Set message to display */ $this->message = '

This form has been deleted.

'; /* Redirect to keep the URL clean (use AJAX in the future?) */ wp_redirect( 'options-general.php?page=visual-form-builder' ); exit(); break; case 'delete_field' : $form_id = absint( $_REQUEST['form'] ); $field_id = absint( $_REQUEST['field'] ); check_admin_referer( 'delete-field-' . $form_id ); /* Delete the field */ $wpdb->query( $wpdb->prepare( "DELETE FROM $this->field_table_name WHERE field_id = %d", $field_id ) ); /* Set message to display */ $this->message = '

The field has been deleted.

'; /* Redirect to keep the URL clean (use AJAX in the future?) */ wp_redirect( 'options-general.php?page=visual-form-builder&form=' . $form_id ); exit(); break; case 'create_field' : $form_id = absint( $_REQUEST['form_id'] ); $field_key = sanitize_title( $_REQUEST['field_name'] ); $field_name = esc_html( $_REQUEST['field_type'] ); $field_type = strtolower( sanitize_title( $_REQUEST['field_type'] ) ); /* Set defaults for validation */ switch ( $field_type ) { case 'email' : case 'url' : case 'phone' : $field_validation = $field_type; break; case 'currency' : $field_validation = 'number'; break; case 'number' : $field_validation = 'digits'; break; case 'time' : $field_validation = 'time-12'; break; } check_admin_referer( 'create-field-' . $form_id ); /* Get the last row's sequence */ $sequence_last_row = $wpdb->get_row( "SELECT field_sequence FROM $this->field_table_name WHERE form_id = $form_id ORDER BY field_sequence DESC LIMIT 1" ); /* If it's not the first for this form, add 1 */ $field_sequence = ( !empty( $sequence_last_row ) ) ? $sequence_last_row->field_sequence + 1 : 0; $newdata = array( 'form_id' => absint( $_REQUEST['form_id'] ), 'field_key' => $field_key, 'field_name' => $field_name, 'field_type' => $field_type, 'field_sequence' => $field_sequence, 'field_validation' => $field_validation ); /* Create the field */ $wpdb->insert( $this->field_table_name, $newdata ); break; } } } /** * The jQuery field sorting callback * * @since 1.0 */ public function visual_form_builder_process_sort_callback() { global $wpdb; /* Get the order of the fields as make an array */ $order = explode( ',', $_REQUEST['order'] ); foreach ( $order as $k => $v ) { /* Find the digits from each field */ preg_match( '/(\d+)/', $v, $matches ); /* Update each field with it's new sequence */ $wpdb->update( $this->field_table_name, array( 'field_sequence' => $k ), array( 'field_id' => $matches[0] ) ); } die(1); } /** * Builds the options settings page * * @since 1.0 */ public function admin() { global $wpdb; /* Set variables depending on which tab is selected */ $form_nav_selected_id = ( isset( $_REQUEST['form'] ) ) ? $_REQUEST['form'] : '0'; $action = ( isset( $_REQUEST['form'] ) && $_REQUEST['form'] !== '0' ) ? 'update_form' : 'create_form'; $details_meta = ( isset( $_REQUEST['details'] ) ) ? $_REQUEST['details'] : 'email'; /* Query to get all forms */ $order = sanitize_sql_orderby( 'form_id DESC' ); $query = "SELECT * FROM $this->form_table_name ORDER BY $order"; /* Build our forms as an object */ $forms = $wpdb->get_results( $query ); /* Loop through each form and assign a form id, if any */ foreach ( $forms as $form ) { $form_id = ( $form_nav_selected_id == $form->form_id ) ? $form->form_id : ''; /* If we are on a form, set the form name for the shortcode box */ if ( $form_nav_selected_id == $form->form_id ) $form_name = stripslashes( $form->form_title ); } ?>

entries_detail(); else : $entries_list->prepare_items(); ?>
display(); ?>
message ) ) ? $this->message : ''; ?>
form_table_name WHERE form_id = $form_id ORDER BY $order"; $forms = $wpdb->get_results( $query ); foreach ( $forms as $form ) { /* If text, return output and format the HTML for display */ if ( 'text' == $form->form_success_type ) return stripslashes( html_entity_decode( wp_kses_stripslashes( $form->form_success_message ) ) ); /* If page, redirect to the permalink */ elseif ( 'page' == $form->form_success_type ) { $page = get_permalink( $form->form_success_message ); wp_redirect( $page ); exit(); } /* If redirect, redirect to the URL */ elseif ( 'redirect' == $form->form_success_type ) { wp_redirect( $form->form_success_message ); exit(); } } } } /** * Output form via shortcode * * @since 1.0 */ public function form_code( $atts ) { global $wpdb; /* Extract shortcode attributes, set defaults */ extract( shortcode_atts( array( 'id' => '' ), $atts ) ); /* Get form id. Allows use of [vfb id=1] or [vfb 1] */ $form_id = ( isset( $id ) && !empty( $id ) ) ? $id : $atts[0]; $open_fieldset = false; /* If form is submitted, show success message, otherwise the form */ if ( isset( $_REQUEST['visual-form-builder-submit'] ) && in_array( $_REQUEST['visual-form-builder-submit'], array( 'Submit', 'submit' ) ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'visual-form-builder-nonce' ) ) { $output = $this->confirmation(); } else { /* Get forms */ $order = sanitize_sql_orderby( 'form_id DESC' ); $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order"; $forms = $wpdb->get_results( $query ); /* Get fields */ $order_fields = sanitize_sql_orderby( 'field_sequence ASC' ); $query_fields = "SELECT * FROM $this->field_table_name WHERE form_id = $form_id ORDER BY $order_fields"; $fields = $wpdb->get_results( $query_fields ); foreach ( $forms as $form ) : $output = '
'; $output .= wp_nonce_field( 'visual-form-builder-nonce', '_wpnonce', false, false ); foreach ( $fields as $field ) { if ( $field->field_type == 'fieldset' ) { /* Close each fieldset */ if ( $open_fieldset == true ) $output .= '
'; $output .= '

' . stripslashes( $field->field_name ) . '


'; /* Output our security test */ $output .= '

Verification

'; endforeach; } return $output; } /** * Handle emailing the content * * @since 1.0 * @uses wp_mail() E-mails a message */ public function email() { global $wpdb, $post; /* Security check before moving any further */ if ( isset( $_REQUEST['visual-form-builder-submit'] ) && $_REQUEST['visual-form-builder-submit'] == 'Submit' && $_REQUEST['vfb-spam'] == '' && is_numeric( $_REQUEST['vfb-secret'] ) && strlen( $_REQUEST['vfb-secret'] ) == 2 ) : $nonce = $_REQUEST['_wpnonce']; /* Security check to verify the nonce */ if ( ! wp_verify_nonce( $nonce, 'visual-form-builder-nonce' ) ) die(__('Security check')); /* Set submitted action to display success message */ $this->submitted = true; /* Tells us which form to get from the database */ $form_id = absint( $_REQUEST['form_id'] ); /* Query to get all forms */ $order = sanitize_sql_orderby( 'form_id DESC' ); $query = "SELECT * FROM $this->form_table_name WHERE form_id = $form_id ORDER BY $order"; /* Build our forms as an object */ $forms = $wpdb->get_results( $query ); /* Get sender and email details */ foreach ( $forms as $form ) { $form_title = $form->form_title; $form_subject = $form->form_email_subject; $form_to = explode( ',', unserialize( $form->form_email_to ) ); $form_from = $form->form_email_from; $form_from_name = $form->form_email_from_name; } /* Sender name override query */ $sender_query = "SELECT fields.field_key FROM $this->form_table_name AS forms LEFT JOIN $this->field_table_name AS fields ON forms.form_email_from_name_override = fields.field_id WHERE forms.form_id = $form_id"; $senders = $wpdb->get_results( $sender_query ); /* Sender email override query */ $email_query = "SELECT fields.field_key FROM $this->form_table_name AS forms LEFT JOIN $this->field_table_name AS fields ON forms.form_email_from_override = fields.field_id WHERE forms.form_id = $form_id"; $emails = $wpdb->get_results( $email_query ); /* Loop through name results and assign sender name to override, if needed */ foreach( $senders as $sender ) { if ( !empty( $sender->field_key ) ) $form_from_name = $_POST[ 'vfb-' . $sender->field_key ]; } /* Loop through email results and assign sender email to override, if needed */ foreach ( $emails as $email ) { if ( !empty( $email->field_key ) ) $form_from = $_POST[ 'vfb-' . $email->field_key ]; } /* Prepare the beginning of the content */ $message = ''; /* Loop through each form field and build the body of the message */ foreach ( $_POST as $key => $value ) { /* Remove prefix, dashes and lowercase */ $key = str_replace( 'vfb-', '', $key ); $key = strtolower( str_replace( '-', ' ', $key ) ); /* If time field, build proper output */ if ( is_array( $value ) && array_key_exists( 'hour', $value ) && array_key_exists( 'min', $value ) ) $value = ( array_key_exists( 'ampm', $value ) ) ? substr_replace( implode( ':', $value ), ' ', 5, 1 ) : implode( ':', $value ); /* If multiple values, build the list */ elseif ( is_array( $value ) ) $value = implode( ', ', $value ); /* Lastly, handle single values */ else $value = esc_html( $value ); /* Hide fields that aren't necessary to the body of the message */ if ( !in_array( $key, array( 'spam', 'secret', 'visual form builder submit', '_wpnonce', 'form_id' ) ) ) { $message .= ''; $fields[ $key ] = $value; } } /* Prepare the attachments */ if ( isset( $_FILES ) ) { foreach ( $_FILES as $k => $v ) { if ( $v['size'] > 0 ) { /* Options array for the wp_handle_upload function. 'test_upload' => false */ $upload_overrides = array( 'test_form' => false ); /* We need to include the file that runs the wp_handle_upload function */ require_once( ABSPATH . 'wp-admin/includes/file.php' ); /* Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array */ $uploaded_file = wp_handle_upload( $v, $upload_overrides ); /* If the wp_handle_upload call returned a local path for the image */ if ( isset( $uploaded_file['file'] ) ) { $attachments[$k] = $uploaded_file['file']; $key = str_replace( 'vfb-', '', $k ); $key = strtolower( str_replace( '-', ' ', $key ) ); $fields[$key] = $uploaded_file['url']; $message .= ''; } } } } /* Setup our entries data */ $entry = array( 'form_id' => $form_id, 'data' => serialize( $fields ), 'subject' => $form_subject, 'sender_name' => $form_from_name, 'sender_email' => $form_from, 'emails_to' => serialize( $form_to ), 'date_submitted' => date_i18n( 'Y-m-d G:i:s' ), 'ip_address' => $_SERVER['REMOTE_ADDR'] ); /* Insert this data into the entries table */ $wpdb->insert( $this->entries_table_name, $entry ); /* Close out the content */ $message .= '
' . ucwords( $key ) . ': ' . $value . '
' . ucwords( $key ) . ': ' . $uploaded_file['url'] . '
'; /* Set headers to send an HTML email */ $headers = "MIME-Version: 1.0\n". "From: " . $form_from_name . " <" . $form_from . ">\n" . "Content-Type: text/html; charset=\"" . get_settings( 'blog_charset' ) . "\"\n"; /* Send the mail */ foreach ( $form_to as $email ) { $mail_sent = wp_mail( $email, esc_html( $form_subject ), $message, $headers, $attachments ); } elseif ( isset( $_REQUEST['visual-form-builder-submit'] ) ) : /* If any of the security checks fail, provide some user feedback */ if ( $_REQUEST['vfb-spam'] !== '' || !is_numeric( $_REQUEST['vfb-secret'] ) || strlen( $_REQUEST['vfb-secret'] ) !== 2 ) wp_die( 'Ooops! Looks like you have failed the security validation for this form. Please go back and try again.' ); endif; } } /* On plugin activation, install the databases and add/update the DB version */ register_activation_hook( __FILE__, array( 'Visual_Form_Builder', 'install_db' ) ); ?>