Merged in feature/MAW-855-import-code-into-aws (pull request #2)
code import from pantheon * code import from pantheon
This commit is contained in:
@@ -55,7 +55,7 @@ var $ = jQuery.noConflict(),
|
||||
default:
|
||||
if (tag) {
|
||||
// Queue the requests for an AJAX call at the end of init
|
||||
dtx.queue.push(raw_value);
|
||||
dtx.queue.push({ 'value': raw_value, 'multiline': $input.is('textarea') });
|
||||
}
|
||||
return; // Don't continue after queuing it for AJAX
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
/*! Do not edit, this file is generated automatically - 2023-08-07 16:08:32 EDT */
|
||||
var $=jQuery.noConflict(),dtx={queue:[],init:function(){var $inputs=$("input.dtx-pageload[data-dtx-value]");$inputs.length&&($inputs.each(function(i,el){var el=$(el),raw_value=el.attr("data-dtx-value"),v=decodeURIComponent(raw_value).split(" ");if(v.length){var tag=v[0],atts={};if(1<v.length)for(var x=1;x<v.length;x++){var att=v[x].split("=");2===att.length&&(atts[att[0]]=att[1].split("'").join(""))}var value="";switch(tag){case"CF7_GET":value=dtx.get(atts);break;case"CF7_referrer":value=dtx.referrer(atts);break;case"CF7_URL":value=dtx.current_url(atts);break;case"CF7_get_cookie":value=dtx.get_cookie(atts);break;case"CF7_guid":value=dtx.guid();break;case"CF7_get_current_var":if(!dtx.validKey(atts,"key")||"url"!=atts.key)return;value=dtx.current_url(atts);break;case"CF7_get_post_var":case"CF7_get_custom_field":case"CF7_get_taxonomy":case"CF7_get_attachment":case"CF7_bloginfo":case"CF7_get_theme_option":return;default:return void(tag&&dtx.queue.push(raw_value))}dtx.set(el,value)}}),dtx.queue.length)&&setTimeout(function(){$.ajax({type:"POST",url:dtx_obj.ajax_url,dataType:"json",data:{action:"wpcf7dtx",shortcodes:dtx.queue},cache:!1,error:function(xhr,status,error){console.error("[CF7 DTX AJAX ERROR]",error,status,xhr)},success:function(data,status,xhr){"object"==typeof data&&data.length&&$.each(data,function(i,obj){var $inputs=$('.wpcf7 form input.dtx-pageload[data-dtx-value="'+obj.raw_value+'"]');$inputs.length&&(dtx.set($inputs,obj.value),$inputs.addClass("dtx-ajax-loaded"))})}})},10)},validKey:function(obj,key){return obj.hasOwnProperty(key)&&"string"==typeof obj[key]&&obj[key].trim()},obfuscate:function(value,atts){if(value=value.trim(),dtx.validKey(atts,"obfuscate")&&atts.obfuscate){for(var o="",i=0;i<value.length;i++)o+="&#"+value.codePointAt(i)+";";return o}return value},set:function($input,value){$input.attr("value",value).addClass("dtx-loaded")},get:function(atts){if(dtx.validKey(atts,"key")){var query=window.location.search;if(query)return query=new URLSearchParams(query),dtx.obfuscate(query.get(atts.key).trim(),atts)}return""},referrer:function(atts){return dtx.obfuscate(document.referrer,atts)},current_url:function(atts){if(!atts.hasOwnProperty("part"))return dtx.obfuscate(window.location.href,atts);if(["scheme","host","port","path","query","fragment"].includes(atts.part))switch(atts.part){case"scheme":return dtx.obfuscate(window.location.protocol.replace(":",""),atts);case"host":return dtx.obfuscate(window.location.host,atts);case"port":return dtx.obfuscate(window.location.port,atts);case"path":return dtx.obfuscate(window.location.pathname,atts);case"query":return dtx.obfuscate(window.location.search.replace("?",""),atts);case"fragment":return dtx.obfuscate(window.location.hash.replace("#",""),atts)}return""},get_cookie:function(atts){var keyValue;return atts.hasOwnProperty("key")&&"string"==typeof atts.key&&""!=atts.key.trim()&&(keyValue=document.cookie.match("(^|;) ?"+atts.key.trim()+"=([^;]*)(;|$)"))?dtx.obfuscate(keyValue[2],atts):""},guid:function(){if(void 0!==window.crypto&&void 0!==window.crypto.getRandomValues)return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,c=>(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16)).toUpperCase();console.warn("[CF7 DTX] Cryptographically secure PRNG is not available for generating GUID value");var d=(new Date).getTime(),d2="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var r=16*Math.random();return 0<d?(r=(d+r)%16|0,d=Math.floor(d/16)):(r=(d2+r)%16|0,d2=Math.floor(d2/16)),("x"===c?r:3&r|8).toString(16).toUpperCase()}).toUpperCase()}};$(document).ready(dtx.init);
|
||||
/*! Do not edit, this file is generated automatically - 2023-09-18 14:09:50 EDT */
|
||||
var $=jQuery.noConflict(),dtx={queue:[],init:function(){var e=$("input.dtx-pageload[data-dtx-value]");e.length&&(e.each(function(e,t){var r=$(t),a=r.attr("data-dtx-value"),o=decodeURIComponent(a).split(" ");if(o.length){var n=o[0],c={};if(1<o.length)for(var u=1;u<o.length;u++){var i=o[u].split("="),d;2===i.length&&(c[i[0]]=i[1].split("'").join(""))}var s="";switch(n){case"CF7_GET":s=dtx.get(c);break;case"CF7_referrer":s=dtx.referrer(c);break;case"CF7_URL":s=dtx.current_url(c);break;case"CF7_get_cookie":s=dtx.get_cookie(c);break;case"CF7_guid":s=dtx.guid();break;case"CF7_get_current_var":if(!dtx.validKey(c,"key")||"url"!=c.key)return;s=dtx.current_url(c);break;case"CF7_get_post_var":case"CF7_get_custom_field":case"CF7_get_taxonomy":case"CF7_get_attachment":case"CF7_bloginfo":case"CF7_get_theme_option":return;default:return void(n&&dtx.queue.push({value:a,multiline:r.is("textarea")}))}dtx.set(r,s)}}),dtx.queue.length)&&setTimeout(function(){$.ajax({type:"POST",url:dtx_obj.ajax_url,dataType:"json",data:{action:"wpcf7dtx",shortcodes:dtx.queue},cache:!1,error:function(e,t,r){},success:function(e,t,r){"object"==typeof e&&e.length&&$.each(e,function(e,t){var r=$('.wpcf7 form input.dtx-pageload[data-dtx-value="'+t.raw_value+'"]');r.length&&(dtx.set(r,t.value),r.addClass("dtx-ajax-loaded"))})}})},10)},validKey:function(e,t){return e.hasOwnProperty(t)&&"string"==typeof e[t]&&e[t].trim()},obfuscate:function(e,t){if(e=e.trim(),dtx.validKey(t,"obfuscate")&&t.obfuscate){for(var r="",a=0;a<e.length;a++)r+="&#"+e.codePointAt(a)+";";return r}return e},set:function(e,t){e.attr("value",t).addClass("dtx-loaded")},get:function(e){if(dtx.validKey(e,"key")){var t=window.location.search;if(t)return t=new URLSearchParams(t),dtx.obfuscate(t.get(e.key).trim(),e)}return""},referrer:function(e){return dtx.obfuscate(document.referrer,e)},current_url:function(e){if(!e.hasOwnProperty("part"))return dtx.obfuscate(window.location.href,e);var t;if(["scheme","host","port","path","query","fragment"].includes(e.part))switch(e.part){case"scheme":return dtx.obfuscate(window.location.protocol.replace(":",""),e);case"host":return dtx.obfuscate(window.location.host,e);case"port":return dtx.obfuscate(window.location.port,e);case"path":return dtx.obfuscate(window.location.pathname,e);case"query":return dtx.obfuscate(window.location.search.replace("?",""),e);case"fragment":return dtx.obfuscate(window.location.hash.replace("#",""),e)}return""},get_cookie:function(e){var t;return e.hasOwnProperty("key")&&"string"==typeof e.key&&""!=e.key.trim()&&(t=document.cookie.match("(^|;) ?"+e.key.trim()+"=([^;]*)(;|$)"))?dtx.obfuscate(t[2],e):""},guid:function(){var r,a;return(void 0!==window.crypto&&void 0!==window.crypto.getRandomValues?([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)):(r=(new Date).getTime(),a="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0,"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random();return 0<r?(t=(r+t)%16|0,r=Math.floor(r/16)):(t=(a+t)%16|0,a=Math.floor(a/16)),("x"===e?t:3&t|8).toString(16).toUpperCase()}))).toUpperCase()}};$(document).ready(dtx.init);
|
||||
@@ -26,6 +26,14 @@
|
||||
};
|
||||
|
||||
$(function() {
|
||||
$('form.tag-generator-panel input.dtx-option').on('change keyup', wpcf7dtx.taggen.updateOption);
|
||||
$('form.tag-generator-panel .dtx-option').on('change keyup click', wpcf7dtx.taggen.updateOption);
|
||||
$('.contact-form-editor-panel #tag-generator-list a.thickbox.button[href*="inlineId=tag-generator-panel-dynamic_"]').each(function() {
|
||||
var $btn = $(this),
|
||||
name = $btn.text();
|
||||
$btn.addClass('dtx-form-tag');
|
||||
if (name == 'dynamic drop-down menu' || name == 'dynamic checkboxes' || name == 'dynamic radio buttons') {
|
||||
$btn.attr('href', $btn.attr('href').replace('height=500', 'height=750'));
|
||||
}
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
@@ -1,2 +1,2 @@
|
||||
/*! Do not edit, this file is generated automatically - 2023-08-07 16:08:32 EDT */
|
||||
!function($){"use strict";"undefined"!=typeof wpcf7&&null!==wpcf7&&(window.wpcf7dtx=window.wpcf7dtx||{},wpcf7dtx.taggen={},wpcf7dtx.taggen.escapeRegExp=function(str){return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")},wpcf7dtx.taggen.replaceAll=function(input,f,r,no_escape){var rexp;return null!=input&&"string"==typeof input&&""!==input.trim()&&-1<input.indexOf(f)?(rexp=new RegExp(wpcf7dtx.taggen.escapeRegExp(f),"g"),no_escape&&(rexp=new RegExp(f,"g")),input.replace(rexp,r)):input},wpcf7dtx.taggen.updateOption=function(e){var e=$(e.currentTarget),value=encodeURIComponent(wpcf7dtx.taggen.replaceAll(e.val(),"'","'"));e.siblings('input[type="hidden"].option').val(value)},$(function(){$("form.tag-generator-panel input.dtx-option").on("change keyup",wpcf7dtx.taggen.updateOption)}))}(jQuery);
|
||||
/*! Do not edit, this file is generated automatically - 2023-09-18 14:09:50 EDT */
|
||||
!function(n){"use strict";"undefined"!=typeof wpcf7&&null!==wpcf7&&(window.wpcf7dtx=window.wpcf7dtx||{},wpcf7dtx.taggen={},wpcf7dtx.taggen.escapeRegExp=function(e){return e.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")},wpcf7dtx.taggen.replaceAll=function(e,t,n,a){var c;return null!=e&&"string"==typeof e&&""!==e.trim()&&-1<e.indexOf(t)?(c=new RegExp(wpcf7dtx.taggen.escapeRegExp(t),"g"),a&&(c=new RegExp(t,"g")),e.replace(c,n)):e},wpcf7dtx.taggen.updateOption=function(e){var e=n(e.currentTarget),t=encodeURIComponent(wpcf7dtx.taggen.replaceAll(e.val(),"'","'"));e.siblings('input[type="hidden"].option').val(t)},n(function(){n("form.tag-generator-panel .dtx-option").on("change keyup click",wpcf7dtx.taggen.updateOption),n('.contact-form-editor-panel #tag-generator-list a.thickbox.button[href*="inlineId=tag-generator-panel-dynamic_"]').each(function(){var e=n(this),t=e.text();e.addClass("dtx-form-tag"),"dynamic drop-down menu"!=t&&"dynamic checkboxes"!=t&&"dynamic radio buttons"!=t||e.attr("href",e.attr("href").replace("height=500","height=750"))})}))}(jQuery);
|
||||
@@ -1,7 +1,46 @@
|
||||
.tag-generator-panel[data-id^="dynamic_select"],
|
||||
.tag-generator-panel[data-id^="dynamic_checkbox"],
|
||||
.tag-generator-panel[data-id^="dynamic_radio"] {
|
||||
height: 740px;
|
||||
}
|
||||
|
||||
#tag-generator-list a.button.dtx-form-tag {
|
||||
border-color: #765cb9;
|
||||
color: #765cb9;
|
||||
}
|
||||
|
||||
.tag-generator-panel table.form-table th {
|
||||
width: 130px;
|
||||
}
|
||||
|
||||
.tag-generator-panel .control-box input.oneline {
|
||||
.tag-generator-panel table.form-table td small {
|
||||
display: block;
|
||||
margin-top: 0.25em;
|
||||
}
|
||||
|
||||
.tag-generator-panel .control-box input.oneline,
|
||||
.tag-generator-panel .control-box input.multiline,
|
||||
.tag-generator-panel .control-box textarea {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tag-generator-panel .control-box input[list],
|
||||
.tag-generator-panel .control-box input.multiline,
|
||||
.tag-generator-panel .control-box textarea {
|
||||
height: 30px;
|
||||
min-height: 30px;
|
||||
}
|
||||
|
||||
.tag-generator-panel .control-box input.multiline {
|
||||
display: inline-block;
|
||||
/* -webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none; */
|
||||
resize: vertical;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.tag-generator-panel .control-box textarea {
|
||||
height: 3.5em;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
.tag-generator-panel[data-id^=dynamic_checkbox],.tag-generator-panel[data-id^=dynamic_radio],.tag-generator-panel[data-id^=dynamic_select]{height:740px}#tag-generator-list a.button.dtx-form-tag{border-color:#765cb9;color:#765cb9}.tag-generator-panel table.form-table th{width:130px}.tag-generator-panel table.form-table td small{display:block;margin-top:.25em}.tag-generator-panel .control-box input.multiline,.tag-generator-panel .control-box input.oneline,.tag-generator-panel .control-box textarea{width:100%}.tag-generator-panel .control-box input.multiline,.tag-generator-panel .control-box input[list],.tag-generator-panel .control-box textarea{height:30px;min-height:30px}.tag-generator-panel .control-box input.multiline{display:inline-block;resize:vertical;overflow-x:hidden;overflow-y:scroll}.tag-generator-panel .control-box textarea{height:3.5em}
|
||||
@@ -1,5 +1,48 @@
|
||||
== Changelog ==
|
||||
|
||||
= 4.1.0 =
|
||||
|
||||
* Feature: Looks for a `dtx.php` file in the `wp_content` directory to maybe load custom shortcodes, [see support thread](https://wordpress.org/support/topic/how-to-avoid-custom-shortcodes-being-overwritten-on-updates/)
|
||||
* Feature: Looks for a `dtx.php` file in the current active theme's directory to maybe load custom shortcodes, [see support thread](https://wordpress.org/support/topic/how-to-avoid-custom-shortcodes-being-overwritten-on-updates/)
|
||||
* Feature: Looks for a `dtx.php` file in the current active theme's parent directory to maybe load custom shortcodes, [see support thread](https://wordpress.org/support/topic/how-to-avoid-custom-shortcodes-being-overwritten-on-updates/)
|
||||
* Fix: addressed user reported bug, [see support thread](https://wordpress.org/support/topic/fatal-error-v4-0-3/)
|
||||
|
||||
= 4.0.3 =
|
||||
|
||||
* Feature: Added `exclusive` option to checkbox tag generator
|
||||
* Fix: addressed bug that put all dynamic checkbox/radio options into one
|
||||
* Fix: addressed bug in frontend validator for multiple selected values
|
||||
|
||||
= 4.0.2 =
|
||||
|
||||
* Fix: addressed bug that put all dynamic select options into one, [see support thread](https://wordpress.org/support/topic/dynamic-select-get-option-values-from-shortcode/)
|
||||
* Update: sanitizing and escaping filters now accept `none` as value for `$type` to bypass. Use with caution.
|
||||
|
||||
= 4.0.1 =
|
||||
|
||||
* Fix: addressed bug that prevented translation for cache compatibility description
|
||||
|
||||
= 4.0.0 =
|
||||
|
||||
* Major: modified function names
|
||||
* Major: deprecated `dynamictext` and `dynamichidden` form tags in favor of `dynamic_text` and `dynamic_hidden`. For more information, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_email` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-email/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_url` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-url/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_tel` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-tel/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_number` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-number/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_range` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-range/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_textarea` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-textarea/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_select` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_radio` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-radio/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_date` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-date/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_submit` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-submit/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dtx_hide_blank` form tag attribute for `dynamic_select`. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dtx_disable_blank` form tag attribute for `dynamic_select`. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: added mail validation for `dynamic_email` and `dynamic_hidden` for backend configuration. For more information, see the [FAQ](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/frequently-asked-questions/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: added the Akismet feature to DTX text, email, and URL form tags.
|
||||
* Update: adjusted how queued values were sent for cache compatibility mode to allow for multiline values in textareas
|
||||
* Removed unused utility functions
|
||||
|
||||
= 3.5.4 =
|
||||
|
||||
* Fix: Updated JavaScript to prevent cacheable fields from making unnecessary AJAX requests
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Plugin Name: Contact Form 7 - Dynamic Text Extension
|
||||
* Plugin URI: https://sevenspark.com/goods/contact-form-7-dynamic-text-extension
|
||||
* Description: This plugin extends Contact Form 7 by adding dynamic form fields that accept any shortcode to generate default values and placeholder text. Requires Contact Form 7.
|
||||
* Version: 3.5.4
|
||||
* Version: 4.1.0
|
||||
* Author: SevenSpark, AuRise Creative
|
||||
* Author URI: https://sevenspark.com
|
||||
* License: GPL2
|
||||
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
// Define current version
|
||||
define('WPCF7DTX_VERSION', '3.5.4');
|
||||
define('WPCF7DTX_VERSION', '4.1.0');
|
||||
|
||||
// Define root directory
|
||||
defined('WPCF7DTX_DIR') || define('WPCF7DTX_DIR', __DIR__);
|
||||
@@ -47,31 +47,139 @@ defined('WPCF7DTX_FILE') || define('WPCF7DTX_FILE', __FILE__);
|
||||
*/
|
||||
function wpcf7dtx_init()
|
||||
{
|
||||
add_action('wpcf7_init', 'wpcf7dtx_add_shortcode_dynamictext'); // Add custom form tags to CF7
|
||||
add_filter('wpcf7_validate_dynamictext*', 'wpcf7dtx_dynamictext_validation_filter', 20, 2); // Validate custom form tags
|
||||
add_action('wpcf7_init', 'wpcf7dtx_add_shortcodes'); // Add custom form tags to CF7
|
||||
}
|
||||
add_action('plugins_loaded', 'wpcf7dtx_init', 20);
|
||||
|
||||
/**
|
||||
* DTX Formg Tag Configuration
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wpcf7dtx_config()
|
||||
{
|
||||
global $wpcf7_dynamic_fields_config;
|
||||
if (!isset($wpcf7_dynamic_fields_config)) {
|
||||
$wpcf7_dynamic_fields_config = array(
|
||||
'dynamic_text' => array(
|
||||
'title' => __('dynamic text', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'dtx_pageload'),
|
||||
'description' => __('a single-line plain text', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dynamic_hidden' => array(
|
||||
'title' => __('dynamic hidden', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('dtx_pageload'),
|
||||
'description' => __('a single-line plain text hidden input field', 'contact-form-7-dynamic-text-extension'),
|
||||
'features' => array(
|
||||
'display-hidden' => true // Generates an HTML element that is not visible
|
||||
)
|
||||
),
|
||||
'dynamic_email' => array(
|
||||
'title' => __('dynamic email', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'dtx_pageload'),
|
||||
'description' => __('a single-line email address input field', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dynamic_url' => array(
|
||||
'title' => __('dynamic URL', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'dtx_pageload'),
|
||||
'description' => __('a single-line URL input field', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dynamic_tel' => array(
|
||||
'title' => __('dynamic tel', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'pattern'),
|
||||
'description' => __('a single-line telephone number input field', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dynamic_number' => array(
|
||||
'title' => __('dynamic number', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'min', 'max', 'step', 'pattern'),
|
||||
'description' => __('a numeric input field displayed as a number spinbox', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dynamic_range' => array(
|
||||
'title' => __('dynamic range', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'min', 'max', 'step', 'pattern'),
|
||||
'description' => __('a numeric input field displayed as a slider between a minimum and maximum range', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dynamic_textarea' => array(
|
||||
'title' => __('dynamic textarea', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'dtx_pageload'),
|
||||
'description' => __('a multi-line plain text input field', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dynamic_select' => array(
|
||||
'title' => __('dynamic drop-down menu', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'multiple', 'include_blank'),
|
||||
'description' => __('a drop-down menu (i.e select input field)', 'contact-form-7-dynamic-text-extension'),
|
||||
'features' => array(
|
||||
'selectable-values' => true // Generates an option (or group of options) from which you can select one or more options
|
||||
)
|
||||
),
|
||||
'dynamic_checkbox' => array(
|
||||
'title' => __('dynamic checkboxes', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('readonly', 'label_first', 'use_label_element', 'exclusive'),
|
||||
'description' => __('a group of checkboxes', 'contact-form-7-dynamic-text-extension'),
|
||||
'features' => array(
|
||||
'multiple-controls-container' => true, // Generates an HTML element that can contain multiple form controls
|
||||
'selectable-values' => true // Generates an option (or group of options) from which you can select one or more options
|
||||
)
|
||||
),
|
||||
'dynamic_radio' => array(
|
||||
'title' => __('dynamic radio buttons', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('readonly', 'label_first', 'use_label_element'),
|
||||
'description' => __('a group of radio buttons', 'contact-form-7-dynamic-text-extension'),
|
||||
'features' => array(
|
||||
'multiple-controls-container' => true, // Generates an HTML element that can contain multiple form controls
|
||||
'selectable-values' => true // Generates an option (or group of options) from which you can select one or more options
|
||||
)
|
||||
),
|
||||
'dynamic_date' => array(
|
||||
'title' => __('dynamic date', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('placeholder', 'readonly', 'min', 'max'),
|
||||
'description' => __('a date input field', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dynamic_submit' => array(
|
||||
'title' => __('dynamic submit', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'options' => array('dtx_pageload'),
|
||||
'description' => __('a submit button', 'contact-form-7-dynamic-text-extension')
|
||||
)
|
||||
);
|
||||
}
|
||||
return $wpcf7_dynamic_fields_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Custom Shortcodes to Contact Form 7
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wpcf7dtx_add_shortcode_dynamictext()
|
||||
function wpcf7dtx_add_shortcodes()
|
||||
{
|
||||
//Add the dynamic text and hidden form fields
|
||||
wpcf7_add_form_tag(
|
||||
array(
|
||||
'dynamictext', 'dynamictext*',
|
||||
'dynamichidden', 'dynamichidden*' //Required hidden fields do nothing
|
||||
),
|
||||
'wpcf7dtx_dynamictext_shortcode_handler', //Callback
|
||||
array( //Features
|
||||
'name-attr' => true,
|
||||
'dtx_pageload' => true
|
||||
)
|
||||
);
|
||||
//Add the dynamic form fields
|
||||
foreach (wpcf7dtx_config() as $form_tag => $field) {
|
||||
$input_type = str_replace('dynamic_', '', $form_tag);
|
||||
$tag_types = array($form_tag, "$form_tag*");
|
||||
$callback = 'wpcf7dtx_shortcode_handler';
|
||||
$features = array_merge(array('name-attr' => true), wpcf7dtx_array_has_key('features', $field, array()));
|
||||
switch ($input_type) {
|
||||
case 'text':
|
||||
case 'hidden':
|
||||
// Add deprecated tags
|
||||
$dep_tag = str_replace('_', '', $form_tag);
|
||||
$tag_types[] = $dep_tag;
|
||||
$tag_types[] = "$dep_tag*";
|
||||
add_filter("wpcf7_validate_$dep_tag*", 'wpcf7dtx_validation_filter', 20, 2); // Validate required deprecated form tags
|
||||
break;
|
||||
case 'submit':
|
||||
case 'reset':
|
||||
$callback = 'wpcf7dtx_button_shortcode_handler';
|
||||
$features['name-attr'] = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
add_filter("wpcf7_validate_$form_tag*", 'wpcf7dtx_validation_filter', 20, 2); // Validate required custom form tags
|
||||
wpcf7_add_form_tag($tag_types, $callback, $features);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,35 +220,9 @@ add_action('wp_enqueue_scripts', 'wpcf7dtx_enqueue_frontend_assets');
|
||||
include_once(WPCF7DTX_DIR . '/includes/utilities.php');
|
||||
|
||||
/**
|
||||
* Get Dynamic Value
|
||||
*
|
||||
* @since 3.2.2
|
||||
*
|
||||
* @param string $value The form tag value.
|
||||
* @param WPCF7_FormTag|false $tag Optional. Use to look up default value.
|
||||
*
|
||||
* @return string The dynamic output or the original value, not escaped or sanitized.
|
||||
* Include Validation Functions
|
||||
*/
|
||||
function wpcf7dtx_get_dynamic($value, $tag = false)
|
||||
{
|
||||
if ($tag !== false) {
|
||||
$default = $tag->get_option('defaultvalue', '', true);
|
||||
if (!$default) {
|
||||
$default = $tag->get_default_option(strval(reset($tag->values)));
|
||||
}
|
||||
$value = wpcf7_get_hangover($tag->name, $default);
|
||||
}
|
||||
$value = apply_filters('wpcf7dtx_sanitize', $value);
|
||||
if (is_string($value) && !empty($value)) {
|
||||
// If a shortcode was passed as the options, evaluate it and use the result
|
||||
$shortcode_tag = '[' . $value . ']';
|
||||
$shortcode_output = do_shortcode($shortcode_tag); //Shortcode value
|
||||
if (is_string($shortcode_output) && $shortcode_output != $shortcode_tag) {
|
||||
return apply_filters('wpcf7dtx_sanitize', $shortcode_output);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
include_once(WPCF7DTX_DIR . '/includes/validation.php');
|
||||
|
||||
/**
|
||||
* Form Tag Handler
|
||||
@@ -149,59 +231,54 @@ function wpcf7dtx_get_dynamic($value, $tag = false)
|
||||
*
|
||||
* @return string HTML output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_dynamictext_shortcode_handler($tag)
|
||||
function wpcf7dtx_shortcode_handler($tag)
|
||||
{
|
||||
// Name attribute is required for these form tags
|
||||
if (empty($tag->name)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
//Validate
|
||||
// Validate
|
||||
$validation_error = wpcf7_get_validation_error($tag->name);
|
||||
|
||||
//Configure classes
|
||||
$class = wpcf7_form_controls_class($tag->type, 'wpcf7dtx-dynamictext');
|
||||
if ($validation_error) {
|
||||
$class .= ' wpcf7-not-valid';
|
||||
}
|
||||
|
||||
//Configure input attributes
|
||||
$atts = array();
|
||||
$atts['type'] = sanitize_key(str_replace(array('dynamic_', 'dynamic'), '', $tag->basetype));
|
||||
$atts['name'] = $tag->name;
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['id'] = strval($tag->get_id_option());
|
||||
$atts['tabindex'] = $tag->get_option('tabindex', 'signed_int', true);
|
||||
$atts['size'] = $tag->get_size_option('40');
|
||||
$atts['maxlength'] = $tag->get_maxlength_option();
|
||||
$atts['minlength'] = $tag->get_minlength_option();
|
||||
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
|
||||
switch ($tag->basetype) {
|
||||
case 'dynamichidden':
|
||||
$atts['type'] = 'hidden'; //Override type as hidden
|
||||
break;
|
||||
default: // Includes `dynamictext`
|
||||
$atts['type'] = 'text'; //Override type as text
|
||||
break;
|
||||
}
|
||||
if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
|
||||
unset($atts['maxlength'], $atts['minlength']);
|
||||
$atts['class'] = explode(' ', wpcf7_form_controls_class($atts['type']));
|
||||
$atts['class'][] = 'wpcf7dtx';
|
||||
$atts['class'][] = sanitize_html_class('wpcf7dtx-' . $atts['type']);
|
||||
if ($validation_error) {
|
||||
$atts['class'][] = 'wpcf7-not-valid';
|
||||
$atts['aria-invalid'] = 'true';
|
||||
$atts['aria-describedby'] = wpcf7_get_validation_error_reference($tag->name);
|
||||
} else {
|
||||
$atts['aria-invalid'] = 'false';
|
||||
}
|
||||
|
||||
if ($tag->has_option('readonly')) {
|
||||
$atts['readonly'] = 'readonly';
|
||||
}
|
||||
if ($tag->is_required() && $atts['type'] !== 'hidden') {
|
||||
// Add required attribute to applicable input types
|
||||
if ($tag->is_required() && !in_array($atts['type'], array('hidden', 'quiz'))) {
|
||||
$atts['aria-required'] = 'true';
|
||||
$atts['required'] = 'required';
|
||||
}
|
||||
|
||||
// Evaluate the dynamic value
|
||||
$value = wpcf7dtx_get_dynamic(false, $tag);
|
||||
$sanitize_type = $atts['type'] == 'textarea' ? $atts['type'] : 'auto';
|
||||
$value = wpcf7dtx_get_dynamic(false, $tag, $sanitize_type);
|
||||
|
||||
// Identify placeholder
|
||||
if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
|
||||
//Reverse engineer what JS did (converted quotes to HTML entities --> URL encode) then sanitize
|
||||
$placeholder = html_entity_decode(urldecode(implode('', (array)$tag->get_option('placeholder'))), ENT_QUOTES);
|
||||
$placeholder = html_entity_decode(urldecode($tag->get_option('placeholder', '', true)), ENT_QUOTES);
|
||||
if ($placeholder) {
|
||||
//If a different placeholder text has been specified, set both attributes
|
||||
$placeholder = wpcf7dtx_get_dynamic($placeholder);
|
||||
$placeholder = wpcf7dtx_get_dynamic($placeholder, false, $sanitize_type);
|
||||
$atts['placeholder'] = $placeholder;
|
||||
$atts['value'] = $value;
|
||||
} else {
|
||||
@@ -212,18 +289,186 @@ function wpcf7dtx_dynamictext_shortcode_handler($tag)
|
||||
$atts['value'] = $value;
|
||||
}
|
||||
|
||||
if ($atts['type'] == 'hidden') {
|
||||
// Always disable for hidden fields
|
||||
$atts['autocomplete'] = 'off';
|
||||
// Page load attribute
|
||||
if ($tag->has_option('dtx_pageload') && is_array($tag->raw_values) && count($tag->raw_values)) {
|
||||
$atts['data-dtx-value'] = rawurlencode(sanitize_text_field($tag->raw_values[0]));
|
||||
$atts['class'][] = 'dtx-pageload';
|
||||
if (wp_style_is('wpcf7dtx', 'registered') && !wp_script_is('wpcf7dtx', 'queue')) {
|
||||
// If already registered, just enqueue it
|
||||
wp_enqueue_script('wpcf7dtx');
|
||||
} elseif (!wp_style_is('wpcf7dtx', 'registered')) {
|
||||
// If not registered, do that first, then enqueue it
|
||||
wpcf7dtx_enqueue_frontend_assets();
|
||||
wp_enqueue_script('wpcf7dtx');
|
||||
}
|
||||
}
|
||||
|
||||
// Additional configuration based on form field type
|
||||
if (in_array($atts['type'], array('select', 'checkbox', 'radio'))) {
|
||||
/**
|
||||
* Configuration for selection-based fields
|
||||
*/
|
||||
if ($tag->has_option('default')) {
|
||||
$atts['dtx-default'] = wpcf7dtx_get_dynamic(html_entity_decode(urldecode($tag->get_option('default', '', true)), ENT_QUOTES));
|
||||
}
|
||||
|
||||
// Get options for selection-based fields
|
||||
$options = array();
|
||||
$pipes = $tag->pipes->to_array();
|
||||
if (count($pipes)) {
|
||||
foreach ($pipes as $pipe) {
|
||||
$key = trim(strval($pipe[0]));
|
||||
$value = trim(strval($pipe[1]));
|
||||
if ($key && $value) {
|
||||
$options[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($atts['type'] == 'select' && $tag->has_option('include_blank')) {
|
||||
$atts['placeholder'] = wpcf7dtx_array_has_key('placeholder', $atts, __('—Please choose an option—', 'contact-form-7-dynamic-text-extension'));
|
||||
}
|
||||
} else {
|
||||
// Disable autocomplete for this field if a value has been specified
|
||||
$atts['autocomplete'] = $atts['value'] ? 'off' : $tag->get_option('autocomplete', '[-0-9a-zA-Z]+', true);
|
||||
/**
|
||||
* Configuration for text-based fields
|
||||
*/
|
||||
|
||||
// Attributes
|
||||
$atts['maxlength'] = $tag->get_maxlength_option();
|
||||
$atts['minlength'] = $tag->get_minlength_option();
|
||||
if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
|
||||
unset($atts['maxlength'], $atts['minlength']);
|
||||
}
|
||||
|
||||
// Autocomplete attribute
|
||||
if ($atts['type'] == 'hidden') {
|
||||
$atts['autocomplete'] = 'off'; // Always disable for hidden fields
|
||||
} else {
|
||||
// Disable autocomplete for this field if a dynamic value has been specified
|
||||
$atts['autocomplete'] = $atts['value'] ? 'off' : $tag->get_option('autocomplete', '[-0-9a-zA-Z]+', true);
|
||||
}
|
||||
|
||||
switch ($atts['type']) {
|
||||
case 'email':
|
||||
case 'url':
|
||||
case 'tel':
|
||||
case 'number':
|
||||
case 'date':
|
||||
// Client-side validation by type
|
||||
$atts['class'][] = sanitize_html_class('wpcf7-validates-as-' . $atts['type']);
|
||||
break;
|
||||
case 'range':
|
||||
// Client-side validation by type
|
||||
$atts['class'][] = 'wpcf7-validates-as-number';
|
||||
break;
|
||||
case 'textarea':
|
||||
// Attributes unique to textareas
|
||||
$atts['cols'] = $tag->get_cols_option('40');
|
||||
$atts['rows'] = $tag->get_rows_option('10');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap up class attribute
|
||||
$atts['class'] = $tag->get_class_option($atts['class']);
|
||||
|
||||
// Output the form field HTML
|
||||
$wrapper = '<span class="wpcf7-form-control-wrap %1$s" data-name="%1$s">%2$s%3$s</span>';
|
||||
$allowed_html = array('br' => array(), 'span' => array('id' => array(), 'class' => array(), 'data-name' => array(), 'aria-hidden' => array()));
|
||||
switch ($atts['type']) {
|
||||
case 'checkbox':
|
||||
case 'radio':
|
||||
return wp_kses(sprintf(
|
||||
str_replace('<span class=', '<span%4$s class=', $wrapper), // Insert a 4th parameter for wrapper
|
||||
esc_attr($tag->name),
|
||||
wpcf7dtx_checkbox_group_html(
|
||||
$atts,
|
||||
$options,
|
||||
in_array('use_label_element', $tag->options),
|
||||
in_array('label_first', $tag->options),
|
||||
in_array('exclusive', $tag->options)
|
||||
),
|
||||
$validation_error,
|
||||
$atts['id'] ? sprintf(' id="%s"', esc_attr($atts['id'])) : ''
|
||||
), array_merge($allowed_html, array(
|
||||
'label' => array('for' => array()),
|
||||
'input' => wpcf7dtx_get_allowed_field_properties($atts['type'])
|
||||
)));
|
||||
case 'select':
|
||||
$allowed_html = array_merge($allowed_html, wpcf7dtx_get_allowed_field_properties('option'), array(
|
||||
'select' => wpcf7dtx_get_allowed_field_properties($atts['type'])
|
||||
));
|
||||
return wp_kses(sprintf(
|
||||
$wrapper,
|
||||
esc_attr($tag->name),
|
||||
wpcf7dtx_select_html(
|
||||
$atts,
|
||||
$options,
|
||||
$tag->has_option('dtx_hide_blank'),
|
||||
$tag->has_option('dtx_disable_blank')
|
||||
),
|
||||
$validation_error
|
||||
), array_merge($allowed_html, wpcf7dtx_get_allowed_field_properties('option'), array(
|
||||
'select' => wpcf7dtx_get_allowed_field_properties($atts['type']),
|
||||
)));
|
||||
case 'textarea':
|
||||
return wp_kses(sprintf(
|
||||
$wrapper,
|
||||
esc_attr($tag->name),
|
||||
wpcf7dtx_textarea_html($atts),
|
||||
$validation_error
|
||||
), array_merge($allowed_html, array(
|
||||
'textarea' => wpcf7dtx_get_allowed_field_properties($atts['type'])
|
||||
)));
|
||||
default:
|
||||
return wp_kses(sprintf(
|
||||
$wrapper,
|
||||
esc_attr($tag->name),
|
||||
wpcf7dtx_input_html($atts),
|
||||
$validation_error
|
||||
), array_merge($allowed_html, array(
|
||||
'input' => wpcf7dtx_get_allowed_field_properties($atts['type'])
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form Tag Handler for Dynamic Submit
|
||||
*
|
||||
* @param WPCF7_FormTag $tag Current Contact Form 7 tag object
|
||||
*
|
||||
* @return string HTML output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_button_shortcode_handler($tag)
|
||||
{
|
||||
//Configure input attributes
|
||||
$atts = array();
|
||||
$atts['type'] = sanitize_key(str_replace('dynamic_', '', $tag->basetype));
|
||||
$atts['id'] = strval($tag->get_id_option());
|
||||
$atts['tabindex'] = $tag->get_option('tabindex', 'signed_int', true);
|
||||
$atts['value'] = wpcf7dtx_get_dynamic(false, $tag); // Evaluate the dynamic value
|
||||
$atts['class'] = explode(' ', wpcf7_form_controls_class($atts['type']));
|
||||
$atts['class'][] = 'wpcf7dtx';
|
||||
$atts['class'][] = sanitize_html_class('wpcf7dtx-' . $atts['type']);
|
||||
if ($atts['type'] == 'submit') {
|
||||
$atts['class'][] = 'has-spinner';
|
||||
}
|
||||
|
||||
// Default value if empty
|
||||
if (empty($atts['value'])) {
|
||||
switch ($atts['type']) {
|
||||
case 'reset':
|
||||
$atts['value'] = __('Clear', 'contact-form-7-dynamic-text-extension');
|
||||
break;
|
||||
default:
|
||||
$atts['value'] = __('Send', 'contact-form-7-dynamic-text-extension');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Page load attribute
|
||||
if ($tag->has_option('dtx_pageload')) {
|
||||
$atts['data-dtx-value'] = rawurlencode(sanitize_text_field(implode('', (array)$tag->raw_values)));
|
||||
$class .= ' dtx-pageload';
|
||||
if ($tag->has_option('dtx_pageload') && is_array($tag->raw_values) && count($tag->raw_values)) {
|
||||
$atts['data-dtx-value'] = rawurlencode(sanitize_text_field($tag->raw_values[0]));
|
||||
$atts['class'][] = 'dtx-pageload';
|
||||
if (wp_style_is('wpcf7dtx', 'registered') && !wp_script_is('wpcf7dtx', 'queue')) {
|
||||
// If already registered, just enqueue it
|
||||
wp_enqueue_script('wpcf7dtx');
|
||||
@@ -235,55 +480,15 @@ function wpcf7dtx_dynamictext_shortcode_handler($tag)
|
||||
}
|
||||
|
||||
// Wrap up class attribute
|
||||
$atts['class'] = $tag->get_class_option($class);
|
||||
$atts['class'] = $tag->get_class_option($atts['class']);
|
||||
|
||||
//Output the HTML
|
||||
return sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %s" data-name="%s"><input %s />%s</span>',
|
||||
sanitize_html_class($tag->name),
|
||||
esc_attr($tag->name),
|
||||
wpcf7_format_atts($atts), //This function already escapes attribute values
|
||||
$validation_error
|
||||
// Output the form field HTML
|
||||
return wp_kses(
|
||||
wpcf7dtx_input_html($atts),
|
||||
array('input' => wpcf7dtx_get_allowed_field_properties($atts['type']))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Required Dynamic Text Field
|
||||
*
|
||||
* @param WPCF7_Validation $result the current validation result object
|
||||
* @param WPCF7_FormTag $tag the current form tag being filtered for validation
|
||||
*
|
||||
* @return WPCF7_Validation a possibly modified validation result object
|
||||
*/
|
||||
function wpcf7dtx_dynamictext_validation_filter($result, $tag)
|
||||
{
|
||||
//Sanitize value
|
||||
$value = empty($_POST[$tag->name]) ? '' : sanitize_text_field(strval($_POST[$tag->name]));
|
||||
|
||||
//Validate
|
||||
if ('dynamictext' == $tag->basetype) {
|
||||
if ($tag->is_required() && '' == $value) {
|
||||
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
|
||||
}
|
||||
}
|
||||
if (!empty($value)) {
|
||||
$maxlength = $tag->get_maxlength_option();
|
||||
$minlength = $tag->get_minlength_option();
|
||||
if ($maxlength && $minlength && $maxlength < $minlength) {
|
||||
$maxlength = $minlength = null;
|
||||
}
|
||||
$code_units = wpcf7_count_code_units($value);
|
||||
if (false !== $code_units) {
|
||||
if ($maxlength && $maxlength < $code_units) {
|
||||
$result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
|
||||
} elseif ($minlength && $code_units < $minlength) {
|
||||
$result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX Request Handler for After Page Loading
|
||||
*
|
||||
@@ -296,16 +501,14 @@ function wpcf7dtx_dynamictext_validation_filter($result, $tag)
|
||||
function wpcf7dtx_js_handler()
|
||||
{
|
||||
$return = array();
|
||||
$shortcodes = wpcf7dtx_array_has_key('shortcodes', $_POST);
|
||||
if (is_array($shortcodes) && count($shortcodes)) {
|
||||
foreach ($shortcodes as $raw_value) {
|
||||
$value = sanitize_text_field(rawurldecode($raw_value));
|
||||
if (!empty($value)) {
|
||||
$value = wpcf7dtx_get_dynamic($value);
|
||||
}
|
||||
$queue = wpcf7dtx_array_has_key('shortcodes', $_POST);
|
||||
if (is_array($queue) && count($queue)) {
|
||||
foreach ($queue as $field) {
|
||||
$multiline = wpcf7dtx_array_has_key('multiline', $field, false);
|
||||
$raw_value = sanitize_text_field(rawurldecode(wpcf7dtx_array_has_key('value', $field)));
|
||||
$return[] = array(
|
||||
'raw_value' => esc_attr($raw_value),
|
||||
'value' => esc_attr($value)
|
||||
'value' => esc_attr(wpcf7dtx_get_dynamic($raw_value, false, $multiline ? 'textarea' : 'auto'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -322,6 +525,20 @@ if (is_admin()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Included Shortcodes
|
||||
* Built-in Shortcodes
|
||||
*/
|
||||
include_once(WPCF7DTX_DIR . '/includes/shortcodes.php');
|
||||
|
||||
/**
|
||||
* Website's custom shortcodes, if they exist
|
||||
*/
|
||||
$user_files = array(
|
||||
constant('WP_CONTENT_DIR') . '/dtx.php', // e.g. C:\path\to\website\wp-content\dtx.php
|
||||
get_template_directory() . '/dtx.php', // e.g. C:\path\to\website\wp-content/themes/parent-theme/dtx.php
|
||||
get_stylesheet_directory() . '/dtx.php' // e.g. C:\path\to\website\wp-content/themes/child-theme/dtx.php
|
||||
);
|
||||
foreach ($user_files as $user_file) {
|
||||
if (file_exists($user_file)) {
|
||||
include_once($user_file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ function wpcf7dtx_enqueue_admin_assets($hook)
|
||||
// Only load on CF7 Form pages (both editing forms and creating new forms)
|
||||
if ($hook === 'toplevel_page_wpcf7' || $hook === 'contact_page_wpcf7-new') {
|
||||
$prefix = 'wpcf7dtx-';
|
||||
$debug = defined('WP_DEBUG') && constant('WP_DEBUG');
|
||||
$debug = defined('WP_DEBUG_SCRIPTS') && constant('WP_DEBUG_SCRIPTS');
|
||||
$url = plugin_dir_url(WPCF7DTX_FILE);
|
||||
$path = plugin_dir_path(WPCF7DTX_FILE);
|
||||
|
||||
wp_enqueue_style(
|
||||
$prefix . 'admin', //Handle
|
||||
$url . 'assets/styles/tag-generator.css', //Source
|
||||
$url . 'assets/styles/tag-generator' . ($debug ? '' : '.min') . '.css', //Source
|
||||
array('contact-form-7-admin'), //Dependencies
|
||||
$debug ? @filemtime($path . 'assets/styles/tag-generator.css') : WPCF7DTX_VERSION //Version
|
||||
);
|
||||
@@ -44,30 +44,22 @@ add_action('admin_enqueue_scripts', 'wpcf7dtx_enqueue_admin_assets'); //Enqueue
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wpcf7dtx_add_tag_generator_dynamictext()
|
||||
function wpcf7dtx_add_tag_generators()
|
||||
{
|
||||
if (!class_exists('WPCF7_TagGenerator')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Custom dynamic fields to add
|
||||
global $wpcf7_dynamic_fields_config;
|
||||
|
||||
// Loop fields to add them
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
|
||||
//Dynamic Text Field
|
||||
$tag_generator->add(
|
||||
'dynamictext', //id
|
||||
__('dynamic text', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'wpcf7dtx_tag_generator_dynamictext', //callback
|
||||
array('placeholder', 'readonly', 'dtx_pageload') //options
|
||||
);
|
||||
|
||||
//Dynamic Hidden Field
|
||||
$tag_generator->add(
|
||||
'dynamichidden', //id
|
||||
__('dynamic hidden', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'wpcf7dtx_tag_generator_dynamictext', //callback
|
||||
array('dtx_pageload') // options
|
||||
);
|
||||
foreach ($wpcf7_dynamic_fields_config as $id => $field) {
|
||||
$tag_generator->add($id, $field['title'], 'wpcf7dtx_tag_generator', array_merge(array('name-attr', 'dtx_pageload'), $field['options']));
|
||||
}
|
||||
}
|
||||
add_action('wpcf7_admin_init', 'wpcf7dtx_add_tag_generator_dynamictext', 100);
|
||||
add_action('wpcf7_admin_init', 'wpcf7dtx_add_tag_generators', 100);
|
||||
|
||||
/**
|
||||
* Echo HTML for Dynamic Tag Generator
|
||||
@@ -77,36 +69,43 @@ add_action('wpcf7_admin_init', 'wpcf7dtx_add_tag_generator_dynamictext', 100);
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wpcf7dtx_tag_generator_dynamictext($contact_form, $options = '')
|
||||
function wpcf7dtx_tag_generator($contact_form, $options = '')
|
||||
{
|
||||
$options = wp_parse_args($options);
|
||||
global $wpcf7_dynamic_fields_config;
|
||||
$type = $options['id'];
|
||||
switch ($type) {
|
||||
case 'dynamichidden': //hiden
|
||||
$description = __('Generate a form-tag for a hidden input field, with a dynamically generated default value.', 'contact-form-7-dynamic-text-extension');
|
||||
break;
|
||||
default:
|
||||
$description = __('Generate a form-tag for a single-line plain text input field, with a dynamically generated default value.', 'contact-form-7-dynamic-text-extension');
|
||||
break;
|
||||
}
|
||||
$input_type = str_replace('dynamic_', '', $type);
|
||||
$utm_source = urlencode(home_url());
|
||||
$description .= sprintf(
|
||||
' %s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" title="%s" target="_blank" rel="noopener">%s</a>.',
|
||||
esc_html__('For more details, see', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_attr__('Go to DTX Documentation website', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_html__('DTX knowledge base', 'contact-form-7-dynamic-text-extension')
|
||||
$description = sprintf(
|
||||
__('Generate a form-tag for %s with a dynamic default value. For more details, see %s fields in the %s.', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_html($wpcf7_dynamic_fields_config[$type]['description']), // dynamic description
|
||||
// Link to specific form-tag documentation
|
||||
sprintf(
|
||||
'<a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/%s?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" title="%s" target="_blank" rel="noopener">%s</a>',
|
||||
esc_attr(str_replace('_', '-', $type)), // URL component
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_attr__('View this form-tag on the DTX Documentation website', 'contact-form-7-dynamic-text-extension'), // Link title
|
||||
esc_html(ucwords(str_replace('_', ' ', $type))) // Link label
|
||||
),
|
||||
// Link to general DTX documentation
|
||||
sprintf(
|
||||
'<a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" title="%s" target="_blank" rel="noopener">%s</a>',
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_attr__('Go to DTX Documentation website', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_html__('DTX knowledge base', 'contact-form-7-dynamic-text-extension')
|
||||
)
|
||||
);
|
||||
|
||||
//Open Form-Tag Generator
|
||||
// Open Form-Tag Generator
|
||||
printf(
|
||||
'<div class="control-box"><fieldset><legend>%s</legend><table class="form-table"><tbody>',
|
||||
'<div class="control-box dtx-taggen"><fieldset><legend>%s</legend><table class="form-table"><tbody>',
|
||||
wp_kses($description, array('a' => array('href' => array(), 'target' => array(), 'rel' => array(), 'title' => array()))) //Tag generator description
|
||||
);
|
||||
|
||||
//Input field - Required checkbox (not available for hidden fields)
|
||||
if ($type != 'dynamichidden') {
|
||||
// Input field - Required checkbox (not available for some fields)
|
||||
if (!in_array($input_type, array('hidden', 'quiz', 'submit', 'reset'))) {
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
|
||||
esc_attr($options['content'] . '-required'), // field id
|
||||
@@ -120,62 +119,253 @@ function wpcf7dtx_tag_generator_dynamictext($contact_form, $options = '')
|
||||
);
|
||||
}
|
||||
|
||||
//Input field - Field Name
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s /></td></tr>',
|
||||
esc_attr($options['content'] . '-name'), // field id
|
||||
esc_html__('Name', 'contact-form-7-dynamic-text-extension'), // field label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'text',
|
||||
'name' => 'name',
|
||||
'id' => $options['content'] . '-name',
|
||||
'class' => 'tg-name oneline'
|
||||
))
|
||||
);
|
||||
// Input field - Field Name (not available for some fields)
|
||||
if (!in_array($input_type, array('submit', 'reset'))) {
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s /></td></tr>',
|
||||
esc_attr($options['content'] . '-name'), // field id
|
||||
esc_html__('Name', 'contact-form-7-dynamic-text-extension'), // field label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'text',
|
||||
'name' => 'name',
|
||||
'id' => $options['content'] . '-name',
|
||||
'class' => 'tg-name oneline',
|
||||
'autocomplete' => 'off'
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
//Input field - Dynamic value
|
||||
// Input field - Dynamic value/options
|
||||
$value_name = __('Dynamic value', 'contact-form-7-dynamic-text-extension');
|
||||
$value_description = __('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension');
|
||||
$value_placeholder = "CF7_GET key='foo'";
|
||||
$value_input_type = '<input %s />';
|
||||
switch ($input_type) {
|
||||
case 'textarea':
|
||||
$value_placeholder = "CF7_get_post_var key='post_excerpt'";
|
||||
$value_input_type = '<textarea %s></textarea>';
|
||||
break;
|
||||
case 'select':
|
||||
$value_name = __('Dynamic options', 'contact-form-7-dynamic-text-extension');
|
||||
$value_description .= ' ' . __('If static text, use one option per line. Can define static key/value pairs using pipes.', 'contact-form-7-dynamic-text-extension');
|
||||
$value_description .= ' ' . __('If shortcode, it must return only option or optgroup HTML and can override the first option and select default settings here.', 'contact-form-7-dynamic-text-extension');
|
||||
$value_placeholder = "hello-world | Hello World" . PHP_EOL . "Foo";
|
||||
$value_input_type = '<textarea %s></textarea>';
|
||||
break;
|
||||
case 'checkbox':
|
||||
case 'radio':
|
||||
$value_name = __('Dynamic options', 'contact-form-7-dynamic-text-extension');
|
||||
$value_description .= ' ' . __('If static text, use one option per line. Can define static key/value pairs using pipes.', 'contact-form-7-dynamic-text-extension');
|
||||
$value_description .= ' ' . __('If shortcode, it must return only option or optgroup HTML.', 'contact-form-7-dynamic-text-extension');
|
||||
$value_placeholder = "hello-world | Hello World" . PHP_EOL . "Foo";
|
||||
$value_input_type = '<textarea %s></textarea>';
|
||||
break;
|
||||
default: // All other text fields
|
||||
break;
|
||||
}
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s /><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td>' . $value_input_type . '<br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
|
||||
esc_attr($options['content'] . '-values'), // field id
|
||||
esc_html__('Dynamic value', 'contact-form-7-dynamic-text-extension'), // field label
|
||||
esc_html($value_name), // field label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'text',
|
||||
'name' => 'values',
|
||||
'id' => $options['content'] . '-values',
|
||||
'class' => 'oneline',
|
||||
'placeholder' => "CF7_GET key='foo'"
|
||||
'class' => 'multiline',
|
||||
'placeholder' => $value_placeholder,
|
||||
'list' => 'dtx-shortcodes'
|
||||
)),
|
||||
esc_html__('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_html__('View DTX shortcode syntax documentation', 'contact-form-7-dynamic-text-extension') //Link label
|
||||
esc_html($value_description),
|
||||
esc_attr($utm_source), // UTM source
|
||||
esc_attr($type), // UTM content
|
||||
esc_html__('View DTX shortcode syntax documentation', 'contact-form-7-dynamic-text-extension') // Link label
|
||||
);
|
||||
|
||||
//Input field - Dynamic placeholder (not available for hidden fields)
|
||||
if ($type != 'dynamichidden') {
|
||||
if ($input_type == 'select') {
|
||||
// Input field - Multiple selections checkbox
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s /><input %s /><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-attribute-placeholder/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
|
||||
esc_attr($options['content'] . '-multiple'), // field id
|
||||
esc_html__('Multiple Options', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'multiple',
|
||||
'id' => $options['content'] . '-multiple',
|
||||
'class' => 'option'
|
||||
)),
|
||||
esc_html__('Allow user to select multiple options', 'contact-form-7-dynamic-text-extension') // checkbox label
|
||||
);
|
||||
|
||||
// Input field - Include blank checkbox
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
|
||||
esc_attr($options['content'] . '-include_blank'), // field id
|
||||
esc_html__('First Option', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'include_blank',
|
||||
'id' => $options['content'] . '-include_blank',
|
||||
'class' => 'include_blankvalue option'
|
||||
)),
|
||||
esc_html__('Insert a blank item as the first option', 'contact-form-7-dynamic-text-extension') // checkbox label
|
||||
);
|
||||
}
|
||||
|
||||
// Input field - Dynamic placeholder (not available for some fields)
|
||||
if (!in_array($input_type, array('hidden', 'radio', 'checkbox', 'quiz', 'submit', 'reset'))) {
|
||||
$placeholder_description = '';
|
||||
if (in_array($input_type, array('select', 'checkbox', 'radio'))) {
|
||||
$placeholder_label = __('First Option Label', 'contact-form-7-dynamic-text-extension');
|
||||
$placeholder_description .= __('Optionally define a label for the first option.', 'contact-form-7-dynamic-text-extension') . ' ';
|
||||
} else {
|
||||
$placeholder_label = __('Dynamic placeholder', 'contact-form-7-dynamic-text-extension');
|
||||
}
|
||||
$placeholder_description .= __('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension');
|
||||
$placeholder_input_type = $input_type == 'textarea' ? $value_input_type : '<input %s />';
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s />' . $placeholder_input_type . '<br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-attribute-placeholder/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
|
||||
esc_attr($options['content'] . '-placeholder'), // field id
|
||||
esc_html__('Dynamic placeholder', 'contact-form-7-dynamic-text-extension'), // field label
|
||||
esc_html($placeholder_label), // field label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'placeholder',
|
||||
'class' => 'option'
|
||||
)),
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'text',
|
||||
'name' => 'dtx-placeholder',
|
||||
'id' => $options['content'] . '-placeholder', // field id
|
||||
'class' => 'oneline dtx-option',
|
||||
'placeholder' => 'CF7_get_post_var key=\'post_title\''
|
||||
'class' => 'multiline dtx-option',
|
||||
'placeholder' => "CF7_get_post_var key='post_title'",
|
||||
'list' => 'dtx-shortcodes'
|
||||
)),
|
||||
esc_html__('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension'), // Small note below input
|
||||
esc_html($placeholder_description), // Small note below input
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_html__('View DTX placeholder documentation', 'contact-form-7-dynamic-text-extension') //Link label
|
||||
);
|
||||
}
|
||||
|
||||
// Additional fields for select regarding placeholder options
|
||||
if ($input_type == 'select') {
|
||||
|
||||
// Input field - Hide Blank Option
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
|
||||
esc_attr($options['content'] . '-dtx_hide_blank'), // field id
|
||||
esc_html__('Hide First Option', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'dtx_hide_blank',
|
||||
'id' => $options['content'] . '-dtx_hide_blank',
|
||||
'class' => 'option'
|
||||
)),
|
||||
esc_html__('Hide the first blank option from being visible in the drop-down', 'contact-form-7-dynamic-text-extension'), // checkbox label
|
||||
esc_html__('Optional. Only works if "First Option" is checked.', 'contact-form-7-dynamic-text-extension'), // Small note below input
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_html__('View Dynamic Select documentation', 'contact-form-7-dynamic-text-extension') //Link label
|
||||
);
|
||||
|
||||
// Input field - Disable Blank Option
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
|
||||
esc_attr($options['content'] . '-dtx_disable_blank'), // field id
|
||||
esc_html__('Disable First Option', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'dtx_disable_blank',
|
||||
'id' => $options['content'] . '-dtx_disable_blank',
|
||||
'class' => 'option'
|
||||
)),
|
||||
esc_html__('Disable the first blank option from being selectable in the drop-down', 'contact-form-7-dynamic-text-extension'), // checkbox label
|
||||
esc_html__('Optional. Only works if "First Option" is checked.', 'contact-form-7-dynamic-text-extension'), // Small note below input
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_html__('View Dynamic Select documentation', 'contact-form-7-dynamic-text-extension') //Link label
|
||||
|
||||
);
|
||||
} elseif (in_array($input_type, array('checkbox', 'radio'))) {
|
||||
// Additional fields for checkboxes and radio buttons
|
||||
|
||||
// Input field - Checkbox Layout Reverse Option
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
|
||||
esc_attr($options['content'] . '-label_first'), // field id
|
||||
esc_html__('Reverse', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'label_first',
|
||||
'id' => $options['content'] . '-label_first',
|
||||
'class' => 'option'
|
||||
)),
|
||||
esc_html__('Put a label first, an input last', 'contact-form-7-dynamic-text-extension') // checkbox label
|
||||
);
|
||||
|
||||
// Input field - Label UI
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
|
||||
esc_attr($options['content'] . '-use_label_element'), // field id
|
||||
esc_html__('Label', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'use_label_element',
|
||||
'id' => $options['content'] . '-use_label_element',
|
||||
'class' => 'option'
|
||||
)),
|
||||
esc_html__('Wrap each item with label element', 'contact-form-7-dynamic-text-extension') // checkbox label
|
||||
);
|
||||
|
||||
// Input field - Exclusive Checkbox
|
||||
if ($input_type == 'checkbox') {
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
|
||||
esc_attr($options['content'] . '-exclusive'), // field id
|
||||
esc_html__('Exclusive', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'exclusive',
|
||||
'id' => $options['content'] . '-exclusive',
|
||||
'class' => 'option'
|
||||
)),
|
||||
esc_html__('Make checkboxes exclusive', 'contact-form-7-dynamic-text-extension') // checkbox label
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Input field - Dynamic default value (not available for some fields)
|
||||
if (in_array($input_type, array('select'))) {
|
||||
$default_input_type = '<input %s />';
|
||||
$default_placeholder = '';
|
||||
if ($input_type == 'checkbox') {
|
||||
$default_input_type = '<textarea %s></textarea>';
|
||||
$default_description = __('Optionally define the default on/off status of the checkboxes by putting a 1 (checked) or 0 (not checked) on each line that corresponds with the options.', 'contact-form-7-dynamic-text-extension') . ' ';
|
||||
$default_placeholder = '0' . PHP_EOL . '1';
|
||||
} else {
|
||||
$default_description = __('Optionally define the option that is selected by default. This can be different than the first [blank] option. If options use key/value pairs, only define the key here.', 'contact-form-7-dynamic-text-extension') . ' ';
|
||||
}
|
||||
$default_description .= __('Can be static text or a shortcode.', 'contact-form-7-dynamic-text-extension');
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s />' . $default_input_type . '<br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
|
||||
esc_attr($options['content'] . '-default'), // field id
|
||||
esc_html__('Selected Default'), // field label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'default',
|
||||
'class' => 'option'
|
||||
)),
|
||||
wpcf7_format_atts(array(
|
||||
'name' => 'dtx-default',
|
||||
'id' => $options['content'] . '-default', // field id
|
||||
'class' => 'oneline dtx-option',
|
||||
'placeholder' => $default_placeholder,
|
||||
'list' => 'dtx-shortcodes'
|
||||
)),
|
||||
esc_html($default_description), // Small note below input
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_html__('View Dynamic Select documentation', 'contact-form-7-dynamic-text-extension') //Link label
|
||||
);
|
||||
}
|
||||
|
||||
//Input field - ID attribute
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><input %s /></td></tr>',
|
||||
@@ -202,8 +392,8 @@ function wpcf7dtx_tag_generator_dynamictext($contact_form, $options = '')
|
||||
))
|
||||
);
|
||||
|
||||
//Input field - Readonly attribute (not available for hidden fields)
|
||||
if ($type != 'dynamichidden') {
|
||||
//Input field - Readonly attribute (not available for hidden, submit, or quiz fields)
|
||||
if (!in_array($input_type, array('hidden', 'submit', 'quiz'))) {
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
|
||||
esc_attr($options['content'] . '-readonly'), // field id
|
||||
@@ -218,25 +408,55 @@ function wpcf7dtx_tag_generator_dynamictext($contact_form, $options = '')
|
||||
);
|
||||
}
|
||||
|
||||
// Page load data attribute (triggers the loading of a frontend script)
|
||||
// Input field - Page load data attribute (triggers the loading of a frontend script)
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label><br /><small>%s <a href="https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tag-attribute-after-page-load/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=form-tag-generator-%s" target="_blank" rel="noopener">%s</a></small></td></tr>',
|
||||
esc_attr($options['content'] . '-frontend'), // field id
|
||||
esc_attr($options['content'] . '-dtx_pageload'), // field id
|
||||
esc_html__('Cache Compatible', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'dtx_pageload',
|
||||
'id' => $options['content'] . '-dtx_pageload',
|
||||
'class' => 'dtx_pageloadvalue option'
|
||||
'class' => 'option'
|
||||
)),
|
||||
esc_html__('Get the dynamic value after the page has loaded', 'contact-form-7-dynamic-text-extension'), // checkbox label
|
||||
esc_html('May impact page performance.', 'contact-form-7-dynamic-text-extension'), // Small note below input
|
||||
esc_html__('May impact page performance.', 'contact-form-7-dynamic-text-extension'), // Small note below input
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
esc_html__('View DTX page load documentation', 'contact-form-7-dynamic-text-extension') //Link label
|
||||
|
||||
);
|
||||
|
||||
// Input field - Akismet module (only available for text, email, and url fields)
|
||||
if (in_array($input_type, array('text', 'email', 'url'))) {
|
||||
switch ($input_type) {
|
||||
case 'email':
|
||||
$akismet_name = 'author_email';
|
||||
$akismet_desc = __("This field requires author's email address", 'contact-form-7-dynamic-text-extension');
|
||||
break;
|
||||
case 'url':
|
||||
$akismet_name = 'author_url';
|
||||
$akismet_desc = __("This field requires author's URL", 'contact-form-7-dynamic-text-extension');
|
||||
break;
|
||||
default:
|
||||
$akismet_name = 'author';
|
||||
$akismet_desc = __("This field requires author's name", 'contact-form-7-dynamic-text-extension');
|
||||
break;
|
||||
}
|
||||
printf(
|
||||
'<tr><th scope="row"><label for="%s">%s</label></th><td><label><input %s />%s</label></td></tr>',
|
||||
esc_attr($options['content'] . '-readonly'), // field id
|
||||
esc_html__('Akismet', 'contact-form-7-dynamic-text-extension'), // field Label
|
||||
wpcf7_format_atts(array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'akismet:' . $akismet_name,
|
||||
'id' => $options['content'] . '-akismet-' . $akismet_name,
|
||||
'class' => 'akismetvalue option'
|
||||
)),
|
||||
esc_html($akismet_desc) // checkbox label
|
||||
);
|
||||
}
|
||||
|
||||
//Close Form-Tag Generator
|
||||
printf(
|
||||
'</tbody></table></fieldset></div><div class="insert-box"><input type="text" name="%s" class="tag code" readonly="readonly" onfocus="this.select()" /><div class="submitbox"><input type="button" class="button button-primary insert-tag" value="%s" /></div><br class="clear" /></div>',
|
||||
|
||||
@@ -50,6 +50,9 @@ add_filter('wpcf7dtx_allow_protocols', 'wpcf7dtx_allow_protocols', 10, 2);
|
||||
*/
|
||||
function wpcf7dtx_sanitize($value = '', $type = 'auto', $protocols = false)
|
||||
{
|
||||
if ($type == 'none') {
|
||||
return $value;
|
||||
}
|
||||
$value = is_string($value) ? $value : strval($value); // Force string value
|
||||
if (!empty($value)) {
|
||||
$type = $type == 'auto' ? wpcf7dtx_detect_value_type($value) : sanitize_text_field($type);
|
||||
@@ -62,6 +65,8 @@ function wpcf7dtx_sanitize($value = '', $type = 'auto', $protocols = false)
|
||||
return sanitize_key($value);
|
||||
case 'slug':
|
||||
return sanitize_title($value);
|
||||
case 'textarea':
|
||||
return sanitize_textarea_field($value);
|
||||
}
|
||||
}
|
||||
return sanitize_text_field($value);
|
||||
@@ -82,6 +87,9 @@ add_filter('wpcf7dtx_sanitize', 'wpcf7dtx_sanitize', 10, 3);
|
||||
*/
|
||||
function wpcf7dtx_escape($value = '', $obfuscate = false, $type = 'auto', $protocols = false)
|
||||
{
|
||||
if ($type == 'none') {
|
||||
return $value;
|
||||
}
|
||||
$value = apply_filters('wpcf7dtx_sanitize', $value, $type); // Sanitize value
|
||||
if (!empty($value)) {
|
||||
if ($obfuscate) {
|
||||
@@ -91,6 +99,8 @@ function wpcf7dtx_escape($value = '', $obfuscate = false, $type = 'auto', $proto
|
||||
switch ($type) {
|
||||
case 'url':
|
||||
return esc_url($value, apply_filters('wpcf7dtx_allow_protocols', $protocols));
|
||||
case 'textarea':
|
||||
return esc_textarea($value);
|
||||
}
|
||||
}
|
||||
return esc_attr($value); // Return attribute value
|
||||
@@ -182,51 +192,449 @@ function wpcf7dtx_get_post_id($post_id, $context = 'dtx')
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Content for Specified Shortcodes
|
||||
* Get Dynamic Value
|
||||
*
|
||||
* Parse a string of content for a specific shortcode to retrieve its attributes and content
|
||||
* @since 3.2.2
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @param string $value The form tag value.
|
||||
* @param WPCF7_FormTag|false $tag Optional. Use to look up default value.
|
||||
* @param string $sanitize Optional. Specify type of sanitization. Default is `auto`.
|
||||
*
|
||||
* @param string $content The content to parse
|
||||
* @param string $tag The shortcode tag
|
||||
*
|
||||
* @return array An associative array with `tag` (string) and `shortcodes` (sequential array). If shortcodes were discovered, each one has keys for `atts` (associative array) and `content` (string)
|
||||
* @return string The dynamic output or the original value, not escaped or sanitized.
|
||||
*/
|
||||
function wpcf7dtx_get_shortcode_atts($content)
|
||||
function wpcf7dtx_get_dynamic($value, $tag = false, $sanitize = 'auto')
|
||||
{
|
||||
$return = array(
|
||||
'tag' => '',
|
||||
'atts' => array()
|
||||
if ($tag !== false) {
|
||||
$default = $tag->get_option('defaultvalue', '', true);
|
||||
if (!$default) {
|
||||
$default = $tag->get_default_option(strval(reset($tag->values)));
|
||||
}
|
||||
$value = wpcf7_get_hangover($tag->name, $default);
|
||||
}
|
||||
$value = apply_filters('wpcf7dtx_sanitize', $value, $sanitize);
|
||||
if (is_string($value) && !empty($value)) {
|
||||
// If a shortcode was passed as the value, evaluate it and use the result
|
||||
$shortcode_tag = '[' . $value . ']';
|
||||
$shortcode_output = do_shortcode($shortcode_tag); //Shortcode value
|
||||
if (is_string($shortcode_output) && $shortcode_output != $shortcode_tag) {
|
||||
return apply_filters('wpcf7dtx_sanitize', $shortcode_output, $sanitize);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Allowed HTML for Form Field Properties
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $type Optional. The type of input for unique properties. Default is `text`.
|
||||
* @param array $extra Optional. A sequential array of properties to additionally include.
|
||||
*
|
||||
* @return array An associative array of allowed properties appropriate for use in `wp_kses()`
|
||||
*/
|
||||
function wpcf7dtx_get_allowed_field_properties($type = 'text', $extra = array())
|
||||
{
|
||||
if (in_array($type, array('option', 'optgroup'))) {
|
||||
return array(
|
||||
'optgroup' => array(
|
||||
'label' => array(),
|
||||
'disabled' => array(),
|
||||
'hidden' => array()
|
||||
),
|
||||
'option' => array(
|
||||
'value' => array(),
|
||||
'selected' => array(),
|
||||
'disabled' => array(),
|
||||
'hidden' => array()
|
||||
)
|
||||
);
|
||||
}
|
||||
$allowed_properties = array(
|
||||
// Global properties
|
||||
'type' => array(),
|
||||
'id' => array(),
|
||||
'name' => array(),
|
||||
'value' => array(),
|
||||
'required' => array(),
|
||||
'class' => array(),
|
||||
'disabled' => array(),
|
||||
'readonly' => array(),
|
||||
'tabindex' => array(),
|
||||
'size' => array(),
|
||||
'title' => array(),
|
||||
'autofocus' => array(),
|
||||
// ARIA properties
|
||||
'aria-invalid' => array(),
|
||||
'aria-describedby' => array(),
|
||||
// DTX properties
|
||||
'data-dtx-value' => array(),
|
||||
);
|
||||
//Search for shortcodes with attributes
|
||||
if (false !== ($start = strpos($content, ' '))) {
|
||||
$return['tag'] = substr($content, 0, $start); //Opens the start tag, assumes there are attributes because of the space
|
||||
if (in_array($type, array('checkbox', 'radio', 'acceptance'))) {
|
||||
// Properties exclusive to checkboxes and radio buttons
|
||||
$allowed_properties['checked'] = array();
|
||||
$allowed_properties['dtx-default'] = array();
|
||||
} elseif (in_array($type, array('number', 'range'))) {
|
||||
// Properties exclusive to number inputs
|
||||
$allowed_properties['step'] = array();
|
||||
} elseif ($type == 'select') {
|
||||
// Properties exclusive to select fields
|
||||
$allowed_properties['multiple'] = array();
|
||||
$allowed_properties['dtx-default'] = array();
|
||||
unset($allowed_properties['type'], $allowed_properties['value'], $allowed_properties['placeholder'], $allowed_properties['size']); // Remove invalid select attributes
|
||||
}
|
||||
if (!in_array($type, array('checkbox', 'radio', 'select', 'acceptance'))) {
|
||||
// Allowed properties for all text-based inputs
|
||||
$allowed_properties['placeholder'] = array();
|
||||
$allowed_properties['autocomplete'] = array();
|
||||
$allowed_properties['minlength'] = array();
|
||||
$allowed_properties['maxlength'] = array();
|
||||
if (in_array($type, array('number', 'range', 'date', 'datetime-local', 'time'))) {
|
||||
// Additional properties for number and date inputs
|
||||
$allowed_properties['min'] = array();
|
||||
$allowed_properties['max'] = array();
|
||||
}
|
||||
if ($type == 'textarea') {
|
||||
// Additional properties exclusive to textarea fields
|
||||
$allowed_properties['cols'] = array();
|
||||
$allowed_properties['rows'] = array();
|
||||
unset($allowed_properties['type'], $allowed_properties['value']); // Remove invalid textarea attributes
|
||||
} elseif (in_array($type, array('text', 'date', 'url', 'tel', 'email', 'password'))) {
|
||||
// Additional properties exclusive to specific text fields
|
||||
$allowed_properties['pattern'] = array();
|
||||
}
|
||||
}
|
||||
if (is_array($extra) && count($extra)) {
|
||||
foreach ($extra as $property) {
|
||||
$allowed_properties[sanitize_title($property)] = array();
|
||||
}
|
||||
}
|
||||
return $allowed_properties;
|
||||
}
|
||||
|
||||
//Parse for shortcode attributes: `shortcode att1='foo' att2='bar'`
|
||||
|
||||
//Chop only the attributes e.g. `att1="foo" att2="bar"`
|
||||
$atts_str = trim(str_replace($return['tag'], '', $content));
|
||||
if (strpos($atts_str, "'") !== false) {
|
||||
$atts = explode("' ", substr(
|
||||
$atts_str,
|
||||
0,
|
||||
-1 //Clip off the last character, which is a single quote
|
||||
));
|
||||
if (is_array($atts) && count($atts)) {
|
||||
foreach ($atts as $att_str) {
|
||||
$pair = explode("='", $att_str);
|
||||
if (is_array($pair) && count($pair) > 1) {
|
||||
$key = sanitize_key(trim($pair[0])); //Validate & normalize the key
|
||||
if (!empty($key)) {
|
||||
$return['atts'][$key] = sanitize_text_field(html_entity_decode($pair[1]));
|
||||
}
|
||||
/**
|
||||
* Returns a formatted string of HTML attributes
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $atts Associative array of attribute name and value pairs
|
||||
*
|
||||
* @return string Formatted HTML attributes with keys and values both escaped
|
||||
*/
|
||||
function wpcf7dtx_format_atts($atts)
|
||||
{
|
||||
if (is_array($atts) && count($atts)) {
|
||||
$sanitized_atts = array();
|
||||
static $boolean_attributes = array(
|
||||
'checked', 'disabled', 'multiple', 'readonly', 'required', 'selected'
|
||||
);
|
||||
foreach ($atts as $key => $value) {
|
||||
$key = sanitize_key(strval($key));
|
||||
if ($key) {
|
||||
if (in_array($key, $boolean_attributes) || is_bool($value)) {
|
||||
if ($value) {
|
||||
$sanitized_atts[$key] = $key;
|
||||
}
|
||||
} elseif ($value && (is_string($value) || is_numeric($value))) {
|
||||
$sanitized_atts[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($sanitized_atts)) {
|
||||
$output = array();
|
||||
foreach ($sanitized_atts as $key => $value) {
|
||||
$output[] = sprintf('%s="%s"', esc_attr($key), esc_attr($value));
|
||||
}
|
||||
return implode(' ', $output);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Input Field HTML
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $atts An associative array of input attributes.
|
||||
*
|
||||
* @return string HTML output of input field
|
||||
*/
|
||||
function wpcf7dtx_input_html($atts)
|
||||
{
|
||||
return sprintf('<input %s />', wpcf7dtx_format_atts($atts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Checkbox Field HTML
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $atts An associative array of select input attributes.
|
||||
* @param string $label_text Optional. The text to display next to the checkbox or radio button.
|
||||
* @param bool $label_ui Optional. If true, will place input and label text inside a `<label>` element. Default is true.
|
||||
* @param bool $reverse Optional. If true, will reverse the order to display the text label first then the button. Has no effect if label text is empty. Default is false.
|
||||
*
|
||||
* @return string HTML output of the checkbox or radio button or empty string on failure.
|
||||
*/
|
||||
function wpcf7dtx_checkbox_html($atts, $label_text = '', $label_ui = true, $reverse = false)
|
||||
{
|
||||
// Default field attributes
|
||||
$atts = array_merge(array('value' => '', 'dtx-default' => ''), array_change_key_case((array)$atts, CASE_LOWER));
|
||||
if ($atts['value'] && $atts['dtx-default'] && $atts['value'] == $atts['dtx-default']) {
|
||||
$atts['checked'] = 'checked';
|
||||
}
|
||||
$input = wpcf7dtx_input_html($atts);
|
||||
if (!empty(trim($label_text))) {
|
||||
$label_el = $label_ui ? 'span' : 'label'; // If not wrapping with a label element, display it next to it
|
||||
$label_text = sprintf(
|
||||
'<%1$s%2$s class="wpcf7-list-item-label">%3$s</%1$s>',
|
||||
$label_el,
|
||||
// If not wrapping with a label element and the element has an ID attribute, add a `for` attribute
|
||||
$label_ui ? '' : (wpcf7dtx_array_has_key('id', $atts) ? ' for="' . esc_attr($atts['id']) . '"' : ''),
|
||||
esc_html($label_text)
|
||||
);
|
||||
if ($reverse) {
|
||||
$html = $label_text . $input;
|
||||
} else {
|
||||
$html = $input . $label_text;
|
||||
}
|
||||
} else {
|
||||
$html = $input;
|
||||
}
|
||||
if ($label_ui) {
|
||||
$html = '<label>' . $html . '</label>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Checkbox Group HTML
|
||||
*
|
||||
* @since 4.0.3
|
||||
*
|
||||
* @param array $atts An associative array of select input attributes.
|
||||
* @param array|string $options Accepts an associative array of key/value pairs to use as the
|
||||
* select option's value/label pairs. It also accepts an associative array of associative
|
||||
* arrays with the keys being used as option group labels and the array values used as that
|
||||
* group's options. It also accepts a string value of HTML already formatted as options or
|
||||
* option groups. It also accepts a string value of a self-closing shortcode that is
|
||||
* evaluated and its output is either options or option groups.
|
||||
* @param bool $label_ui Optional. If true, will place input and label text inside a `<label>` element. Default is true.
|
||||
* @param bool $reverse Optional. If true, will reverse the order to display the text label first then the button. Has no effect if label text is empty. Default is false.
|
||||
*
|
||||
* @return string HTML output of the checkbox or radio button or empty string on failure.
|
||||
*/
|
||||
function wpcf7dtx_checkbox_group_html($atts, $options, $label_ui = false, $reverse = false, $exclusive = false)
|
||||
{
|
||||
$group_html = '';
|
||||
if ($count = count($options)) {
|
||||
// Attributes specific to HTML creation
|
||||
$atts = array_merge(array(
|
||||
'type' => 'checkbox',
|
||||
'id' => '',
|
||||
'name' => '',
|
||||
'value' => '',
|
||||
'dtx-default' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER));
|
||||
|
||||
// Loop all the options
|
||||
$group_html = array();
|
||||
$id_prefix = ($atts['id'] ? $atts['id'] : uniqid($atts['name'] . '_')) . '_'; // Create prefix from passed ID or Name
|
||||
$i = 1;
|
||||
foreach ($options as $value => $label) {
|
||||
$my_atts = array_merge($atts, array(
|
||||
'id' => sanitize_html_class($id_prefix . $i) // Always have unique IDs for group items
|
||||
));
|
||||
$dynamic_value = '';
|
||||
$dynamic_label = $label;
|
||||
if ($value && $label && $value === $label) {
|
||||
// These are identical, just handle it as one, could also be a raw shortcode
|
||||
$dynamic_option = trim(wpcf7dtx_get_dynamic($value, false, 'none')); // Do not sanitize yet, it may have HTML
|
||||
if (is_string($dynamic_option) && !empty($dynamic_option) && strpos($dynamic_option, '{') === 0 && strpos($dynamic_option, '}') === strlen($dynamic_option) - 1) {
|
||||
// If it outputs JSON, try parsing it
|
||||
try {
|
||||
$dynamic_option = json_decode($dynamic_option, true);
|
||||
if (is_array($dynamic_option) && count($dynamic_option)) {
|
||||
$group_html[] = wpcf7dtx_checkbox_group_html(
|
||||
$my_atts,
|
||||
$dynamic_option,
|
||||
$label_ui,
|
||||
$reverse,
|
||||
$exclusive
|
||||
);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Fail quietly
|
||||
if (WP_DEBUG && WP_DEBUG_LOG) {
|
||||
error_log('[Contact Form 7 - Dynamic Text Extension] Error parsing JSON value');
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
continue; // Continue with next iteration
|
||||
} elseif (is_string($dynamic_option) && !empty($dynamic_option) && esc_html($dynamic_option) != $dynamic_option) {
|
||||
$group_html[] = force_balance_tags($dynamic_option); // If it outputs HTML, escape and use them as-is
|
||||
$i++;
|
||||
continue; // Continue with next iteration
|
||||
} else {
|
||||
$dynamic_value = $dynamic_option;
|
||||
$dynamic_label = $dynamic_option;
|
||||
}
|
||||
} else {
|
||||
// These are different, could be raw shortcodes
|
||||
$dynamic_value = wpcf7dtx_get_dynamic($value, false);
|
||||
$dynamic_label = wpcf7dtx_get_dynamic($label, false);
|
||||
}
|
||||
// This could be a single??
|
||||
$class = array('wpcf7-list-item');
|
||||
$class[] = sanitize_html_class('wpcf7-list-item-' . $i);
|
||||
if ($i === 1) {
|
||||
$class[] = 'first';
|
||||
}
|
||||
if ($i === $count) {
|
||||
$class[] = 'last';
|
||||
}
|
||||
if ($exclusive) {
|
||||
$class[] = 'wpcf7-exclusive-checkbox';
|
||||
}
|
||||
if ($dynamic_value && $atts['dtx-default'] && $dynamic_value == $atts['dtx-default']) {
|
||||
$my_atts['checked'] = 'checked';
|
||||
}
|
||||
$group_html[] = sprintf(
|
||||
'<span class="%s">%s</span>',
|
||||
esc_attr(implode(' ', $class)),
|
||||
wpcf7dtx_checkbox_html(
|
||||
// Overwrite name attribute
|
||||
array_merge($my_atts, array(
|
||||
'name' => $atts['type'] == 'radio' || $exclusive || $count === 1 ? $atts['name'] : $atts['name'] . '[]', // if there are multiple checkboxes and they aren't exclusive, names are an array
|
||||
'value' => $dynamic_value
|
||||
)),
|
||||
$dynamic_label,
|
||||
$label_ui,
|
||||
$reverse
|
||||
)
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
$group_html = implode('', $group_html);
|
||||
}
|
||||
return $group_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Textarea Field HTML
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $atts An associative array of textarea field attributes.
|
||||
*
|
||||
* @return string HTML output of textarea field
|
||||
*/
|
||||
function wpcf7dtx_textarea_html($atts)
|
||||
{
|
||||
// Attributes specific to HTML creation
|
||||
$atts = array_merge(array('value' => ''), array_change_key_case((array)$atts, CASE_LOWER));
|
||||
return sprintf(
|
||||
'<textarea %s>%s</textarea>',
|
||||
wpcf7dtx_format_atts($atts),
|
||||
apply_filters('wpcf7dtx_escape', $atts['value'], false, 'textarea')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Select Field HTML
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $atts An associative array of select input attributes.
|
||||
* @param array|string $options Accepts an associative array of key/value pairs to use as the
|
||||
* select option's value/label pairs. It also accepts an associative array of associative
|
||||
* arrays with the keys being used as option group labels and the array values used as that
|
||||
* group's options. It also accepts a string value of HTML already formatted as options or
|
||||
* option groups. It also accepts a string value of a self-closing shortcode that is
|
||||
* evaluated and its output is either options or option groups.
|
||||
* @param bool $hide_blank Optional. If true, the first blank placeholder option will have the `hidden` attribute added to it. Default is false.
|
||||
* @param bool $disable_blank Optional. If true, the first blank placeholder option will have the `disabled` attribute added to it. Default is false.
|
||||
*
|
||||
* @return string HTML output of select field
|
||||
*/
|
||||
function wpcf7dtx_select_html($atts, $options, $hide_blank = false, $disable_blank = false)
|
||||
{
|
||||
// Attributes specific to HTML creation
|
||||
$atts = array_merge(array('placeholder' => '', 'dtx-default' => ''), array_change_key_case((array)$atts, CASE_LOWER));
|
||||
$options_html = ''; // Open options HTML
|
||||
|
||||
// If using a placeholder, use it as the text of the first option
|
||||
if ($atts['placeholder']) {
|
||||
$options_html .= sprintf(
|
||||
'<option value=""%s%s%s>%s</option>',
|
||||
empty($atts['dtx-default']) ? ' selected' : '',
|
||||
$hide_blank ? ' hidden' : '',
|
||||
$disable_blank ? ' disabled' : '',
|
||||
apply_filters('wpcf7dtx_escape', $atts['placeholder'])
|
||||
);
|
||||
}
|
||||
if (is_array($options) && count($options)) {
|
||||
//Check if using option groups
|
||||
if (is_array(array_values($options)[0])) {
|
||||
foreach ($options as $group_name => $opt_group) {
|
||||
$options_html .= sprintf('<optgroup label="%s">', esc_attr(apply_filters('wpcf7dtx_escape', wpcf7dtx_get_dynamic($group_name)))); // Open option group
|
||||
foreach ($opt_group as $option_value => $option_label) {
|
||||
// Check if option values and groups are dynamic
|
||||
$dynamic_option_value = wpcf7dtx_get_dynamic($option_value);
|
||||
$options_html .= sprintf(
|
||||
'<option value="%1$s"%3$s>%2$s</option>',
|
||||
esc_attr(apply_filters('wpcf7dtx_escape', $dynamic_option_value)),
|
||||
esc_html(apply_filters('wpcf7dtx_escape', wpcf7dtx_get_dynamic($option_label))),
|
||||
$atts['dtx-default'] == $dynamic_option_value ? ' selected' : ''
|
||||
);
|
||||
}
|
||||
$options_html .= '</optgroup>'; // Close option group
|
||||
}
|
||||
} else {
|
||||
$allowed_html = wpcf7dtx_get_allowed_field_properties('option');
|
||||
foreach ($options as $option_value => $option_label) {
|
||||
if ($option_value === $option_label) {
|
||||
// These are identical, just handle it as one, could also be a raw shortcode
|
||||
$dynamic_option = trim(wpcf7dtx_get_dynamic($option_value, false, 'none')); // Do not sanitize yet, it may have HTML
|
||||
if (is_string($dynamic_option) && !empty($dynamic_option) && (strpos($dynamic_option, '<option') === 0 || stripos($dynamic_option, '<optgroup') === 0)) {
|
||||
$options_html .= wp_kses($dynamic_option, $allowed_html); // If it outputs HTML, escape and use them as-is
|
||||
} elseif ($dynamic_option) {
|
||||
// Just output the option
|
||||
$dynamic_option = apply_filters('wpcf7dtx_escape', $dynamic_option);
|
||||
$options_html .= sprintf(
|
||||
'<option value="%1$s"%3$s>%2$s</option>',
|
||||
esc_attr($dynamic_option),
|
||||
esc_html($dynamic_option),
|
||||
$atts['dtx-default'] == $dynamic_option ? ' selected' : ''
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$dynamic_option_value = wpcf7dtx_get_dynamic($option_value, false);
|
||||
$options_html .= sprintf(
|
||||
'<option value="%1$s"%3$s>%2$s</option>',
|
||||
esc_attr(apply_filters('wpcf7dtx_escape', $dynamic_option_value)),
|
||||
esc_html(apply_filters('wpcf7dtx_escape', wpcf7dtx_get_dynamic($option_label))),
|
||||
$atts['dtx-default'] == $dynamic_option_value ? ' selected' : ''
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (is_string($options) && !empty($options = trim($options))) {
|
||||
$allowed_html = wpcf7dtx_get_allowed_field_properties('option');
|
||||
// If options were passed as a string, go ahead and use them
|
||||
if (strpos($options, '<option') === 0 || stripos($options, '<optgroup') === 0) {
|
||||
$options_html .= wp_kses($options, $allowed_html);
|
||||
} else {
|
||||
// If a shortcode was passed as the options, evaluate it and use the result
|
||||
$shortcode_output = wpcf7dtx_get_dynamic($options);
|
||||
if (is_string($shortcode_output) && !empty($shortcode_output) && (strpos($shortcode_output, '<option') === 0) || strpos($shortcode_output, '<optgroup') === 0) {
|
||||
$options_html .= wp_kses($shortcode_output, $allowed_html);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sprintf('<select %s>%s</select>', wpcf7dtx_format_atts($atts), $options_html);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,21 +661,3 @@ function wpcf7dtx_array_has_key($key, $array = array(), $default = '')
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (!function_exists('array_key_first')) {
|
||||
/**
|
||||
* Gets the first key of an array
|
||||
*
|
||||
* Gets the first key of the given array without affecting the internal array pointer.
|
||||
*
|
||||
* @param array $array
|
||||
* @return int|string|null
|
||||
*/
|
||||
function array_key_first($array = array())
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
return $key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Add Frontend Validation Messages
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array An associative array of messages
|
||||
*
|
||||
* @return array A modified associative array of messages
|
||||
*/
|
||||
function wpcf7dtx_messages($messages)
|
||||
{
|
||||
return array_merge($messages, array(
|
||||
'dtx_invalid_email' => array(
|
||||
'description' => __('There is a field with an invalid email address', 'contact-form-7-dynamic-text-extension'),
|
||||
'default' => __('Please enter a valid email address.', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dtx_invalid_tel' => array(
|
||||
'description' => __('There is a field with an invalid phone number', 'contact-form-7-dynamic-text-extension'),
|
||||
'default' => __('Please enter a valid phone number.', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dtx_invalid_number' => array(
|
||||
'description' => __('There is a field with an invalid number', 'contact-form-7-dynamic-text-extension'),
|
||||
'default' => __('Please enter a valid number.', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
'dtx_invalid_date' => array(
|
||||
'description' => __('There is a field with an invalid date', 'contact-form-7-dynamic-text-extension'),
|
||||
'default' => __('Please enter a valid date.', 'contact-form-7-dynamic-text-extension')
|
||||
),
|
||||
));
|
||||
}
|
||||
add_filter('wpcf7_messages', 'wpcf7dtx_messages');
|
||||
|
||||
/**
|
||||
* Validate DTX Form Fields
|
||||
*
|
||||
* Frontend validation for DTX form tags
|
||||
*
|
||||
* @param WPCF7_Validation $result the current validation result object
|
||||
* @param WPCF7_FormTag $tag the current form tag being filtered for validation
|
||||
*
|
||||
* @return WPCF7_Validation a possibly modified validation result object
|
||||
*/
|
||||
function wpcf7dtx_validation_filter($result, $tag)
|
||||
{
|
||||
$type = str_replace(array('dynamic_', 'dynamic'), '', $tag->basetype);
|
||||
if (empty($tag->name) || in_array($type, array('hidden', 'submit', 'reset'))) {
|
||||
return $result; // Bail early for tags without names or if a specific type
|
||||
}
|
||||
|
||||
// Get the value
|
||||
$user_value = wpcf7dtx_array_has_key($tag->name, $_POST);
|
||||
if (is_array($user_value)) {
|
||||
$selection_count = count($user_value);
|
||||
if (!wpcf7_form_tag_supports($tag->type, 'selectable-values')) {
|
||||
// Field passed selectable values when it's doesn't support them
|
||||
$result->invalidate($tag, wpcf7_get_message('validation_error'));
|
||||
return $result;
|
||||
} elseif ($selection_count > 1) {
|
||||
if (!wpcf7_form_tag_supports($tag->type, 'multiple-controls-container')) {
|
||||
// Field passed multiple values when it's doesn't support them
|
||||
$result->invalidate($tag, wpcf7_get_message('validation_error'));
|
||||
return $result;
|
||||
}
|
||||
foreach ($user_value as $selection) {
|
||||
// Validate each selected choice
|
||||
$result = wpcf7dtx_validate_value($result, sanitize_textarea_field(strval($selection)), $tag, $type);
|
||||
if (!$result->is_valid($tag->name)) {
|
||||
return $result; // Return early if any are invalid
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
$user_value = sanitize_text_field(strval(implode(' ', $user_value)));
|
||||
} elseif ($type == 'textarea') {
|
||||
$user_value = sanitize_textarea_field(strval($user_value));
|
||||
} else {
|
||||
$user_value = sanitize_text_field(strval($user_value));
|
||||
}
|
||||
// Validate and return
|
||||
return wpcf7dtx_validate_value($result, $user_value, $tag, $type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate Single Value
|
||||
*
|
||||
* @param WPCF7_Validation $result the current validation result object
|
||||
* @param string $value the current value being validated, sanitized
|
||||
* @param WPCF7_FormTag $tag the current form tag being filtered for validation
|
||||
* @param string $type Optional. The type of the current form tag. Default is blank for lookup.
|
||||
*
|
||||
* @return WPCF7_Validation a possibly modified validation result object
|
||||
*/
|
||||
function wpcf7dtx_validate_value($result, $value, $tag, $type = '')
|
||||
{
|
||||
$type = $type ? $type : str_replace(array('dynamic_', 'dynamic'), '', $tag->basetype);
|
||||
|
||||
// Validate required fields for value
|
||||
if ($tag->is_required() && empty($value)) {
|
||||
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Validate value by type
|
||||
if (!empty($value)) {
|
||||
switch ($type) {
|
||||
case 'email':
|
||||
if (!wpcf7_is_email($value)) {
|
||||
$result->invalidate($tag, wpcf7_get_message('dtx_invalid_email'));
|
||||
return $result;
|
||||
}
|
||||
break;
|
||||
case 'tel':
|
||||
if (!wpcf7_is_tel($value)) {
|
||||
$result->invalidate($tag, wpcf7_get_message('dtx_invalid_tel'));
|
||||
return $result;
|
||||
}
|
||||
break;
|
||||
case 'number':
|
||||
case 'range':
|
||||
if (!wpcf7_is_number($value)) {
|
||||
$result->invalidate($tag, wpcf7_get_message('dtx_invalid_number'));
|
||||
return $result;
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
if (!wpcf7_is_date($value)) {
|
||||
$result->invalidate($tag, wpcf7_get_message('dtx_invalid_date'));
|
||||
return $result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Finish validating text-based inputs
|
||||
$maxlength = $tag->get_maxlength_option();
|
||||
$minlength = $tag->get_minlength_option();
|
||||
if ($maxlength && $minlength && $maxlength < $minlength) {
|
||||
$maxlength = $minlength = null;
|
||||
}
|
||||
$code_units = wpcf7_count_code_units($value);
|
||||
if (false !== $code_units) {
|
||||
if ($maxlength && $maxlength < $code_units) {
|
||||
$result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
|
||||
return $result;
|
||||
} elseif ($minlength && $code_units < $minlength) {
|
||||
$result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backend Mail Configuration Validation
|
||||
*
|
||||
* Validate dynamic form tags used in mail configuration.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param WPCF7_ConfigValidator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wpcf7dtx_validate($validator)
|
||||
{
|
||||
if (!$validator->is_valid()) {
|
||||
$contact_form = null;
|
||||
$form_tags = null;
|
||||
foreach ($validator->collect_error_messages() as $component => $errors) {
|
||||
$components = explode('.', $component);
|
||||
if (count($components) === 2 && strpos($components[0], 'mail') === 0 && in_array($components[1], array('sender', 'recipient', 'additional_headers'))) {
|
||||
foreach ($errors as $error) {
|
||||
// Focus on email fields that flag the invalid mailbox syntax warning, have to test link because code isn't sent and message could be in any language
|
||||
if (strpos(wpcf7dtx_array_has_key('link', $error), 'invalid-mailbox-syntax') !== false) {
|
||||
if (is_null($contact_form)) {
|
||||
$contact_form = $validator->contact_form();
|
||||
}
|
||||
if (is_null($form_tags)) {
|
||||
$form_tags = wpcf7_scan_form_tags();
|
||||
}
|
||||
$raw_value = $contact_form->prop($components[0])[$components[1]];
|
||||
foreach ($form_tags as $tag) {
|
||||
if (!empty($tag->name)) {
|
||||
// Check if this form tag is in the raw value
|
||||
$form_tag = '[' . $tag->name . ']';
|
||||
if (strpos($raw_value, $form_tag) !== false && in_array($tag->basetype, array_keys(wpcf7dtx_config()))) {
|
||||
$validator->remove_error($component, 'invalid_mailbox_syntax'); // Remove error, this is ours to handle now
|
||||
$utm_source = urlencode(home_url());
|
||||
if (!in_array($tag->basetype, array('dynamic_hidden', 'dynamic_email'))) {
|
||||
$validator->add_error($component, 'invalid_mailbox_syntax', array(
|
||||
'message' => __('Only email, dynamic email, hidden, or dynamic hidden form tags can be used for email addresses.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-invalid_mailbox_syntax#valid-form-tags', $utm_source))
|
||||
));
|
||||
} else {
|
||||
$dynamic_value = wpcf7dtx_get_dynamic(false, $tag); // Get the dynamic value of this tag
|
||||
if (empty($dynamic_value) && $tag->basetype == 'dynamic_hidden') {
|
||||
$validator->add_error($component, 'maybe_empty', array(
|
||||
'message' => __('The dynamic hidden form tag must have a default value.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-maybe_empty#maybe-empty', $utm_source))
|
||||
));
|
||||
} elseif (empty($dynamic_value) && !$tag->is_required()) {
|
||||
$validator->add_error($component, 'maybe_empty', array(
|
||||
'message' => __('The dynamic form tag must be required or have a default value.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-maybe_empty#maybe-empty', $utm_source))
|
||||
));
|
||||
} elseif (!empty($dynamic_value)) {
|
||||
if (!wpcf7_is_email($dynamic_value)) {
|
||||
$validator->add_error($component, 'invalid_mailbox_syntax', array(
|
||||
'message' => __('The default dynamic value does not result in a valid email address.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-invalid_mailbox_syntax#invalid-email-address', $utm_source))
|
||||
));
|
||||
} elseif ($component[1] == 'sender' && !wpcf7_is_email_in_site_domain($dynamic_value)) {
|
||||
$validator->add_error($component, 'email_not_in_site_domain', array(
|
||||
'message' => __('The dynamic email address for the sender does not belong to the site domain.', 'contact-form-7-dynamic-text-extension'),
|
||||
'link' => esc_url(sprintf('https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/configuration-errors/?utm_source=%s&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=config-error-email_not_in_site_domain#invalid-site-domain', $utm_source))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action('wpcf7_config_validator_validate', 'wpcf7dtx_validate');
|
||||
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
||||
@@ -3,9 +3,9 @@ Contributors: sevenspark, tessawatkinsllc
|
||||
Donate link: https://just1voice.com/donate/
|
||||
Tags: Contact Form 7, autofill, prepopulate, input, form field, contact form, text, hidden, input, dynamic, GET, POST, title, slug, auto-fill, pre-populate
|
||||
Tested up to: 6.3
|
||||
Stable tag: 3.5.4
|
||||
Stable tag: 4.1.0
|
||||
|
||||
This plugin provides additional form tags for the Contact Form 7 plugin. It allows dynamic generation of content for text or hidden input fields using any shortcode.
|
||||
This plugin provides additional form tags for the Contact Form 7 plugin. It allows dynamic generation of content for text-based input fields like text, hidden, and email, checkboxes, radio buttons, and drop-down selections using any shortcode.
|
||||
|
||||
== Description ==
|
||||
|
||||
@@ -25,11 +25,25 @@ Contact Form 7 is an excellent WordPress plugin and one of the top choices of fr
|
||||
* Getting custom theme modifications
|
||||
* Any value using custom shortcodes
|
||||
|
||||
For over 10 years, DTX only handled `<input type="text" />` and `<input type="hidden" />` form fields, but version 4 finally introduces more:
|
||||
|
||||
* email
|
||||
* URL
|
||||
* tel (for phone numbers)
|
||||
* number
|
||||
* range (slider)
|
||||
* textarea (multiline text)
|
||||
* drop-down menu (select field)
|
||||
* checkboxes
|
||||
* radio buttons
|
||||
* date
|
||||
* submit (yes, a submit button where you can have dynamic text!)
|
||||
|
||||
The possibilities are endless!
|
||||
|
||||
## WHAT DOES IT DO? ##
|
||||
|
||||
DTX comes with several built-in shortcodes that will allow the contact form to be populated from HTTPS GET variable or any info from the `get_bloginfo()` function, among others. See below for included shortcodes.
|
||||
DTX provides flexibility to WordPress users in creating dynamic forms in Contact Form 7. DTX comes with several built-in shortcodes that will allow the contact form to be populated from HTTPS GET variable or any info from the `get_bloginfo()` function, among others. See below for included shortcodes.
|
||||
|
||||
Don't see the shortcode you need on the list? You can write a [custom one](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/custom-shortcodes/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)! Any shortcode that returns a string or numeric value can be used here. The included shortcodes just cover the most common scenarios, but DTX provides the flexibility for you to grab any value you have access to programmatically.
|
||||
|
||||
@@ -341,9 +355,20 @@ This method is the most involved as it requires you to be familiar with the proc
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. Screenshot of the form tag buttons in the form editor of Contact Form 7. A red square highlights the addition of two new buttons for "dynamic text" and "dynamic hidden"
|
||||
1. Screenshot of the form tag buttons in the form editor of Contact Form 7. The dynamic buttons appear in purple instead of blue to visually set them apart.
|
||||
2. The form tag generator screen for the dynamic text form tag
|
||||
3. The form tag generator screen for the dynamic hidden form tag
|
||||
4. The form tag generator screen for the dynamic email form tag
|
||||
5. The form tag generator screen for the dynamic URL form tag
|
||||
6. The form tag generator screen for the dynamic phone number (tel) form tag
|
||||
7. The form tag generator screen for the dynamic number spinbox form tag
|
||||
8. The form tag generator screen for the dynamic sliding range form tag
|
||||
9. The form tag generator screen for the dynamic textarea form tag
|
||||
10. The form tag generator screen for the dynamic drop-down menu (select) form tag
|
||||
11. The form tag generator screen for the dynamic checkboxes form tag
|
||||
12. The form tag generator screen for the dynamic radio buttons form tag
|
||||
13. The form tag generator screen for the dynamic date form tag
|
||||
14. The form tag generator screen for the dynamic submit form tag
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
@@ -351,111 +376,53 @@ Please check out the [FAQ on our website](https://aurisecreative.com/docs/contac
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 3.5.3 =
|
||||
Optimized JavaScript used in cache compatibility mode.
|
||||
= 4.1.0 =
|
||||
Extend functionality without losing your work!
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 3.5.4 =
|
||||
= 4.1.0 =
|
||||
|
||||
* Fix: Updated JavaScript to prevent cacheable fields from making unnecessary AJAX requests
|
||||
* Feature: Looks for a `dtx.php` file in the `wp_content` directory to maybe load custom shortcodes, [see support thread](https://wordpress.org/support/topic/how-to-avoid-custom-shortcodes-being-overwritten-on-updates/)
|
||||
* Feature: Looks for a `dtx.php` file in the current active theme's directory to maybe load custom shortcodes, [see support thread](https://wordpress.org/support/topic/how-to-avoid-custom-shortcodes-being-overwritten-on-updates/)
|
||||
* Feature: Looks for a `dtx.php` file in the current active theme's parent directory to maybe load custom shortcodes, [see support thread](https://wordpress.org/support/topic/how-to-avoid-custom-shortcodes-being-overwritten-on-updates/)
|
||||
* Fix: addressed user reported bug, [see support thread](https://wordpress.org/support/topic/fatal-error-v4-0-3/)
|
||||
|
||||
= 3.5.3 =
|
||||
= 4.0.3 =
|
||||
|
||||
* Update: removed the use of sessions, [see support thread](https://wordpress.org/support/topic/add-option-to-disable-session-data/)
|
||||
* Feature: Added `exclusive` option to checkbox tag generator
|
||||
* Fix: addressed bug that put all dynamic checkbox/radio options into one
|
||||
* Fix: addressed bug in frontend validator for multiple selected values
|
||||
|
||||
= 3.5.2 =
|
||||
= 4.0.2 =
|
||||
|
||||
* Fix: Updated the `CF7_URL` shortcode to only use `network_home_url()` for multisite installs that do not use subdomains, and use `home_url()` for all others to [maybe address this support thread](https://wordpress.org/support/topic/cf7_url-return-only-domain-and-not-subdomain/)
|
||||
* Fix: Removed a lingering debug call
|
||||
* Fix: addressed bug that put all dynamic select options into one, [see support thread](https://wordpress.org/support/topic/dynamic-select-get-option-values-from-shortcode/)
|
||||
* Update: sanitizing and escaping filters now accept `none` as value for `$type` to bypass. Use with caution.
|
||||
|
||||
= 3.5.1 =
|
||||
= 4.0.1 =
|
||||
|
||||
* Fix: fixed bug so tag generator for dynamic fields work on "Add New Contact Form" page of Contact Form 7
|
||||
* Updated: Updated text in tag generator for cache compatible checkbox and added link to documentation
|
||||
* Fix: addressed bug that prevented translation for cache compatibility description
|
||||
|
||||
= 3.5.0 =
|
||||
= 4.0.0 =
|
||||
|
||||
* Feature: Added the `dtx_pageload` form tag attribute for cache compatibility. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tag-attribute-after-page-load/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Fix: Updated to be compatible with WordPress version 6.3
|
||||
* Fix: Addressed a bug where `scheme` in `CF7_URL part='scheme'` was incorrectly sanitizing as URL instead of text
|
||||
* Fix: Fixed `wp_kses()` in tag generator that stripped out link opening in new tab
|
||||
* Update: `CF7_get_current_var` utilizes PHP session variables where appropriate
|
||||
* Update: All JavaScript assets will load with the `defer` strategy in the footer in [WordPress 6.3](https://make.wordpress.org/core/2023/07/14/registering-scripts-with-async-and-defer-attributes-in-wordpress-6-3/)
|
||||
|
||||
= 3.4.0 =
|
||||
|
||||
* Feature: Added the `CF7_get_current_var` shortcode, [see support thread for user request](https://wordpress.org/support/topic/wrong-page-title-7/). For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-current-variables/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Fix: Updated the `CF7_URL` shortcode to no longer check for ports since that's handled in `network_home_url()` function, [see support thread](https://wordpress.org/support/topic/version-3-3-0-breaking/)
|
||||
|
||||
= 3.3.0 =
|
||||
|
||||
* Feature: Added the `CF7_get_cookie` shortcode. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-cookie/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: Added the `CF7_get_taxonomy` shortcode. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-taxonomy/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: Added the `CF7_get_theme_option` shortcode. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-theme-option/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: Added `wpcf7dtx_sanitize` filter that sanitizes attribute values in built-in shortcodes
|
||||
* Feature: Added `wpcf7dtx_escape` filter that escapes values in built-in shortcodes
|
||||
* Feature: Added `wpcf7dtx_allow_protocols` filter to customize allowed protocols in escaping URLs in built-in shortcodes
|
||||
* Fix: Updated how plugin gets dynamic value in form tags, now uses `wpcf7dtx_get_dynamic()` function
|
||||
* Fix: Added case-insensitive ID in `CF7_get_post_var`
|
||||
* Fix: Sanitizes post variable keys as keys in `wpcf7dtx_get_post_var()`
|
||||
* Fix: Updated `wpcf7dtx_get_post_id()` to pull from "the loop" if `$post` is unavailable and now used consistently across built-in shortcodes
|
||||
* Fix: Updated tag markup to be compatible with Contact Form 7 version 5.6 Beta for successful form validation, [see support thread](https://wordpress.org/support/topic/required-field-no-error-is-output-when-validating-when-field-is-empty/)
|
||||
* Fix: Updated the `CF7_URL` shortcode to use `network_home_url()`, [see support thread](https://wordpress.org/support/topic/current-url-not-working/)
|
||||
* Fix: Updated GUID function to return appropriately escaped values
|
||||
* Fix: Updated all existing built-in shortcodes to use the the sanitizing, escaping, and obfuscating shortcodes, [see support thread](https://wordpress.org/support/topic/cant-get-obfuscate-to-work/)
|
||||
* Fix: Marked compatible with WordPress core version 6.2.
|
||||
|
||||
= 3.2 =
|
||||
|
||||
* Feature: Add optional 'part' parameter to CF7_URL shortcode to retrieve Host, Query, or Path from current URL
|
||||
* Updated minimum PHP requirement to 7.4 moving forward
|
||||
* Update branding assets
|
||||
* Update Tested Up To to 6.1.1
|
||||
* Plugin will now be jointly maintained by [SevenSpark](https://sevenspark.com/) and [AuRise Creative](https://aurisecreative.com)
|
||||
|
||||
= 3.1.3 =
|
||||
|
||||
* Fix: Fixed the syntax error that reappeared in 3.1.2.
|
||||
|
||||
= 3.1.2 =
|
||||
|
||||
**Release Date: January 27, 2023**
|
||||
|
||||
* Fix: updated the text domain to match the plugin slug
|
||||
* Fix: updated all of the translated strings to match
|
||||
|
||||
= 3.1.1 =
|
||||
|
||||
**Release Date: January 26, 2023**
|
||||
|
||||
* Fix: Fixed the syntax error: Parse error: syntax error, unexpected `)` in /wp-content/plugins/contact-form-7-dynamic-text extension/includes/admin.php on line 212
|
||||
|
||||
= 3.1.0 =
|
||||
|
||||
**Release Date: January 25, 2023**
|
||||
|
||||
* Feature: Added the `CF7_get_attachment` shortcode. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-media-attachment/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: Added the `CF7_guid` shortcode. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-guid/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
* Feature: Added the dynamic placeholder option to the dynamic form tags that allows you to specify dynamic or static placeholder content while also setting dynamic values. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-attribute-placeholder/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: Added a "required" dynamic hidden tag (e.g., `[dynamichidden* ...]`). It is identical to the original dynamic hidden tag (as in the field is not actually validated as required because it is hidden); it just doesn't break your website if you use it. This feature was requested by a user.
|
||||
* Feature: Added the `obfuscate` attribute to all included shortcodes
|
||||
|
||||
= 3.0.0 =
|
||||
|
||||
**Release Date: January 17, 2023**
|
||||
|
||||
* Major: Plugin was adopted by AuRise Creative
|
||||
* Major: All functions use the `wpcf7dtx_` prefix
|
||||
* Feature: Added a `post_id` key for the `CF7_get_post_var` shortcode so you can specify a different post
|
||||
* Feature: Updated the `CF7_get_current_user` shortcode to be able to pull data from user metadata too
|
||||
* Feature: Added the "obfuscate" option to `CF7_get_custom_field` shortcode
|
||||
* Feature: Added the "placeholder" checkbox option to the `dynamictext` tag
|
||||
* Fix: Added additional validation for post ID input
|
||||
* Fix: Added additional validation for the `key` attribute in the `CF7_GET` and `CF7_POST` shortcodes
|
||||
* Fix: Shortcode keys are normalized into lowercase before processing
|
||||
* Security: Sanitizing URLs for the `CF7_URL` and `CF7_referrer` shortcode outputs
|
||||
* Feature/Security: Added a `allowed_protocols` attribute to the `CF7_URL` and `CF7_referrer` shortcodes that defaults to `http,https`
|
||||
* Major: modified function names
|
||||
* Major: deprecated `dynamictext` and `dynamichidden` form tags in favor of `dynamic_text` and `dynamic_hidden`. For more information, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_email` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-email/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_url` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-url/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_tel` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-tel/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_number` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-number/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_range` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-range/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_textarea` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-textarea/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_select` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_radio` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-radio/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_date` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-date/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dynamic_submit` form tag. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-submit/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dtx_hide_blank` form tag attribute for `dynamic_select`. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: introduced `dtx_disable_blank` form tag attribute for `dynamic_select`. For usage details, see the [knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/form-tags/dynamic-select/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: added mail validation for `dynamic_email` and `dynamic_hidden` for backend configuration. For more information, see the [FAQ](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/frequently-asked-questions/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme)
|
||||
* Feature: added the Akismet feature to DTX text, email, and URL form tags.
|
||||
* Update: adjusted how queued values were sent for cache compatibility mode to allow for multiline values in textareas
|
||||
* Removed unused utility functions
|
||||
|
||||
= Older Releases =
|
||||
|
||||
|
||||
Reference in New Issue
Block a user