function cf7bs_get_form_property($property, $form_id = 0) { global $current_form_id, $current_form_properties; if ($form_id == 0) { if (is_callable(array('WPCF7_ContactForm', 'get_current'))) { $current_form = WPCF7_ContactForm::get_current(); if (is_a($current_form, 'WPCF7_ContactForm') && is_callable(array($current_form, 'id'))) { $form_id = $current_form->id(); } } } if ($form_id == 0) { return false; } if ($current_form_id != $form_id) { $current_form_id = $form_id; $properties = cf7bs_get_default_form_properties(); if (is_a($current_form, 'WPCF7_ContactForm') && is_callable(array($current_form, 'additional_setting'))) { foreach ($properties as $key => &$value) { $setting = $current_form->additional_setting($key); if (isset($setting[0])) { $value = $setting[0]; } } unset($key); unset($value); } $current_form_properties = apply_filters('cf7bs_form_' . $form_id . '_properties', $properties); } if (isset($current_form_properties[$property])) { return $current_form_properties[$property]; } return false; }
function wpcf7_scan_form_tags($cond = null) { $contact_form = WPCF7_ContactForm::get_current(); if ($contact_form) { return $contact_form->scan_form_tags($cond); } return array(); }
function send_mail_for_form($cf7_posted_data) { $wpcf7 = WPCF7_ContactForm::get_current(); if ($wpcf7->id() == 596) { $wpcf7->skip_mail = false; } return $cf7_posted_data; }
/** * Takes the body of the mail, evaluates it and sets it back. * * @param [Object] The $WPCF7_ContactForm object. * @return void */ public function prepare_body($cf7) { // Get the object. $wpcf = WPCF7_ContactForm::get_current(); // Now we get the mail body and evaluate it. $mail = $wpcf->prop('mail'); $mail['body'] = $this->evaluate($mail['body']); // Set the new body. $wpcf->set_properties(array('mail' => $mail)); return $wpcf; }
function wpcf7gpg_encrypt_mail($wpcf7gpg_mailcomponents) { $wpcf7gpg_contactform = WPCF7_ContactForm::get_current(); $wpcf7gpg_publickey = $wpcf7gpg_contactform->additional_setting('wpcf7gpg_publickey'); if ($wpcf7gpg_publickey) { // A public key has been defined (element 0 in array), sanitize as required by GPG library $wpcf7gpg_publickey = str_replace('|', "\n", $wpcf7gpg_publickey[0]); // Replace body of mail with encrypted body text $wpcf7gpg_mailcomponents['body'] = wpcf7gpg_encrypt_text($wpcf7gpg_mailcomponents['body'], $wpcf7gpg_publickey); } else { // No public key has been defined, we can skip encryption } return $wpcf7gpg_mailcomponents; }
public function dynamic_shortcode_handler($tag) { // generates html for form field if (!is_array($tag)) { return ''; } $name = $tag['name']; if (empty($name)) { return ''; } $wpcf7_contact_form = WPCF7_ContactForm::get_current(); // most attributes not really needed, not included $name_att = $name; $filter = ''; $filter_args = array(); $filter_string = ''; $values = $tag['values']; if (isset($values[0])) { $filter_string = $values[0]; } //echo $filter_string; if ($filter_string != '') { $filter_parts = explode(' ', $filter_string); $filter = trim($filter_parts[0]); $count = count($filter_parts); for ($i = 1; $i < $count; $i++) { if (trim($filter_parts[$i]) != '') { $arg_parts = explode('=', $filter_parts[$i]); if (count($arg_parts) == 2) { $filter_args[trim($arg_parts[0])] = trim($arg_parts[1], ' \''); } else { $filter_args[] = trim($arg_parts[0], ' \''); } } // end if filter part } // end for } // end if filter string $value = ''; if ($filter != '') { $value = apply_filters($filter, $value, $filter_args); } $atts = ' name="' . $name . '" value="' . $value . '" autocomplete="off"'; $html = '<input type="hidden"' . $atts . ' />'; return $html; }
function maybe_reset_autop($form) { $form_instance = WPCF7_ContactForm::get_current(); $manager = WPCF7_ShortcodeManager::get_instance(); $form_meta = get_post_meta($form_instance->id(), '_form', true); $form = $manager->do_shortcode($form_meta); $form_instance->set_properties(array('form' => $form)); return $form; }
function cf7bs_get_current_form_id() { if (is_callable(array('WPCF7_ContactForm', 'get_current'))) { $current_form = WPCF7_ContactForm::get_current(); if (is_a($current_form, 'WPCF7_ContactForm') && is_callable(array($current_form, 'id'))) { return $current_form->id(); } } return false; }
function wpcf7c_ajax_json_echo_step1($items, $result) { global $wpcf7_confflag; $flag = false; if (WPCF7_VERSION == '3.9' || WPCF7_VERSION == '3.9.1') { $flag = $wpcf7_confflag; } else { if (WPCF7_VERSION >= "3.9.2") { if ('mail_sent' == $result['status']) { $flag = true; } } else { $flag = $result['mail_sent']; } } if ($flag) { if (!isset($items["onSubmit"]) || $items["onSubmit"] == null) { $items["onSubmit"] = array("wpcf7c_step1('" . $_POST['_wpcf7_unit_tag'] . "');"); } else { $items["onSubmit"][] = "wpcf7c_step1('" . $_POST['_wpcf7_unit_tag'] . "');"; } // オプションによる追加チェック $form = WPCF7_ContactForm::get_current(); $on_confirm = $form->additional_setting('on_confirm', false); if (!empty($on_confirm)) { foreach ($on_confirm as $key => $on_confirm_func) { $items["onSubmit"][] = wpcf7_strip_quote($on_confirm_func); } } $items["message"] = ""; $items["mailSent"] = false; unset($items['captcha']); } else { // フィルタ指定があればエラー時にアンカーまでスクロールさせる $result = false; if (apply_filters('wpcf7c_input_error_scroll', $result)) { if (!isset($items["onSubmit"]) || $items["onSubmit"] == null) { $items["onSubmit"] = array("wpcf7c_scroll('" . $_POST['_wpcf7_unit_tag'] . "');"); } else { $items["onSubmit"][] = "wpcf7c_scroll('" . $_POST['_wpcf7_unit_tag'] . "');"; } } } return $items; }
/** * contact form submision * @param object $WPCF7_ContactForm: current contact form object */ public function _hw_wpcf7_do_something($WPCF7_ContactForm) { /* Use WPCF7_Submission object's get_posted_data() method to get it. */ $properties = $WPCF7_ContactForm->get_properties(); //get google form ID of this form $gformID = $properties['hw_gformID']; // get the contact form object $wpcf7 = WPCF7_ContactForm::get_current(); if (isset($properties['enable_email_by_gapp']) && $properties['enable_email_by_gapp']) { // do not send the email $wpcf7->skip_mail = true; //turn off default send mail by wpcf7, use google drive instead } $atts = $WPCF7_ContactForm->form_scan_shortcode(); $fields_title = array(); //fields title $data = array(); //fields value //submission data $submission = WPCF7_Submission::get_instance(); if ($submission) { //get storage service $storage_hook = $WPCF7_ContactForm->prop('hwcf_data_hook'); //get posted form data $posted_data = $submission->get_posted_data(); //parse email template into user data $mail_temp = $WPCF7_ContactForm->prop('mail'); $result = wpcf7_mail_replace_tags($mail_temp); $admin_email = !empty($mail_temp['recipient']) ? $mail_temp['recipient'] : get_option('admin_email'); //set special field value $special_fields_value['sendEmail'] = $result['body']; $special_fields_value['admin_email'] = $admin_email; #admin email $special_fields_value['website'] = hw_wpcf7_current_page_url(); #site url foreach ($atts as $field) { //loop each field $tag = new WPCF7_Shortcode($field); $name = $tag->name; //get field name if ($tag->has_option('gfield') && $tag->type != 'hw_wpcf7_special_fields') { if ($tag->get_option('gfield', '', true)) { $name = $tag->get_option('gfield', '', true); //modify field value $data[$name] = apply_filters('hwwpcf7_field_value', $posted_data[$tag->name], array('name' => $name, 'tag' => $tag, 'data' => &$data, 'wpcf7' => $wpcf7)); /*if(isset($_POST['product_id']) && $tag->name=='order_detail'){ $sp=get_post($_POST['product_id']); $data[$name] = '[ID='.$sp->ID.']'.PHP_EOL.$sp->post_title.PHP_EOL.get_permalink($sp->ID); }*/ //else $data[$name] = $posted_data[$tag->name]; } } /** * get field title */ if ($tag->has_option('placeholder') && $tag->type != 'hw_wpcf7_special_fields') { $fields_title[$name] = (string) reset($tag->values); #$tag->get_option('placeholder','',true); } /** * special tag to get special fields */ if ($tag->type == 'hw_wpcf7_special_fields') { foreach (HW_WPCF7::$special_gfields as $fname => $desc) { if ($tag->has_option($fname) && isset($special_fields_value[$fname])) { $data[$tag->get_option($fname, '', true)] = $special_fields_value[$fname]; //add special field value to data } } } } //storage if ($storage_hook == 'google_form') { //get google form id $gform_id = $WPCF7_ContactForm->prop('hw_gformID'); //from google spreadsheet as responses that link to google form. Create event onSubmitForm. you can send mail using google script. hw_wpcf7_post_gform($gform_id, $data); } elseif ($storage_hook == 'url') { $hook_url = $WPCF7_ContactForm->prop('hook_url'); //web hook url $data['labels'] = serialize($fields_title); //nest labels for all fields in one data together HW_CURL::curl_post($hook_url, $data); } /*hw_mail(array( 'subject'=>'Khách hàng liên hệ từ '.home_url(), 'body'=>$body ));*/ } }
/** * return current working form */ function current_form() { $current = WPCF7_ContactForm::get_current(); return $current; }
/** * Initialize the plugin by setting localization, filters, and administration functions. * * @since 1.0.0 * * @access private */ private function __construct() { global $formworks_tracker; //auto load modules $dir = FRMWKS_PATH . 'includes/modules'; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($folder = readdir($dh)) !== false) { if ($folder === '..' || $folder === '.') { continue; } if (file_exists($dir . '/' . $folder . '/handler.php')) { include_once $dir . '/' . $folder . '/handler.php'; } } closedir($dh); } } // Load plugin text domain add_action('init', array($this, 'load_plugin_textdomain')); //initialize visitor tracker if (!is_admin()) { add_action('wp', array($this, 'register_visitor_session')); } // Activate plugin when new blog is added add_action('wpmu_new_blog', array($this, 'activate_new_site')); // Load admin style sheet and JavaScript. add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_stylescripts')); // Load front style sheet and JavaScript. add_action('wp_enqueue_scripts', array($this, 'enqueue_front_stylescripts')); // output tracking code add_action('wp_print_footer_scripts', array($this, 'print_front_scripts')); // Add partial completions add_action('wp_ajax_frmwks_push', array($this, 'tracker_push')); add_action('wp_ajax_nopriv_frmwks_push', array($this, 'tracker_push')); // open actions add_action('formworks_track', array($this, 'handle_track'), 10, 4); /** * Tracking */ /** Caldera Forms */ add_action('caldera_forms_submit_complete', function ($form) { do_action('formworks_track', 'caldera', $form['ID'], 'submission'); }); add_filter('caldera_forms_render_form', function ($html, $form) { $selector = array("name" => $form['name'], "selector" => "." . $form['ID'], "prefix" => 'caldera', "id" => $form['ID']); do_action('formworks_track', 'caldera', $form['ID'], 'loaded', $selector); return $html; }, 10, 2); /** JETPACK */ add_filter('grunion_contact_form_success_message', function ($html) { if (isset($_GET['contact-form-id'])) { $form_id = $_GET['contact-form-id']; do_action('formworks_track', 'jp', $form_id, 'submission'); } return $html; }); add_filter('grunion_contact_form_form_action', function ($url, $post, $form) { $selector = array("name" => $post->post_title, "selector" => "#contact-form-" . $form); do_action('formworks_track', 'jp', $form, 'loaded', $selector); return $url; }, 15, 3); /** Formidable */ add_action('frm_process_entry', function ($params) { do_action('formworks_track', 'frmid', $params['form_id'], 'submission'); }, 15); add_filter('formidable_shortcode_atts', function ($shortcode_atts, $atts) { if (class_exists('\\FrmForm')) { $form = \FrmForm::getOne($atts['id']); } $selector = array("name" => $form->name, "selector" => "#form_" . $form->form_key); do_action('formworks_track', 'frmid', $form->id, 'loaded', $selector); }, 10, 2); /** Contact Form 7 */ add_filter('wpcf7_form_elements', function ($html) { if (class_exists('\\WPCF7_ContactForm')) { $form = \WPCF7_ContactForm::get_current(); do_action('formworks_track', 'cf7', $form->id(), 'loaded'); } return $html; }, 10, 2); add_action('wpcf7_submit', function ($instance, $result) { if (isset($result['status']) && 'mail_sent' === $result['status']) { do_action('formworks_track', 'cf7', $instance->id(), 'submission'); } }, 20, 2); /** Gravity Forms */ add_filter('gform_get_form_filter', function ($html, $form) { $selector = array("name" => $form['title'], "selector" => "#gform_" . $form['id']); do_action('formworks_track', 'gform', $form['id'], 'loaded', $selector); return $html; }, 10, 2); add_action('gform_after_submission', function ($form) { // do a submission complete do_action('formworks_track', 'gform', $form['form_id'], 'submission'); return; }); /** Ninja Forms */ add_action('ninja_forms_post_process', function () { global $ninja_forms_processing; if (is_object($ninja_forms_processing)) { do_action('formworks_track', 'ninja', $ninja_forms_processing->get_form_ID(), 'submission'); } }); //load settings class && licensing in admin if (is_admin()) { new settings(); add_action('admin_init', function () { $plugin = frmwks_licensing_args(); new \calderawp\licensing_helper\licensing($plugin); }, 0); } }
public function get_default_option($default = '', $args = '') { $args = wp_parse_args($args, array('multiple' => false)); $options = (array) $this->get_option('default'); $values = array(); if (empty($options)) { return $args['multiple'] ? $values : $default; } foreach ($options as $opt) { $opt = sanitize_key($opt); if ('user_' == substr($opt, 0, 5) && is_user_logged_in()) { $primary_props = array('user_login', 'user_email', 'user_url'); $opt = in_array($opt, $primary_props) ? $opt : substr($opt, 5); $user = wp_get_current_user(); $user_prop = $user->get($opt); if (!empty($user_prop)) { if ($args['multiple']) { $values[] = $user_prop; } else { return $user_prop; } } } elseif ('post_meta' == $opt && in_the_loop()) { if ($args['multiple']) { $values = array_merge($values, get_post_meta(get_the_ID(), $this->name)); } else { $val = (string) get_post_meta(get_the_ID(), $this->name, true); if (strlen($val)) { return $val; } } } elseif ('get' == $opt && isset($_GET[$this->name])) { $vals = (array) $_GET[$this->name]; $vals = array_map('wpcf7_sanitize_query_var', $vals); if ($args['multiple']) { $values = array_merge($values, $vals); } else { $val = isset($vals[0]) ? (string) $vals[0] : ''; if (strlen($val)) { return $val; } } } elseif ('post' == $opt && isset($_POST[$this->name])) { $vals = (array) $_POST[$this->name]; $vals = array_map('wpcf7_sanitize_query_var', $vals); if ($args['multiple']) { $values = array_merge($values, $vals); } else { $val = isset($vals[0]) ? (string) $vals[0] : ''; if (strlen($val)) { return $val; } } } elseif ('shortcode_attr' == $opt) { if ($contact_form = WPCF7_ContactForm::get_current()) { $val = $contact_form->shortcode_attr($this->name); if (strlen($val)) { if ($args['multiple']) { $values[] = $val; } else { return $val; } } } } } if ($args['multiple']) { $values = array_unique($values); return $values; } else { return $default; } }
/** * Redirect the user to the thanks/success page after submitting the form * * @since 1.0 */ function affwp_cf7_success_page_redirect($contact_form) { // Success page ID $success_page = affwp_cf7_get_success_page_id(); $submission = WPCF7_Submission::get_instance(); // get the value of the name field $name = $submission->get_posted_data('your-name'); // get the description $description = rawurlencode($contact_form->title()); // add customer's email address to the description $description .= ' - ' . $submission->get_posted_data('your-email'); // set the reference to be the first name $reference = isset($name) ? rawurlencode($name) : ''; // redirect to success page if ($success_page) { $wpcf7 = WPCF7_ContactForm::get_current(); $wpcf7->set_properties(array('additional_settings' => "on_sent_ok: \"location.replace(' " . add_query_arg(array('description' => $description, 'reference' => $reference, 'amount' => affwp_cf7_get_form_amount($contact_form->id())), get_permalink($success_page)) . " ');\"")); } }
function wpcf7_dynamichidden_shortcode_handler($tag) { $wpcf7_contact_form = WPCF7_ContactForm::get_current(); if (!is_array($tag)) { return ''; } $type = $tag['type']; $name = $tag['name']; $options = (array) $tag['options']; $values = (array) $tag['values']; if (empty($name)) { return ''; } $atts = ''; $id_att = ''; $class_att = ''; $size_att = ''; $maxlength_att = ''; $tabindex_att = ''; $class_att .= ' wpcf7-text'; foreach ($options as $option) { if (preg_match('%^id:([-0-9a-zA-Z_]+)$%', $option, $matches)) { $id_att = $matches[1]; } } if ($id_att) { $atts .= ' id="' . trim($id_att) . '"'; } // Value if (is_a($wpcf7_contact_form, 'WPCF7_ContactForm') && $wpcf7_contact_form->is_posted()) { if (isset($_POST['_wpcf7_mail_sent']) && $_POST['_wpcf7_mail_sent']['ok']) { $value = ''; } else { $value = stripslashes_deep($_POST[$name]); } } else { $value = isset($values[0]) ? $values[0] : ''; } $scval = do_shortcode('[' . $value . ']'); if ($scval != '[' . $value . ']') { $value = $scval; } //echo '<pre>'; print_r($options);echo '</pre>'; $html = '<input type="hidden" name="' . $name . '" value="' . esc_attr($value) . '"' . $atts . ' />'; //No need to validate, it's a hidden field - we could validate by checking the value hasn't changed, but that seems overkill I think //$validation_error = ''; //if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) ) // $validation_error = $wpcf7_contact_form->validation_error( $name ); $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . '</span>'; return $html; }
function dvin_wcql_mycf7_before_send_mail($WPCF7_ContactForm) { global $dvin_wcql_settings, $dvin_wcql_obj, $dvin_qlist_products; if (!isset($dvin_qlist_products) || empty($dvin_qlist_products)) { $dvin_qlist_products = WC()->session->get('$dvin_qlist_products'); } //Get current form $wpcf7 = WPCF7_ContactForm::get_current(); if ($dvin_wcql_settings['contactform7_form_select'] == $WPCF7_ContactForm->id()) { //prepare and send email $submission = WPCF7_Submission::get_instance(); $data = $submission->get_posted_data(); //create order if enabled if ($dvin_wcql_settings['create_order'] == 'on') { $dvin_wcql_obj->order_id = dvin_qlist_create_order($data); } //craete order // do some replacements in the cf7 email body $mail = $wpcf7->prop('mail'); //find the strings of quotelist, if it is there get the shortcode preg_match_all('/(\\[quotelist.*)/', $mail['body'], $matches); if (count($matches) > 0) { list($total_price, $table) = unserialize(do_shortcode($matches[0][0])); } // Find/replace the "[quotelist]" and "[orderinfo]"tag as defined in your CF7 email body // and add changes name $mail['body'] = str_replace(array($matches[0][0], '[orderinfo]'), array($table, $dvin_wcql_obj->get_order_info()), $mail['body']); // Save the email body $wpcf7->set_properties(array("mail" => $mail)); $mail2 = $wpcf7->prop('mail_2'); //get CF7's mail_2 object //handle cc mail if ($mail2['active']) { //if Checkbox checked // Find/replace the "[quotelist]" tag as defined in your CF7 email body // and add changes name //find the strings of quotelist, if it is there get the shortcode preg_match_all('/(\\[quotelist.*)/', $mail2['body'], $matches); if (count($matches) > 0) { list($total_price, $table) = unserialize(do_shortcode($matches[0][0])); } $mail2['body'] = str_replace(array($matches[0][0], '[orderinfo]'), array($table, $dvin_wcql_obj->get_order_info()), $mail2['body']); $wpcf7->set_properties(array('mail_2' => $mail2)); } $dvin_qlist_products = array(); WC()->session->set('dvin_qlist_products', array()); //clear the products from session } // return current cf7 instance return $wpcf7; }
public function validation_filter($result, $tag) { // valiedates field on submit $wpcf7_contact_form = WPCF7_ContactForm::get_current(); $type = $tag['type']; $name = $tag['name']; if ($type != 'dynamicselect*') { return $result; } $value_found = false; if (isset($_POST[$name])) { $value = $_POST[$name]; if (!is_array($value) && trim($value) != '') { $value_found = true; } if (is_array($value) && count($value)) { foreach ($value as $item) { if (trim($item) != '') { $value_found = true; break; } } // end foreach value } // end if array && count } // end if set if (!$value_found) { $result->invalidate($tag, wpcf7_get_message('invalid_required')); $result['valid'] = false; $result['reason'][$name] = $wpcf7_contact_form->message('invalid_required'); } return $result; }
function wpcf7_flamingo_serial_number($output, $name, $html) { if ('_serial_number' != $name) { return $output; } if (!class_exists('Flamingo_Inbound_Message') || !method_exists('Flamingo_Inbound_Message', 'count')) { return $output; } if (!($contact_form = WPCF7_ContactForm::get_current())) { return $output; } $channel_id = wpcf7_flamingo_add_channel($contact_form->name(), $contact_form->title()); if ($channel_id) { return 1 + (int) Flamingo_Inbound_Message::count(array('channel_id' => $channel_id)); } return 0; }
function wpcf7_get_current_contact_form() { if ($current = WPCF7_ContactForm::get_current()) { return $current; } }