rebase on oct-10-2023
This commit is contained in:
@@ -0,0 +1,226 @@
|
||||
var $ = jQuery.noConflict(),
|
||||
dtx = {
|
||||
queue: [],
|
||||
init: function() {
|
||||
var $inputs = $('input.dtx-pageload[data-dtx-value]');
|
||||
if ($inputs.length) {
|
||||
// If this is any of our built-in shortcodes, see if there's any that can be duplicated via client side
|
||||
$inputs.each(function(i, el) {
|
||||
var $input = $(el),
|
||||
raw_value = $input.attr('data-dtx-value'),
|
||||
v = decodeURIComponent(raw_value).split(' ');
|
||||
if (v.length) {
|
||||
var tag = v[0],
|
||||
atts = {};
|
||||
if (v.length > 1) {
|
||||
for (var x = 1; x < v.length; x++) {
|
||||
var att = v[x].split('=');
|
||||
if (att.length === 2) {
|
||||
var key = att[0];
|
||||
atts[key] = 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') && atts.key == 'url') {
|
||||
value = dtx.current_url(atts);
|
||||
} else {
|
||||
return; // Do nothing, current page variables are safe to cache, just use the value that was calculated by server
|
||||
}
|
||||
break;
|
||||
case 'CF7_get_post_var': // Current post variables are safe to cache
|
||||
case 'CF7_get_custom_field': // Meta data is safe to cache
|
||||
case 'CF7_get_taxonomy': // Terms are safe to cache
|
||||
case 'CF7_get_attachment': // Media attachment info is safe to cache
|
||||
case 'CF7_bloginfo': // Site info is safe to cache
|
||||
case 'CF7_get_theme_option': // Theme options are safe to cache
|
||||
return; // Do nothing, just use the value that was calculated by server
|
||||
default:
|
||||
if (tag) {
|
||||
// Queue the requests for an AJAX call at the end of init
|
||||
dtx.queue.push({ 'value': raw_value, 'multiline': $input.is('textarea') });
|
||||
}
|
||||
return; // Don't continue after queuing it for AJAX
|
||||
}
|
||||
dtx.set($input, value);
|
||||
}
|
||||
});
|
||||
if (dtx.queue.length) {
|
||||
setTimeout(function() { // Set timeout to force it async
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: dtx_obj.ajax_url,
|
||||
dataType: 'json', // only accept strict JSON objects
|
||||
data: {
|
||||
'action': 'wpcf7dtx',
|
||||
'shortcodes': dtx.queue
|
||||
},
|
||||
cache: false,
|
||||
error: function(xhr, status, error) {
|
||||
console.error('[CF7 DTX AJAX ERROR]', error, status, xhr);
|
||||
},
|
||||
success: function(data, status, xhr) {
|
||||
if (typeof(data) == 'object' && data.length) {
|
||||
$.each(data, function(i, obj) {
|
||||
var $inputs = $('.wpcf7 form input.dtx-pageload[data-dtx-value="' + obj.raw_value + '"]');
|
||||
if ($inputs.length) {
|
||||
dtx.set($inputs, obj.value);
|
||||
$inputs.addClass('dtx-ajax-loaded');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Check if Key Exists in Object
|
||||
*/
|
||||
validKey: function(obj, key) {
|
||||
return obj.hasOwnProperty(key) && typeof(obj[key]) == 'string' && obj[key].trim();
|
||||
},
|
||||
/**
|
||||
* Maybe Obfuscate Value
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-attribute-obfuscate/
|
||||
*/
|
||||
obfuscate: function(value, atts) {
|
||||
value = value.trim();
|
||||
if (dtx.validKey(atts, 'obfuscate') && atts.obfuscate) {
|
||||
var o = '';
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
o += '&#' + value.codePointAt(i) + ';';
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return value;
|
||||
},
|
||||
/**
|
||||
* Set Value for Form Field
|
||||
*/
|
||||
set: function($input, value) {
|
||||
$input.attr('value', value).addClass('dtx-loaded');
|
||||
},
|
||||
/**
|
||||
* Get Value form URL Query by Key
|
||||
*
|
||||
* @see @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-php-get-variables/
|
||||
*/
|
||||
get: function(atts) {
|
||||
if (dtx.validKey(atts, 'key')) {
|
||||
var query = window.location.search;
|
||||
if (query) {
|
||||
query = new URLSearchParams(query);
|
||||
return dtx.obfuscate(query.get(atts.key).trim(), atts);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
},
|
||||
/**
|
||||
* Get Referrering URL
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-referrer-url/
|
||||
*/
|
||||
referrer: function(atts) {
|
||||
return dtx.obfuscate(document.referrer, atts);
|
||||
},
|
||||
/**
|
||||
* Get Current URL or Part
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-current-url/
|
||||
*/
|
||||
current_url: function(atts) {
|
||||
if (atts.hasOwnProperty('part')) {
|
||||
var parts = [
|
||||
'scheme', // e.g. `http`
|
||||
'host',
|
||||
'port',
|
||||
'path',
|
||||
'query', // after the question mark ?
|
||||
'fragment' // after the pound sign #
|
||||
];
|
||||
if (parts.includes(atts.part)) {
|
||||
// return part of the url
|
||||
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);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return dtx.obfuscate(window.location.href, atts); // Return the full url
|
||||
}
|
||||
return '';
|
||||
},
|
||||
/**
|
||||
* Get Cookie Value
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-cookie/
|
||||
*/
|
||||
get_cookie: function(atts) {
|
||||
if (atts.hasOwnProperty('key') && typeof(atts.key) == 'string' && atts.key.trim() != '') {
|
||||
var keyValue = document.cookie.match('(^|;) ?' + atts.key.trim() + '=([^;]*)(;|$)');
|
||||
return keyValue ? dtx.obfuscate(keyValue[2], atts) : '';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
/**
|
||||
* Generate a random GUID (globally unique identifier)
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-guid/
|
||||
*/
|
||||
guid: function() {
|
||||
if (typeof(window.crypto) != 'undefined' && typeof(window.crypto.getRandomValues) != 'undefined') {
|
||||
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(), //Timestamp
|
||||
d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now() * 1000)) || 0; //Time in microseconds since page-load or 0 if unsupported
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16; //random number between 0 and 16
|
||||
if (d > 0) { //Use timestamp until depleted
|
||||
r = (d + r) % 16 | 0;
|
||||
d = Math.floor(d / 16);
|
||||
} else { //Use microseconds since page-load if supported
|
||||
r = (d2 + r) % 16 | 0;
|
||||
d2 = Math.floor(d2 / 16);
|
||||
}
|
||||
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16).toUpperCase();
|
||||
}).toUpperCase();;
|
||||
}
|
||||
};
|
||||
$(document).ready(dtx.init);
|
||||
2
wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.min.js
vendored
Normal file
2
wp/wp-content/plugins/contact-form-7-dynamic-text-extension/assets/scripts/dtx.min.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/*! 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);
|
||||
@@ -0,0 +1,2 @@
|
||||
/*! 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}
|
||||
@@ -0,0 +1,211 @@
|
||||
== 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
|
||||
|
||||
= 3.5.3 =
|
||||
|
||||
* Update: removed the use of sessions, [see support thread](https://wordpress.org/support/topic/add-option-to-disable-session-data/)
|
||||
|
||||
= 3.5.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
|
||||
|
||||
= 3.5.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
|
||||
|
||||
= 3.5.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: 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`
|
||||
|
||||
= 2.0.3 =
|
||||
|
||||
* Security: [Fix Reflected XSS](https://web.archive.org/web/20230121180428/https://sevenspark.com/docs/cf7-dtx-security-2019-07-24)
|
||||
|
||||
= 2.0.2.1 =
|
||||
|
||||
* Update changelog properly for 2.0.2 changes:
|
||||
|
||||
= 2.0.2 =
|
||||
|
||||
* Update deprecated `get_currentuserinfo()` function to `wp_get_current_user()`
|
||||
* Update deprecated functions from `WPCF7_add_shortcode` to `WPCF7_add_formtag` and class from `WPCF7_Shortcode` to `WPCF7_FormTag` to comply with CF7 4.6 changes
|
||||
|
||||
= 2.0.1 =
|
||||
|
||||
* Hook change to guarantee the plugin only runs when Contact Form 7 is present in the admin (avoids errors if Contact Form 7 is disabled, or if there is a plugin sequencing issue)
|
||||
|
||||
= 2.0 =
|
||||
|
||||
* Complete rewrite for Compatibility with Contact Form 7 v4
|
||||
|
||||
= 1.2 =
|
||||
|
||||
* Compatibility update for Contact Form 7 v3.9
|
||||
|
||||
= 1.1.0.2 =
|
||||
|
||||
* Updated to work with Contact Form 7 v3.7.x
|
||||
|
||||
= 1.1.0.1 =
|
||||
|
||||
* Removed undefined variable warning
|
||||
|
||||
= 1.1 =
|
||||
|
||||
* Updated for compatibility with Contact Form 7 v3.6
|
||||
* Added Referrer shortcode
|
||||
|
||||
= 1.0.4.2 =
|
||||
|
||||
* Fixed a bug that created repeating square brackets around dynamic text values in cases where the form doesn't validate and JavaScript is deactivated.
|
||||
|
||||
= 1.0.4.1 =
|
||||
|
||||
* Removed trailing whitespace to fix "Headers already sent" errors
|
||||
|
||||
= 1.0.4 =
|
||||
|
||||
* Added Current User Info shortcode
|
||||
* Added Post Custom Field shortcode (with obfuscation support)
|
||||
* Added Hidden Field capability
|
||||
|
||||
= 1.0.3 =
|
||||
|
||||
* Added $_POST shortcode
|
||||
* Added current post/page variable shortcode
|
||||
* Added current URL shortcode
|
||||
|
||||
= 1.0.2 =
|
||||
|
||||
* Fixed administrative control panel dependency issue
|
||||
|
||||
= 1.0.1 =
|
||||
|
||||
* Fixed dependency issue.
|
||||
@@ -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.2
|
||||
* 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.2');
|
||||
define('WPCF7DTX_VERSION', '4.1.0');
|
||||
|
||||
// Define root directory
|
||||
defined('WPCF7DTX_DIR') || define('WPCF7DTX_DIR', __DIR__);
|
||||
@@ -47,99 +47,238 @@ 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', 10, 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('name-attr' => true) //Features
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Frontend Script
|
||||
*
|
||||
* Register the frontend script to be optionally loaded later.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @param string $hook Hook suffix for the current page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wpcf7dtx_enqueue_frontend_assets($hook = '')
|
||||
{
|
||||
$debug = defined('WP_DEBUG') && constant('WP_DEBUG');
|
||||
$url = plugin_dir_url(WPCF7DTX_FILE);
|
||||
$path = plugin_dir_path(WPCF7DTX_FILE);
|
||||
wp_register_script(
|
||||
'wpcf7dtx', // Handle
|
||||
$url . 'assets/scripts/dtx' . ($debug ? '' : '.min') . '.js', // Source
|
||||
array('jquery-core'), // Dependencies
|
||||
$debug ? @filemtime($path . 'assets/scripts/dtx.js') : WPCF7DTX_VERSION, // Version
|
||||
array('in_footer' => true, 'strategy' => 'defer') // Defer loading in footer
|
||||
|
||||
);
|
||||
wp_localize_script(
|
||||
'wpcf7dtx', // Handle
|
||||
'dtx_obj', // Object
|
||||
array('ajax_url' => admin_url('admin-ajax.php')) // Data
|
||||
);
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'wpcf7dtx_enqueue_frontend_assets');
|
||||
|
||||
/**
|
||||
* Include Utility Functions
|
||||
*/
|
||||
include_once(WPCF7DTX_DIR . '/includes/utilities.php');
|
||||
|
||||
/**
|
||||
* Include Validation Functions
|
||||
*/
|
||||
include_once(WPCF7DTX_DIR . '/includes/validation.php');
|
||||
|
||||
/**
|
||||
* Form Tag Handler
|
||||
*
|
||||
* @param WPCF7_FormTag $tag
|
||||
* @param WPCF7_FormTag $tag Current Contact Form 7 tag object
|
||||
*
|
||||
* @return string HTML output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_dynamictext_shortcode_handler($tag)
|
||||
function wpcf7dtx_shortcode_handler($tag)
|
||||
{
|
||||
$tag = new WPCF7_FormTag($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['class'] = $tag->get_class_option($class);
|
||||
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
|
||||
$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 = wpcf7_get_hangover($tag->name, $tag->get_default_option(strval(reset($tag->values)))); // Input value
|
||||
$scstr = '[' . $value . ']';
|
||||
$scval = do_shortcode($scstr); //Shortcode value
|
||||
if ($scval !== $scstr) {
|
||||
$value = $scval; //Set the input value to the evaluated shortcode
|
||||
}
|
||||
$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 = sanitize_text_field(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) {
|
||||
$scpstr = '[' . $placeholder . ']';
|
||||
$scpval = do_shortcode($scpstr); //Shortcode value
|
||||
if ($scpval !== $scpstr) {
|
||||
$placeholder = $scpval; //Set the placeholder value to the evaluated shortcode
|
||||
}
|
||||
//If a different placeholder text has been specified, set both attributes
|
||||
$placeholder = wpcf7dtx_get_dynamic($placeholder, false, $sanitize_type);
|
||||
$atts['placeholder'] = $placeholder;
|
||||
$atts['value'] = $value;
|
||||
} else {
|
||||
@@ -150,58 +289,233 @@ function wpcf7dtx_dynamictext_shortcode_handler($tag)
|
||||
$atts['value'] = $value;
|
||||
}
|
||||
|
||||
//Output the HTML
|
||||
return sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %s"><input %s />%s</span>',
|
||||
sanitize_html_class($tag->name),
|
||||
wpcf7_format_atts($atts), //This function already escapes attribute values
|
||||
$validation_error
|
||||
// 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 {
|
||||
/**
|
||||
* 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') && 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');
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap up class attribute
|
||||
$atts['class'] = $tag->get_class_option($atts['class']);
|
||||
|
||||
// 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
|
||||
* AJAX Request Handler for After Page Loading
|
||||
*
|
||||
* @param mixed $result
|
||||
* @param WPCF7_FormTag $tag
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @return mixed
|
||||
* @param array $_POST A sequential array of url encoded shortcode values to evaluate
|
||||
*
|
||||
* @return array A sequential array of objects with `raw_value` and `value` keys
|
||||
*/
|
||||
function wpcf7dtx_dynamictext_validation_filter($result, $tag)
|
||||
function wpcf7dtx_js_handler()
|
||||
{
|
||||
$tag = new WPCF7_FormTag($tag);
|
||||
|
||||
//Sanitize value
|
||||
$value = empty($_POST[$tag->name]) ? '' : sanitize_text_field(trim(strval($_POST[$tag->name])));
|
||||
|
||||
//Validate
|
||||
if ('dynamictext' == $tag->basetype) {
|
||||
if ($tag->is_required() && '' == $value) {
|
||||
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
|
||||
$return = array();
|
||||
$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(wpcf7dtx_get_dynamic($raw_value, false, $multiline ? 'textarea' : 'auto'))
|
||||
);
|
||||
}
|
||||
}
|
||||
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;
|
||||
wp_die(json_encode($return));
|
||||
}
|
||||
|
||||
/**
|
||||
* Include Utility Functions
|
||||
*/
|
||||
include_once(WPCF7DTX_DIR . '/includes/utilities.php');
|
||||
add_action('wp_ajax_wpcf7dtx', 'wpcf7dtx_js_handler'); // Add AJAX call for logged in users
|
||||
add_action('wp_ajax_nopriv_wpcf7dtx', 'wpcf7dtx_js_handler'); // Add AJAX call for anonymous users
|
||||
|
||||
if (is_admin()) {
|
||||
/**
|
||||
@@ -211,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,29 +8,32 @@
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string $hook Hook suffix for the current admin page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wpcf7dtx_enqueue_admin_assets($hook)
|
||||
{
|
||||
//Only load on CF7 Form pages
|
||||
if ($hook == 'toplevel_page_wpcf7') {
|
||||
// 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_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
|
||||
@filemtime($path . 'assets/styles/tag-generator.css') //Version
|
||||
$debug ? @filemtime($path . 'assets/styles/tag-generator.css') : WPCF7DTX_VERSION //Version
|
||||
);
|
||||
|
||||
//Plugin Scripts
|
||||
wp_enqueue_script(
|
||||
$prefix . 'taggenerator', //Handle
|
||||
$url . 'assets/scripts/tag-generator.js', //Source
|
||||
$url . 'assets/scripts/tag-generator' . ($debug ? '' : '.min') . '.js', //Source
|
||||
array('jquery', 'wpcf7-admin-taggenerator'), //Dependencies
|
||||
@filemtime($path . 'assets/scripts/tag-generator.js'), //Version
|
||||
true //In footer
|
||||
$debug ? @filemtime($path . 'assets/scripts/tag-generator.js') : WPCF7DTX_VERSION, //Version
|
||||
array('in_footer' => true, 'strategy' => 'defer') // Defer loading in footer
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -41,66 +44,68 @@ 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') //options
|
||||
);
|
||||
|
||||
//Dynamic Hidden Field
|
||||
$tag_generator->add(
|
||||
'dynamichidden', //id
|
||||
__('dynamic hidden', 'contact-form-7-dynamic-text-extension'), //title
|
||||
'wpcf7dtx_tag_generator_dynamictext' //callback
|
||||
);
|
||||
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
|
||||
*
|
||||
* @param WPCF7_ContactForm $contact_form
|
||||
* @param array $options
|
||||
*
|
||||
* @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" target="_blank" rel="noopener">%s</a>.',
|
||||
__('For more details, see', 'contact-form-7-dynamic-text-extension'),
|
||||
esc_attr($utm_source), //UTM source
|
||||
esc_attr($type), //UTM content
|
||||
__('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>',
|
||||
wp_kses($description, 'a') //Tag generator description
|
||||
'<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
|
||||
@@ -114,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'),
|
||||
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>',
|
||||
@@ -196,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
|
||||
@@ -212,6 +408,55 @@ function wpcf7dtx_tag_generator_dynamictext($contact_form, $options = '')
|
||||
);
|
||||
}
|
||||
|
||||
// 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'] . '-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' => '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_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>',
|
||||
|
||||
@@ -17,207 +17,183 @@
|
||||
*/
|
||||
function wpcf7dtx_init_shortcodes()
|
||||
{
|
||||
add_shortcode('CF7_GET', 'wpcf7dtx_get');
|
||||
add_shortcode('CF7_POST', 'wpcf7dtx_post');
|
||||
add_shortcode('CF7_URL', 'wpcf7dtx_url');
|
||||
add_shortcode('CF7_referrer', 'wpcf7dtx_referrer');
|
||||
add_shortcode('CF7_bloginfo', 'wpcf7dtx_bloginfo');
|
||||
add_shortcode('CF7_get_post_var', 'wpcf7dtx_get_post_var');
|
||||
add_shortcode('CF7_get_custom_field', 'wpcf7dtx_get_custom_field');
|
||||
add_shortcode('CF7_get_current_user', 'wpcf7dtx_get_current_user');
|
||||
add_shortcode('CF7_get_attachment', 'wpcf7dtx_get_attachment');
|
||||
add_shortcode('CF7_guid', 'wpcf7dtx_guid');
|
||||
add_shortcode('CF7_GET', 'wpcf7dtx_get', 10, 1);
|
||||
add_shortcode('CF7_POST', 'wpcf7dtx_post', 10, 1);
|
||||
add_shortcode('CF7_URL', 'wpcf7dtx_url', 10, 1);
|
||||
add_shortcode('CF7_referrer', 'wpcf7dtx_referrer', 10, 1);
|
||||
add_shortcode('CF7_bloginfo', 'wpcf7dtx_bloginfo', 10, 1);
|
||||
add_shortcode('CF7_get_post_var', 'wpcf7dtx_get_post_var', 10, 1);
|
||||
add_shortcode('CF7_get_custom_field', 'wpcf7dtx_get_custom_field', 10, 1);
|
||||
add_shortcode('CF7_get_current_var', 'wpcf7dtx_get_current_var', 10, 1);
|
||||
add_shortcode('CF7_get_current_user', 'wpcf7dtx_get_current_user', 10, 1);
|
||||
add_shortcode('CF7_get_attachment', 'wpcf7dtx_get_attachment', 10, 1);
|
||||
add_shortcode('CF7_get_cookie', 'wpcf7dtx_get_cookie', 10, 1);
|
||||
add_shortcode('CF7_get_taxonomy', 'wpcf7dtx_get_taxonomy', 10, 1);
|
||||
add_shortcode('CF7_get_theme_option', 'wpcf7dtx_get_theme_option', 10, 1);
|
||||
add_shortcode('CF7_guid', 'wpcf7dtx_guid', 10, 0);
|
||||
}
|
||||
add_action('init', 'wpcf7dtx_init_shortcodes'); //Add init hook to add shortcodes
|
||||
|
||||
/**
|
||||
* Get Variable from $_GET Array
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-php-get-variables/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get($atts = array(), $content = '', $tag = '')
|
||||
function wpcf7dtx_get($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'key' => 0,
|
||||
'default' => '',
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$valid_key = (is_numeric($key) && intval($key) > -1) || (is_string($key) && !empty($key));
|
||||
if ($valid_key && is_array($_GET) && count($_GET) && array_key_exists($key, $_GET) && !empty($_GET[$key])) {
|
||||
$value = sanitize_text_field(strval($_GET[$key]));
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
return '';
|
||||
$value = apply_filters('wpcf7dtx_sanitize', wpcf7dtx_array_has_key($key, $_GET, $default));
|
||||
return apply_filters('wpcf7dtx_escape', $value, $obfuscate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Variable from $_POST Array
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-php-post-variables/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_post($atts = array(), $content = '', $tag = '')
|
||||
function wpcf7dtx_post($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'key' => '',
|
||||
'default' => '',
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$valid_key = (is_numeric($key) && intval($key) > -1) || (is_string($key) && !empty($key));
|
||||
if ($valid_key && is_array($_POST) && count($_POST) && array_key_exists($key, $_POST) && !empty($_POST[$key])) {
|
||||
$value = sanitize_text_field(strval($_POST[$key]));
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
$value = apply_filters('wpcf7dtx_sanitize', wpcf7dtx_array_has_key($key, $_POST, $default));
|
||||
return apply_filters('wpcf7dtx_escape', $value, $obfuscate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Current URL or Part
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-current-url/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_url($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'allowed_protocols' => '',
|
||||
'part' => '',
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$allowed_protocols = explode(',', sanitize_text_field($allowed_protocols));
|
||||
|
||||
// Get the absolute URL
|
||||
if (is_multisite() && !is_subdomain_install()) {
|
||||
// Network installs not using subdomains
|
||||
$url = apply_filters('wpcf7dtx_sanitize', network_home_url($_SERVER['REQUEST_URI']), 'url', $allowed_protocols);
|
||||
} else {
|
||||
// Single installs and network installs using subdomains
|
||||
$url = apply_filters('wpcf7dtx_sanitize', home_url($_SERVER['REQUEST_URI']), 'url', $allowed_protocols);
|
||||
}
|
||||
if ($url && !empty($part = sanitize_key(strtolower($part)))) {
|
||||
// If an individual part is requested, get that specific value using parse_url()
|
||||
$part_constant_map = [
|
||||
'scheme' => PHP_URL_SCHEME, // e.g. `http`
|
||||
'host' => PHP_URL_HOST, // the domain (or subdomain) of the current website
|
||||
'path' => PHP_URL_PATH, // e.g. `/path/to/current/page/`
|
||||
'query' => PHP_URL_QUERY // after the question mark ?
|
||||
];
|
||||
$value = '';
|
||||
if (array_key_exists($part, $part_constant_map)) {
|
||||
$value = apply_filters('wpcf7dtx_sanitize', strval(wp_parse_url($url, $part_constant_map[$part])), 'text');
|
||||
}
|
||||
return $value;
|
||||
return apply_filters('wpcf7dtx_escape', $value, $obfuscate, 'text');
|
||||
}
|
||||
// No part requested, return the absolute URL
|
||||
return apply_filters('wpcf7dtx_escape', $url, $obfuscate, 'url', $allowed_protocols);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Referrering URL
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-referrer-url/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_referrer($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'allowed_protocols' => '',
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
if ($value = wpcf7dtx_array_has_key('HTTP_REFERER', $_SERVER)) {
|
||||
$value = apply_filters('wpcf7dtx_sanitize', $value, 'url', $allowed_protocols);
|
||||
return apply_filters('wpcf7dtx_escape', $value, $obfuscate, 'url');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Current URL
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_url($atts = array(), $content = '', $tag = '') {
|
||||
|
||||
extract(shortcode_atts(array(
|
||||
'allowed_protocols' => 'http,https',
|
||||
'obfuscate' => '',
|
||||
'part' => '',
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
|
||||
$allowed_protocols = explode(',', sanitize_text_field($allowed_protocols));
|
||||
|
||||
// Build the full URL from the $_SERVER array
|
||||
$url = sprintf('http%s://', is_ssl() ? 's' : '');
|
||||
if (!empty($_SERVER['SERVER_PORT']) && intval($_SERVER['SERVER_PORT']) !== 80) {
|
||||
$url = $url . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
|
||||
} else {
|
||||
$url = $url . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
// Determine the value to return
|
||||
$value = '';
|
||||
|
||||
// If an individual part is requested, get that specific value using parse_url()
|
||||
if( $part ){
|
||||
$part_constant_map = [
|
||||
'host' => PHP_URL_HOST,
|
||||
'query' => PHP_URL_QUERY,
|
||||
'path' => PHP_URL_PATH,
|
||||
// 'fragment' => PHP_URL_FRAGMENT, // Can't get fragment because it's not part of the $_SERVER array
|
||||
];
|
||||
if( isset( $part_constant_map[$part] ) ) {
|
||||
$value = sanitize_text_field(parse_url($url, $part_constant_map[$part]));
|
||||
}
|
||||
}
|
||||
// No part requested, return the whole thing
|
||||
else {
|
||||
$value = sanitize_url($url, $allowed_protocols);
|
||||
}
|
||||
|
||||
// Obfuscate if requested
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Referrer
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_referrer($atts = array(), $content = '', $tag = '')
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'allowed_protocols' => 'http,https',
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$allowed_protocols = explode(',', sanitize_text_field($allowed_protocols));
|
||||
$value = empty($_SERVER['HTTP_REFERER']) ? '' : sanitize_url($_SERVER['HTTP_REFERER'], $allowed_protocols);
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Variable from Bloginfo
|
||||
*
|
||||
* See possible values: https://developer.wordpress.org/reference/functions/get_bloginfo/
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-post-page-variables/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_bloginfo($atts = array(), $content = '', $tag = '')
|
||||
function wpcf7dtx_bloginfo($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'show' => 'name', //Backwards compatibility
|
||||
'key' => 'name',
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$key = $show != $key && $show != 'name' ? $show : $key; //Use old value of "show" if not set to default value
|
||||
$value = sanitize_text_field(strval(get_bloginfo($key)));
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
}
|
||||
return $value;
|
||||
$key = $show != $key && $show != 'name' ? $show : $key; // Use old value of "show" if not set to default value
|
||||
return apply_filters('wpcf7dtx_escape', get_bloginfo($key), $obfuscate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Variable from a Post Object
|
||||
*
|
||||
* @link https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-post-page-variables/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get_post_var($atts = array(), $content = '', $tag = '')
|
||||
function wpcf7dtx_get_post_var($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'key' => 'post_title',
|
||||
'post_id' => '',
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$key = strtolower(apply_filters('wpcf7dtx_sanitize', $key));
|
||||
switch ($key) {
|
||||
case 'slug':
|
||||
case 'acf_id': // If requesting the handle for ACF, return the post ID
|
||||
case 'id':
|
||||
$key = 'ID';
|
||||
break;
|
||||
case 'slug': // Alias
|
||||
$key = 'post_name';
|
||||
break;
|
||||
case 'title':
|
||||
case 'title': // Alias
|
||||
$key = 'post_title';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$post_id = wpcf7dtx_get_post_id($post_id);
|
||||
if ($post_id && is_string($key) && !empty($key)) {
|
||||
$value = sanitize_text_field(trim(strval(get_post_field($key, $post_id))));
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
}
|
||||
return $value;
|
||||
if ($post_id) {
|
||||
return apply_filters('wpcf7dtx_escape', get_post_field($key, $post_id), $obfuscate);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -225,13 +201,13 @@ function wpcf7dtx_get_post_var($atts = array(), $content = '', $tag = '')
|
||||
/**
|
||||
* Get Value from Post Meta Field
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-post-meta-custom-fields/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get_custom_field($atts = array(), $content = '', $tag = '')
|
||||
function wpcf7dtx_get_custom_field($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'key' => '',
|
||||
@@ -239,12 +215,112 @@ function wpcf7dtx_get_custom_field($atts = array(), $content = '', $tag = '')
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$post_id = wpcf7dtx_get_post_id($post_id);
|
||||
if ($post_id && is_string($key) && !empty($key)) {
|
||||
$value = get_post_meta($post_id, $key, true);
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
$key = apply_filters('wpcf7dtx_sanitize', $key, 'text');
|
||||
if ($post_id && $key) {
|
||||
return apply_filters('wpcf7dtx_escape', get_post_meta($post_id, $key, true), $obfuscate);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Variable from the Current Object
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @link https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-current-variables/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get_current_var($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'key' => 'title',
|
||||
'obfuscate' => ''
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$key = apply_filters('wpcf7dtx_sanitize', $key);
|
||||
$temp_key = str_replace('-', '_', sanitize_key($key));
|
||||
if ($temp_key === 'url') {
|
||||
return wpcf7dtx_url($atts); // Getting the current URL is the same for all WordPress pages
|
||||
} elseif (!empty($key)) {
|
||||
$type = '';
|
||||
$obj = null;
|
||||
if (!wp_doing_ajax()) {
|
||||
$obj = get_queried_object(); // Get the current WordPress queried object
|
||||
if (!is_null($obj)) {
|
||||
if ($obj instanceof WP_User) {
|
||||
$type = 'user';
|
||||
} elseif (property_exists($obj, 'ID')) {
|
||||
$type = 'post';
|
||||
} elseif (property_exists($obj, 'term_id')) {
|
||||
$type = 'term';
|
||||
}
|
||||
} elseif (is_archive()) {
|
||||
$type = 'archive';
|
||||
}
|
||||
}
|
||||
switch ($type) {
|
||||
case 'user': // This is an author page
|
||||
switch ($temp_key) {
|
||||
case 'acf_id': // Get handle for Advanced Custom Fields
|
||||
return apply_filters('wpcf7dtx_escape', 'user_' . $obj->ID, $obfuscate);
|
||||
case 'image':
|
||||
case 'featured_image': // Get the profile picture of the user being displayed on the page
|
||||
return apply_filters('wpcf7dtx_escape', get_avatar_url($obj->ID), $obfuscate, 'url');
|
||||
case 'title': // Get author's display name
|
||||
return apply_filters('wpcf7dtx_escape', $obj->display_name, $obfuscate);
|
||||
case 'slug': // Not all author pages use the `user_login` variable for security reasons, so get what is currently displayed as slug
|
||||
return apply_filters('wpcf7dtx_escape', basename(wpcf7dtx_url(array('part' => 'path'))), $obfuscate);
|
||||
default: // Get user value by key should it exist
|
||||
return apply_filters('wpcf7dtx_escape', $obj->get($key), $obfuscate);
|
||||
}
|
||||
case 'post': // This is a post object
|
||||
switch ($temp_key) {
|
||||
case 'image':
|
||||
case 'featured_image': // Get the current post's featured image
|
||||
return wpcf7dtx_get_attachment(array_merge($atts, array('post_id' => $obj->ID)));
|
||||
case 'terms': // Get the current post's assigned terms
|
||||
return wpcf7dtx_get_taxonomy(array_merge($atts, array('post_id' => $obj->ID)));
|
||||
default:
|
||||
// Use the post object shortcode should it exist as a post variable
|
||||
$value = wpcf7dtx_get_post_var(array_merge($atts, array('post_id' => $obj->ID)));
|
||||
if (empty($value)) {
|
||||
// Try post meta if post object variable failed
|
||||
$value = wpcf7dtx_get_custom_field(array_merge($atts, array('post_id' => $obj->ID)));
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
case 'term': // This is a taxonomy with a term ID
|
||||
switch ($key) {
|
||||
case 'id': // Get term ID
|
||||
return apply_filters('wpcf7dtx_escape', $obj->term_id, $obfuscate);
|
||||
case 'acf_id': // Get handle for Advanced Custom Fields
|
||||
return apply_filters('wpcf7dtx_escape', $obj->taxonomy . '_' . $obj->term_id, $obfuscate);
|
||||
case 'title': // Get term name
|
||||
return apply_filters('wpcf7dtx_escape', $obj->name, $obfuscate);
|
||||
default:
|
||||
if (property_exists($obj, $key)) {
|
||||
// Get any property if it exists
|
||||
return apply_filters('wpcf7dtx_escape', $obj->{$key}, $obfuscate);
|
||||
}
|
||||
// Otherwise, try meta data if the property doesn't exist
|
||||
return apply_filters('wpcf7dtx_escape', get_metadata('term', $obj->ID, $key, true), $obfuscate);
|
||||
}
|
||||
case 'archive': // Possibly a date or formats archive
|
||||
switch ($temp_key) {
|
||||
case 'title': // Get archive title
|
||||
return apply_filters('wpcf7dtx_escape', get_the_archive_title(), $obfuscate);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default: // Possibly a search or 404 page at this point
|
||||
if ($temp_key == 'slug') {
|
||||
// no idea what else to get except the slug maybe
|
||||
return apply_filters('wpcf7dtx_escape', basename(wpcf7dtx_url(array('part' => 'path'))), $obfuscate);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -253,15 +329,14 @@ function wpcf7dtx_get_custom_field($atts = array(), $content = '', $tag = '')
|
||||
* Get Value from Current User
|
||||
*
|
||||
* Retreives data from the `users` and `usermeta` tables.
|
||||
* Documentation: https://developer.wordpress.org/reference/classes/wp_user/get/
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-current-user-user-meta/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get_current_user($atts = array(), $content = '', $tag = '')
|
||||
function wpcf7dtx_get_current_user($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'key' => 'user_login',
|
||||
@@ -269,11 +344,7 @@ function wpcf7dtx_get_current_user($atts = array(), $content = '', $tag = '')
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
if (is_user_logged_in()) {
|
||||
$user = wp_get_current_user();
|
||||
$value = $user->get($key);
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
}
|
||||
return $value;
|
||||
return apply_filters('wpcf7dtx_escape', $user->get($key), $obfuscate);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -285,13 +356,13 @@ function wpcf7dtx_get_current_user($atts = array(), $content = '', $tag = '')
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-media-attachment/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get_attachment($atts = array(), $content = '', $tag = '')
|
||||
function wpcf7dtx_get_attachment($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'id' => '', //Get attachment by ID
|
||||
@@ -303,56 +374,131 @@ function wpcf7dtx_get_attachment($atts = array(), $content = '', $tag = '')
|
||||
|
||||
//No attachment ID was provided, check for post ID to get it's featured image
|
||||
if (empty($id)) {
|
||||
if ($post_id = sanitize_text_field(strval($post_id))) {
|
||||
if ($post_id = wpcf7dtx_get_post_id($post_id)) {
|
||||
//If a post ID was provided, get it's featured image
|
||||
if (is_numeric($post_id) && (int)$post_id > 0) {
|
||||
$id = get_post_thumbnail_id($post_id);
|
||||
}
|
||||
} else {
|
||||
//If no post ID was provided, get current featured image
|
||||
global $post;
|
||||
if (isset($post) && property_exists($post, 'ID') && is_numeric($post->ID)) {
|
||||
$id = get_post_thumbnail_id(intval($post->ID));
|
||||
}
|
||||
$id = get_post_thumbnail_id($post_id);
|
||||
}
|
||||
}
|
||||
|
||||
//Get the value
|
||||
$value = '';
|
||||
if ($id) {
|
||||
$id = intval(sanitize_text_field(strval($id)));
|
||||
switch ($return) {
|
||||
case 'id': //Return the attachment ID
|
||||
$value = esc_attr($id);
|
||||
break;
|
||||
return apply_filters('wpcf7dtx_escape', $id, $obfuscate);
|
||||
default: //Return attachment URL
|
||||
$url = wp_get_attachment_image_url(intval($id), sanitize_text_field(strval($size)));
|
||||
$value = $url ? esc_url($url) : '';
|
||||
break;
|
||||
}
|
||||
if ($obfuscate && !empty($value)) {
|
||||
return wpcf7dtx_obfuscate($value);
|
||||
return apply_filters('wpcf7dtx_escape', $url, $obfuscate, 'url');
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Cookie Value
|
||||
*
|
||||
* Retreives the value of a cookie
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-cookie/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get_cookie($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'key' => '',
|
||||
'default' => '',
|
||||
'obfuscate' => '' // Optionally obfuscate returned value
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$key = apply_filters('wpcf7dtx_sanitize', $key);
|
||||
$value = wpcf7dtx_array_has_key($key, $_COOKIE, $default);
|
||||
return apply_filters('wpcf7dtx_escape', $value, $obfuscate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Taxonomy
|
||||
*
|
||||
* Retreives a list of taxonomy values
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-taxonomy/
|
||||
* @see https://developer.wordpress.org/reference/classes/wp_term_query/get_terms/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get_taxonomy($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'post_id' => '',
|
||||
'taxonomy' => 'category', // Default taxonomy is `category`
|
||||
'fields' => 'names', // Return an array of term names
|
||||
'obfuscate' => '' // Optionally obfuscate returned value
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
$post_id = wpcf7dtx_get_post_id($post_id);
|
||||
$fields = apply_filters('wpcf7dtx_sanitize', $fields, 'key');
|
||||
if ($post_id && in_array($fields, array('names', 'slugs', 'ids'))) {
|
||||
$terms = wp_get_object_terms(
|
||||
$post_id, // Get only the ones assigned to this post
|
||||
apply_filters('wpcf7dtx_sanitize', $taxonomy, 'slug'),
|
||||
array('fields' => $fields)
|
||||
);
|
||||
if (is_array($terms) && count($values = array_values($terms)) && (is_string($values[0]) || is_numeric($values[0]))) {
|
||||
return apply_filters('wpcf7dtx_escape', implode(', ', $values), $obfuscate, 'text');
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Theme Customization Option
|
||||
*
|
||||
* Retreives theme modification value for the active theme
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-theme-option/
|
||||
* @see https://developer.wordpress.org/reference/functions/get_theme_mod/
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
*/
|
||||
function wpcf7dtx_get_theme_option($atts = array())
|
||||
{
|
||||
extract(shortcode_atts(array(
|
||||
'key' => '',
|
||||
'default' => '', // Optional default value
|
||||
'obfuscate' => '' // Optionally obfuscate returned value
|
||||
), array_change_key_case((array)$atts, CASE_LOWER)));
|
||||
if ($key = apply_filters('wpcf7dtx_sanitize', $key, 'text')) {
|
||||
$default = apply_filters('wpcf7dtx_sanitize', $default);
|
||||
return apply_filters('wpcf7dtx_escape', get_theme_mod($key, $default), $obfuscate);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* GUID Field
|
||||
*
|
||||
* Generate a random GUID (globally unique identifier)
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $atts Optional. An associative array of shortcode attributes. Default is an empty array.
|
||||
* @param string $content Optional. A string of content between the opening and closing tags. Default is an empty string.
|
||||
* @param string $tag Optional. The shortcode tag. Default is an empty string.
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-guid/
|
||||
*
|
||||
* @return string Output of the shortcode
|
||||
* @return string a randomly generated 128-bit text string.
|
||||
*/
|
||||
function wpcf7dtx_guid()
|
||||
{
|
||||
if (function_exists('com_create_guid') === true) {
|
||||
return trim(com_create_guid(), '{}');
|
||||
return esc_attr(trim(com_create_guid(), '{}'));
|
||||
}
|
||||
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
|
||||
return esc_attr(sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,140 +1,640 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Custom DTX Allowed Protocols Filter
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @param array|string $protocols Optional. Specify protocols to allow either as an array of string values or a string value of comma separated protocols.
|
||||
* @param bool $replace Optional. If true, this function will only return the specified values. If false, will merge specified values with default values. Default is false.
|
||||
*
|
||||
* @return array An array of string values, default only includes `http` and `https` protocols.
|
||||
*/
|
||||
function wpcf7dtx_allow_protocols($protocols = false, $replace = false)
|
||||
{
|
||||
// Get user-inputted protocols
|
||||
$user_protocols = false;
|
||||
if (is_string($protocols) && !empty($protocols)) {
|
||||
$user_protocols = explode(',', sanitize_text_field($protocols));
|
||||
} elseif (is_array($protocols) && count($protocols)) {
|
||||
$user_protocols = array_filter(array_values($protocols));
|
||||
}
|
||||
$default = array('http', 'https');
|
||||
if (is_array($user_protocols) && count($user_protocols)) {
|
||||
// Sanitize each value before adding
|
||||
$allowed_protocols = array();
|
||||
foreach ($user_protocols as $protocol) {
|
||||
$allowed_protocols[] = sanitize_text_field($protocol);
|
||||
}
|
||||
if ($replace) {
|
||||
return array_unique($allowed_protocols);
|
||||
}
|
||||
return array_unique(array_merge(array('http', 'https'), $allowed_protocols)); // Return merged values
|
||||
} elseif ($replace) {
|
||||
return array(); // None allowed, apparently
|
||||
}
|
||||
return $default; // Return only default values
|
||||
}
|
||||
add_filter('wpcf7dtx_allow_protocols', 'wpcf7dtx_allow_protocols', 10, 2);
|
||||
|
||||
/**
|
||||
* Custom DTX Sanitize Filter
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @param string $value value to be sanitized
|
||||
* @param string $type Optional. The type of sanitation to return. Default is `auto` where automatic identification will be used to attempt to identify URLs and email addresses vs text.
|
||||
* @param array|string $protocols Optional. Specify protocols to allow either as an array of string values or a string value of comma separated protocols.
|
||||
*
|
||||
* @return string the sanitized value
|
||||
*/
|
||||
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);
|
||||
switch ($type) {
|
||||
case 'email':
|
||||
return sanitize_email($value);
|
||||
case 'url':
|
||||
return sanitize_url($value, apply_filters('wpcf7dtx_allow_protocols', $protocols));
|
||||
case 'key':
|
||||
return sanitize_key($value);
|
||||
case 'slug':
|
||||
return sanitize_title($value);
|
||||
case 'textarea':
|
||||
return sanitize_textarea_field($value);
|
||||
}
|
||||
}
|
||||
return sanitize_text_field($value);
|
||||
}
|
||||
add_filter('wpcf7dtx_sanitize', 'wpcf7dtx_sanitize', 10, 3);
|
||||
|
||||
/**
|
||||
* Custom DTX Escape Filter
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @param string $value value to be escaped
|
||||
* @param bool $obfuscate Optional. If true, returned value will be obfuscated. Default is false.
|
||||
* @param string $type Optional. The type of escape to return. Default is `auto` where automatic identification will be used to attempt to identify the type of text.
|
||||
* @param array|string $protocols Optional. Specify protocols to allow either as an array of string values or a string value of comma separated protocols.
|
||||
*
|
||||
* @return string the escaped value
|
||||
*/
|
||||
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) {
|
||||
return apply_filters('wpcf7dtx_obfuscate', $value); // Return obfuscated value
|
||||
}
|
||||
$type = $type == 'auto' ? wpcf7dtx_detect_value_type($value) : sanitize_text_field($type);
|
||||
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
|
||||
}
|
||||
add_filter('wpcf7dtx_escape', 'wpcf7dtx_escape', 10, 4);
|
||||
|
||||
/**
|
||||
* Detect Value Type
|
||||
*
|
||||
* @since 3.3.0
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @param string $value the value to be identified
|
||||
*
|
||||
* @return string Potentially identifies string values as `url`, `email`, or `text`.
|
||||
*/
|
||||
function wpcf7dtx_detect_value_type($value)
|
||||
{
|
||||
// Try to detect the value type
|
||||
$value = trim($value);
|
||||
$is_https_url = stripos($value, 'https') === 0 && strlen($value) > 5;
|
||||
$is_http_url = stripos($value, 'http') === 0 && strlen($value) > 4 && sanitize_key($value) != 'https';
|
||||
if ($is_https_url || $is_http_url) {
|
||||
return 'url';
|
||||
} elseif (preg_match('/^[^\s@]+@[^\s@]+\.[^\s@]+$/', $value)) {
|
||||
return 'email';
|
||||
}
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Obfuscate a value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @see https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-attribute-obfuscate/
|
||||
*
|
||||
* @param mixed $value the value to be obfuscated
|
||||
*
|
||||
* @return string obfuscated value
|
||||
*/
|
||||
function wpcf7dtx_obfuscate($value = '')
|
||||
{
|
||||
$return = '';
|
||||
$value = strval($value); //Force value to be string
|
||||
if (!empty($value)) {
|
||||
foreach (str_split($value) as $letter) {
|
||||
$return .= '&#' . ord($letter) . ';';
|
||||
}
|
||||
$o = '';
|
||||
if (!is_string($value)) {
|
||||
$value = sanitize_text_field(strval($value)); // Force value to be string and sanitize it
|
||||
}
|
||||
return sanitize_text_field(trim($return));
|
||||
if (!empty($value)) {
|
||||
$value = htmlentities($value, ENT_QUOTES);
|
||||
foreach (str_split($value) as $letter) {
|
||||
$o .= '&#' . ord($letter) . ';';
|
||||
}
|
||||
return $o; // Return obfuscated value
|
||||
}
|
||||
return esc_attr($value); // Return default attribute escape
|
||||
}
|
||||
add_filter('wpcf7dtx_obfuscate', 'wpcf7dtx_obfuscate', 10, 1);
|
||||
|
||||
/**
|
||||
* Get Post ID
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @param mixed $post_id
|
||||
*
|
||||
* @return int An integer value of the passed post ID or the post ID of the current `$post` global object. 0 on Failure.
|
||||
*/
|
||||
function wpcf7dtx_get_post_id($post_id)
|
||||
function wpcf7dtx_get_post_id($post_id, $context = 'dtx')
|
||||
{
|
||||
$post_id = is_numeric($post_id) && (int)$post_id > 0 ? intval($post_id) : 0;
|
||||
if (!$post_id) {
|
||||
//No post ID was provided, look it up
|
||||
global $post;
|
||||
if (isset($post) && property_exists($post, 'ID')) {
|
||||
$post_id = $post->ID;
|
||||
$post_id = $post_id ? intval(sanitize_text_field(strval($post_id))) : '';
|
||||
if (!$post_id || !is_numeric($post_id)) {
|
||||
if ($context == 'dtx') {
|
||||
if (wp_doing_ajax()) {
|
||||
// If we're doing an AJAX call, just fail quietly
|
||||
return 0;
|
||||
} else {
|
||||
global $post;
|
||||
if (isset($post)) {
|
||||
$post_id = $post->ID; // If the global $post object is set, get its ID
|
||||
} else {
|
||||
$post_id = get_the_ID(); // Otherwise get it from "the loop"
|
||||
}
|
||||
}
|
||||
} elseif ($context == 'acf') {
|
||||
// When a post ID is not specified for ACF keys, it accepts the boolean `false`
|
||||
$post_id = false;
|
||||
}
|
||||
}
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a shortcode as deprecated and inform when it has been used.
|
||||
* Get Dynamic Value
|
||||
*
|
||||
* The current behavior is to trigger a user error if WP_DEBUG is true.
|
||||
* @since 3.2.2
|
||||
*
|
||||
* This function is to be used in every function that is deprecated.
|
||||
* @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`.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @access private
|
||||
*
|
||||
* @param string $tag The tag of the shortcode that was called.
|
||||
* @param string $version The version of the plugin that deprecated the shortcode.
|
||||
* @param string $replacement Optional. The shortcode that should have been used. Default null.
|
||||
* @return string The dynamic output or the original value, not escaped or sanitized.
|
||||
*/
|
||||
function wpcf7dtx_deprecated_shortcode($tag, $version, $replacement = null, $documentation = null)
|
||||
function wpcf7dtx_get_dynamic($value, $tag = false, $sanitize = 'auto')
|
||||
{
|
||||
/**
|
||||
* Filter whether to trigger an error for deprecated shortcodes.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
|
||||
*/
|
||||
if (WP_DEBUG && apply_filters('deprecated_function_trigger_error', true)) {
|
||||
if (!is_null($replacement)) {
|
||||
if (!is_null($documentation)) {
|
||||
trigger_error(sprintf(
|
||||
__('%1$s is <strong>deprecated</strong> since version %2$s! Use Contact Form 7\'s built-in attribute "%3$s" instead. Contact Form 7 Documentation: %4$s', 'contact-form-7-dynamic-text-extension'),
|
||||
$tag,
|
||||
$version,
|
||||
$replacement,
|
||||
$documentation
|
||||
));
|
||||
} else {
|
||||
trigger_error(sprintf(
|
||||
__('%1$s is <strong>deprecated</strong> since version %2$s! Use Contact Form 7\'s built-in attribute "%3$s" instead.', 'contact-form-7-dynamic-text-extension'),
|
||||
$tag,
|
||||
$version,
|
||||
$replacement
|
||||
));
|
||||
}
|
||||
} else {
|
||||
trigger_error(sprintf(
|
||||
__('%1$s is <strong>deprecated</strong> since version %2$s with no alternative currently available.', 'contact-form-7-dynamic-text-extension'),
|
||||
$tag,
|
||||
$version
|
||||
));
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Content for Specified Shortcodes
|
||||
* Get Allowed HTML for Form Field Properties
|
||||
*
|
||||
* Parse a string of content for a specific shortcode to retrieve its attributes and content
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @since 3.1.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.
|
||||
*
|
||||
* @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 array An associative array of allowed properties appropriate for use in `wp_kses()`
|
||||
*/
|
||||
function wpcf7dtx_get_shortcode_atts($content)
|
||||
function wpcf7dtx_get_allowed_field_properties($type = 'text', $extra = array())
|
||||
{
|
||||
$return = array(
|
||||
'tag' => '',
|
||||
'atts' => 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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,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
|
||||
@@ -1,88 +1,183 @@
|
||||
=== Contact Form 7 - Dynamic Text Extension ===
|
||||
Contributors: sevenspark, tessawatkinsllc
|
||||
Donate link: https://just1voice.com/donate/
|
||||
Tags: Contact Form 7, contact, contact form, dynamic, text, input, GET, POST, title, slug, autofill, auto-fill, prepopulate, pre-populate, form field
|
||||
Tested up to: 6.1.1
|
||||
Stable tag: 3.2
|
||||
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: 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 ==
|
||||
|
||||
Contact Form 7 is an excellent WordPress plugin and one of the top choices of free WordPress plugins for contact forms. Contact Form 7 - Dynamic Text Extension (DTX) makes it even more awesome by adding dynamic content capabilities. While default values in Contact Form 7 are static, DTX lets you create pre-populated fields based on other values. Some examples might include:
|
||||
Contact Form 7 is an excellent WordPress plugin and one of the top choices of free WordPress plugins for contact forms. Contact Form 7 - Dynamic Text Extension (DTX) makes it even more awesome by adding dynamic content capabilities. While default values in Contact Form 7 are static, DTX lets you create pre-populated fields pulled from other locations. Some examples might include:
|
||||
|
||||
* Auto-filling a URL
|
||||
* Auto-filling a URL or just getting the domain name or path
|
||||
* Auto-filling a post ID, title, or slug
|
||||
* Auto-filling a title, URL, or slug for the current page
|
||||
* Pre-populating a product number
|
||||
* Referencing other content on the site
|
||||
* Populating with post info
|
||||
* Populating with user info
|
||||
* Populating with custom fields
|
||||
* Populating with post or page info
|
||||
* Populating with the current user's info
|
||||
* Populating with custom and meta fields
|
||||
* Generating unique identifiers for support tickets
|
||||
* Getting a list of post categories or other custom taxonomies
|
||||
* Getting a value from a cookie
|
||||
* 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? =
|
||||
## 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.
|
||||
|
||||
= HOW TO USE IT =
|
||||
= Dynamic Value =
|
||||
|
||||
After installing and activating the plugin, you will have 2 new tag types to select from when creating or editing a Contact Form 7 form: the dynamic text field and dynamic hidden field. Most of the options in their tag generators will be familiar to Contact Form 7 users but there have been some upgrades.
|
||||
|
||||
**Dynamic Value**
|
||||
|
||||
This fields can take a shortcode, with two important provisions:
|
||||
The bread and butter of this plugin, set a dynamic value! This field can take any shortcode, with two important provisions:
|
||||
|
||||
1. The shortcode should NOT include the normal square brackets (`[` and `]`). So, instead of `[CF7_GET key='value']` you would use `CF7_GET key='value'`.
|
||||
1. Any parameters in the shortcode must use single quotes. That is: `CF7_GET key='value'` and not `CF7_GET key="value"`
|
||||
|
||||
**Dynamic placeholder**
|
||||
= Dynamic Placeholder =
|
||||
|
||||
Only available for the dynamic text form tag, this field can take static text or a shortcode. If using a shortcode, the same syntax applies from the dynamic value field. However, this field also has a few more needs:
|
||||
Set a dynamic placeholder with this attribute! This feature accepts static text or a shortcode. If using a shortcode, the same syntax applies from the dynamic value field. However, this field also has a few more needs:
|
||||
|
||||
1. The text/shortcode must first have apostrophes converted to it's HTML entity code, `'`
|
||||
1. After that, it must be URL encoded so that spaces become `%20` and other non-alphanumeric characters are converted.
|
||||
|
||||
**Read Only Attribute**
|
||||
If you're using Contact Form 7's tag generator to create the form tag, those extra needs are already taken care of. Dynamic placeholders are not available for dynamic hidden form tags.
|
||||
|
||||
Only available for the dynamic text form tag, simply check this box if you do not want to let users edit this field. It will add the `readonly` attribute to your form field.
|
||||
Learn more and see examples from [the DTX 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).
|
||||
|
||||
= INCLUDED SHORTCODES =
|
||||
= Compatible with Caching Plugins =
|
||||
|
||||
DTX is cache friendly! You can set a field to be calculated after the page loads by setting the `dtx_pageload` attribute to any dynamic form tag.
|
||||
|
||||
Many websites use caching plugins to optimize for performance. If your website caches the HTML of the form, then any dynamic form fields you have get their first calculated value cached alongside it. This becomes an issue if you're using DTX to pull values from a cookie or the current URL's query string.
|
||||
|
||||
This is best for dynamic form fields that:
|
||||
|
||||
* gets the current URL
|
||||
* gets a value from the URL query
|
||||
* gets a value from a cookie
|
||||
* gets the current user's info
|
||||
* generates a unique identifier (GUID)
|
||||
|
||||
For dynamic fields that are page-specific, it's perfectly safe to cache those values. For example, dynamic form fields that:
|
||||
|
||||
* getting the page or post's ID, title, or slug
|
||||
* getting post meta for the current page
|
||||
* getting the post's assigned categories, tags, or other custom taxonomy
|
||||
* getting site info
|
||||
* getting theme modification values
|
||||
|
||||
*Note: Enabling a dynamic field to be calculated after the page loads will add frontend JavaScript. Depending on the shortcode used as the dynamic value, an AJAX call to the server may be sent to be processed. The script is minified and loaded in the footer and is deferred, minimizing impact on site performance and the AJAX calls are called asynchronously to avoid being a render-blocking resource and minimizing main-thread work. The script itself can be safely cached too.*
|
||||
|
||||
Learn more and see examples from [the DTX 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).
|
||||
|
||||
= Read Only Form Fields =
|
||||
|
||||
Check this box if you do not want to let users edit this field. It will add the `readonly` attribute to the input form field. This feature is not available for dynamic hidden form tags.
|
||||
|
||||
= Obfuscate Values for Enhanced Privacy =
|
||||
|
||||
If you're pre-filling a form field with an email address, bots can scrape that value from the page and use it for spam. You can add an additional layer of protecting by obfuscating the value, which turns each character into it's ASCII code. To the human eye, it looks like the character it's supposed to be because browsers will render the ASCII code, but for bots, it won't look like an email address!
|
||||
|
||||
## HOW TO USE IT ##
|
||||
|
||||
After installing and activating the plugin, you will have 2 new tag types to select from when creating or editing a Contact Form 7 form: the dynamic text field and dynamic hidden field. Most of the options in their tag generators will be familiar to Contact Form 7 users but there have been some upgrades.
|
||||
|
||||
= How to Obfuscate Values =
|
||||
|
||||
All of the shortcodes included with the DTX plugin allow the `obfuscate` attribute that you can set to any truthy value to provide an additional layer of security for sensitive data.
|
||||
|
||||
The Contact Form 7 tag with obfuscation turned on would look like this: `[dynamictext user_email "CF7_get_current_user key='user_email' obfuscate='on'"]`
|
||||
|
||||
= How to Enable Cache-Friendly Mode =
|
||||
|
||||
All of the dynamic form tags can be enabled for processing on the frontend of the website, or the client-side, by adding the `dtx_pageload` attribute to the Contact Form 7 form tag.
|
||||
|
||||
In the form editor of Contact Form 7, your form tag would look like: `[dynamictext current_url dtx_pageload "CF7_URL"]`
|
||||
|
||||
If using the tag generator, it's as simple as checking a box!
|
||||
|
||||
## INCLUDED SHORTCODES ##
|
||||
|
||||
The plugin includes several shortcodes for use with the Dynamic Text Extension right out of the box. You can write your own as well—any self-closing shortcode will work, even with attributes!
|
||||
|
||||
**Current URL or Current URL Part**
|
||||
= Current URL or Part =
|
||||
|
||||
Retrieve the current URL: `CF7_URL`
|
||||
|
||||
Your Contact Form 7 Tag would look like: `[dynamictext dynamicname "CF7_URL"]`
|
||||
In the form editor of Contact Form 7, your form tag would look like: `[dynamictext dynamicname "CF7_URL"]`
|
||||
|
||||
Optional parameter: `part`, which will return a parsed part of the URL. Valid values are `host`, `query`, and `path`
|
||||
|
||||
Host: Just the domain name and tld
|
||||
Host: Just the domain name and tld
|
||||
`[dynamictext host "CF7_URL part='host'"]`
|
||||
|
||||
Query: The query string after the ?, if one exists
|
||||
Query: The query string after the ?, if one exists
|
||||
`[dynamictext query "CF7_URL part='query'"]`
|
||||
|
||||
Path: The URL path, for example, /contact, if one exists
|
||||
Path: The URL path, for example, /contact, if one exists
|
||||
`[dynamictext path "CF7_URL part='path'"]`
|
||||
|
||||
Learn more and see examples from [the DTX Knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-current-url/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
|
||||
|
||||
**Referrer URL**
|
||||
= Referrer URL =
|
||||
|
||||
Get the referral URL, if it exists. Note that this is not necessarily reliable as not all browsers send this data.
|
||||
|
||||
CF7 Tag: `[dynamictext dynamicname "CF7_referrer"]`
|
||||
|
||||
**Post/Page Info**
|
||||
Learn more and see examples from [the DTX Knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-referrer-url/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
|
||||
Retrieve information about the current post or page that the contact form is displayed on. The shortcode works as follows:
|
||||
= Current Page Variables =
|
||||
|
||||
Retrieve information about the current page that the contact form is displayed on. Works great for use in templated areas like the site header, footer, widget, or sidebar! The shortcode works as follows:
|
||||
|
||||
Built-in shortcode: `CF7_get_current_var`
|
||||
|
||||
Required attribute: `key`
|
||||
|
||||
Possible values for `key` include:
|
||||
|
||||
* `id`
|
||||
* `title`
|
||||
* `url` (an alias for `CF7_URL`)
|
||||
* `slug`
|
||||
* `featured_image`
|
||||
* `terms` (an alias for `CF7_get_taxonomy`)
|
||||
|
||||
For pages that use a `WP_POST` object, this acts as an alias for `CF7_get_post_var` so those attributes work here as well.
|
||||
|
||||
For author pages, this acts as an alias for `CF7_get_current_user` so those attributes work here as well.
|
||||
|
||||
In the form editor of Contact Form 7, your form tag's value could look like: `CF7_get_current_var key='title'`
|
||||
|
||||
And then the full form tag would be: `[dynamictext dynamicname "CF7_get_current_var key='title'"]`
|
||||
|
||||
Learn more and see examples from [the DTX 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).
|
||||
|
||||
= Post/Page Info =
|
||||
|
||||
Retrieve information about the current post or page (must be for a WP_POST object) that the contact form is displayed on. The shortcode works as follows:
|
||||
|
||||
`CF7_get_post_var key='title'` <-- retrieves the Post's Title
|
||||
`CF7_get_post_var key='slug'` <-- retrieves the Post's Slug
|
||||
@@ -97,7 +192,9 @@ Dynamic value: `CF7_get_post_var key='title' post_id='245'`
|
||||
|
||||
Contact Form 7 Tag: `[dynamictext dynamicname "CF7_get_post_var key='title' post_id='245'"]`
|
||||
|
||||
**Post Meta & Custom Fields**
|
||||
Learn more and see examples from [the DTX Knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-post-page-variables//?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
|
||||
= Post Meta & Custom Fields =
|
||||
|
||||
Retrieve custom fields from the current post/page. Just set the custom field as the key in the shortcode.
|
||||
|
||||
@@ -108,7 +205,9 @@ And the tag looks like this: `[dynamictext dynamicname "CF7_get_custom_field key
|
||||
For the purposes of including an email address, you can obfuscate the custom field value by setting obfuscate='on' in the shortcode like this:
|
||||
`[dynamictext dynamicname "CF7_get_custom_field key='my_custom_field' obfuscate='on'"]`
|
||||
|
||||
**Featured Images & Media Attachments**
|
||||
Learn more and see examples from [the DTX Knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-post-meta-custom-fields/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
|
||||
= Featured Images & Media Attachments =
|
||||
|
||||
Retrieve the current post's featured image, the featured image of a different page, or any attachment from the Media Library with this shortcode!
|
||||
|
||||
@@ -130,7 +229,9 @@ If I wanted to get a specific image at a specific size, I can use this:
|
||||
|
||||
The only two attributes that can’t play together is `id` and `post_id`. If both are specified, it will get the attachment specified by `id` and completely ignore the `post_id` attribute. If neither are specified, then it looks to the current featured image assigned to the global `$post` object.
|
||||
|
||||
**Current User Info & User Meta**
|
||||
Learn more and see examples from [the DTX 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).
|
||||
|
||||
= Current User Info & User Meta =
|
||||
|
||||
Get data about the current logged-in user.
|
||||
|
||||
@@ -152,7 +253,9 @@ But also custom meta user keys!
|
||||
For the purposes of including an email address, you can obfuscate the value by setting obfuscate='on' in the shortcode like this:
|
||||
`[dynamictext dynamicname "CF7_get_current_user key='user_email' obfuscate='on'"]`
|
||||
|
||||
**Site/Blog Info**
|
||||
Learn more and see examples from [the DTX Knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-current-user-user-meta/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
|
||||
= Site/Blog Info =
|
||||
|
||||
Want to grab some information from your blog like the URL or the site name? Use the `CF7_bloginfo` shortcode. For example, to get the site's URL:
|
||||
|
||||
@@ -162,7 +265,15 @@ Your Content Form 7 Tag will look something like this: `[dynamictext dynamicname
|
||||
|
||||
Your form's dynamicname text input will then be pre-populated with your site's URL
|
||||
|
||||
**HTTP GET Variables**
|
||||
Learn more and see examples from [the DTX Knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-site-blog-information/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
|
||||
= Theme Options =
|
||||
|
||||
Want to retrieve values from your active theme's Customizer? Now you can with the `CF7_get_theme_option` shortcode.
|
||||
|
||||
Learn more and see examples from [the DTX 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).
|
||||
|
||||
= HTTP GET Variables =
|
||||
|
||||
Want to use a variable from the PHP `$_GET` array? Just use the `CF7_GET` shortcode. For example, if you want to get the foo parameter from the url
|
||||
`http://mysite.com?foo=bar`
|
||||
@@ -173,7 +284,9 @@ Your Content Form 7 Tag will look something like this: `[dynamictext dynamicname
|
||||
|
||||
Your form's dynamicname text input will then be pre-populated with the value of `foo`, in this case, `bar`
|
||||
|
||||
**HTTP POST Variables**
|
||||
Learn more and see examples from [the DTX Knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-php-get-variables/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
|
||||
= HTTP POST Variables =
|
||||
|
||||
Grab variables from the PHP `$_POST` array. The shortcode is much like the GET shortcode:
|
||||
|
||||
@@ -181,15 +294,25 @@ Dynamic value: `CF7_POST key='foo'`
|
||||
|
||||
Your Content Form 7 Tag will look something like this: `[dynamictext dynamicname "CF7_POST key='foo'"]`
|
||||
|
||||
**GUID**
|
||||
Learn more and see examples from [the DTX Knowledge base](https://aurisecreative.com/docs/contact-form-7-dynamic-text-extension/shortcodes/dtx-shortcode-php-post-variables/?utm_source=wordpress.org&utm_medium=link&utm_campaign=contact-form-7-dynamic-text-extension&utm_content=readme).
|
||||
|
||||
= Cookie Values =
|
||||
|
||||
If your WordPress website uses cookies, you might want to pull the value of a specific cookie into a form. You can do that with the `CF7_get_cookie` shortcode. It only needs a `key` attribute.
|
||||
|
||||
Dynamic value: `CF7_get_cookie key='foo'`
|
||||
|
||||
Your Content Form 7 Tag will look something like this: `[dynamictext dynamicname "CF7_get_cookie key='foo'"]`
|
||||
|
||||
Learn more and see examples from [the DTX 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).
|
||||
|
||||
= GUID =
|
||||
|
||||
Generate a globally unique identifier (GUID) in a form field. This is a great utility shortcode for forms that need unique identifiers for support tickets, receipts, reference numbers, etc., without having to expose personally identifiable information (PII). This shortcode takes no parameters: `CF7_guid`
|
||||
|
||||
Your Contact Form 7 Tag would look like: `[dynamictext dynamicname "CF7_guid"]`
|
||||
In the form editor of Contact Form 7, your form tag would look like: `[dynamictext dynamicname "CF7_guid"]`
|
||||
|
||||
**Shortcode attribute: obfuscate**
|
||||
|
||||
All of the included shortcodes have an `obfuscate` attribute that you can set to any truthy value to provide an additional layer of security for sensitive data.
|
||||
Learn more and see examples from [the DTX 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).
|
||||
|
||||
== Installation ==
|
||||
|
||||
@@ -232,7 +355,20 @@ This method is the most involved as it requires you to be familiar with the proc
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. A screenshot of the form-tag generator for the dynamic text field.
|
||||
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 ==
|
||||
|
||||
@@ -240,124 +376,54 @@ Please check out the [FAQ on our website](https://aurisecreative.com/docs/contac
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
* 3.1.3 Fixed the syntax error that reappeared in 3.1.2. My apologies!
|
||||
= 4.1.0 =
|
||||
Extend functionality without losing your work!
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 3.2 =
|
||||
= 4.1.0 =
|
||||
|
||||
* 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 and AuRise Creative
|
||||
* 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 =
|
||||
|
||||
= 3.1.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
|
||||
|
||||
* Fix: Fixed the syntax error that reappeared in 3.1.2.
|
||||
= 4.0.2 =
|
||||
|
||||
= 3.1.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.
|
||||
|
||||
**Release Date: January 27, 2023**
|
||||
= 4.0.1 =
|
||||
|
||||
* Fix: updated the text domain to match the plugin slug
|
||||
* Fix: updated all of the translated strings to match
|
||||
* Fix: addressed bug that prevented translation for cache compatibility description
|
||||
|
||||
= 3.1.1 =
|
||||
= 4.0.0 =
|
||||
|
||||
**Release Date: January 26, 2023**
|
||||
* 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
|
||||
|
||||
* 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
|
||||
= Older Releases =
|
||||
|
||||
= 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`
|
||||
|
||||
= 2.0.3 =
|
||||
|
||||
* Security: [Fix Reflected XSS](https://web.archive.org/web/20230121180428/https://sevenspark.com/docs/cf7-dtx-security-2019-07-24)
|
||||
|
||||
= 2.0.2.1 =
|
||||
|
||||
* Update changelog properly for 2.0.2 changes:
|
||||
|
||||
= 2.0.2 =
|
||||
|
||||
* Update deprecated `get_currentuserinfo()` function to `wp_get_current_user()`
|
||||
* Update deprecated functions from `WPCF7_add_shortcode` to `WPCF7_add_formtag` and class from `WPCF7_Shortcode` to `WPCF7_FormTag` to comply with CF7 4.6 changes
|
||||
|
||||
= 2.0.1 =
|
||||
|
||||
* Hook change to guarantee the plugin only runs when Contact Form 7 is present in the admin (avoids errors if Contact Form 7 is disabled, or if there is a plugin sequencing issue)
|
||||
|
||||
= 2.0 =
|
||||
|
||||
* Complete rewrite for Compatibility with Contact Form 7 v4
|
||||
|
||||
= 1.2 =
|
||||
|
||||
* Compatibility update for Contact Form 7 v3.9
|
||||
|
||||
= 1.1.0.2 =
|
||||
|
||||
* Updated to work with Contact Form 7 v3.7.x
|
||||
|
||||
= 1.1.0.1 =
|
||||
|
||||
* Removed undefined variable warning
|
||||
|
||||
= 1.1 =
|
||||
|
||||
* Updated for compatibility with Contact Form 7 v3.6
|
||||
* Added Referrer shortcode
|
||||
|
||||
= 1.0.4.2 =
|
||||
|
||||
* Fixed a bug that created repeating square brackets around dynamic text values in cases where the form doesn't validate and JavaScript is deactivated.
|
||||
|
||||
= 1.0.4.1 =
|
||||
|
||||
* Removed trailing whitespace to fix "Headers already sent" errors
|
||||
|
||||
= 1.0.4 =
|
||||
|
||||
* Added Current User Info shortcode
|
||||
* Added Post Custom Field shortcode (with obfuscation support)
|
||||
* Added Hidden Field capability
|
||||
|
||||
= 1.0.3 =
|
||||
|
||||
* Added $_POST shortcode
|
||||
* Added current post/page variable shortcode
|
||||
* Added current URL shortcode
|
||||
|
||||
= 1.0.2 =
|
||||
|
||||
* Fixed administrative control panel dependency issue
|
||||
|
||||
= 1.0.1 =
|
||||
|
||||
* Fixed dependency issue.
|
||||
Please see our [additional changelog.txt file](https://plugins.trac.wordpress.org/browser/contact-form-7-dynamic-text-extension/trunk/changelog.txt)
|
||||
Reference in New Issue
Block a user