Contact Form 7 Dynamic Text Extension - Version 2.0.2

Version Description

Download this release

Release Info

Developer sevenspark
Plugin Icon wp plugin Contact Form 7 Dynamic Text Extension
Version 2.0.2
Comparing to
See all releases

Code changes from version 2.0.1 to 2.0.2

contact-form-7-dynamic-text-extension.php CHANGED
@@ -4,13 +4,13 @@
4
  Plugin Name: Contact Form 7 - Dynamic Text Extension
5
  Plugin URI: http://sevenspark.com/wordpress-plugins/contact-form-7-dynamic-text-extension
6
  Description: Provides a dynamic text field that accepts any shortcode to generate the content. Requires Contact Form 7
7
- Version: 2.0.1
8
  Author: Chris Mavricos, SevenSpark
9
  Author URI: http://sevenspark.com
10
  License: GPL2
11
  */
12
 
13
- /* Copyright 2010-2015 Chris Mavricos, SevenSpark http://sevenspark.com
14
 
15
  This program is free software; you can redistribute it and/or modify
16
  it under the terms of the GNU General Public License, version 2, as
@@ -36,12 +36,12 @@ function wpcf7dtx_init(){
36
 
37
 
38
  function wpcf7dtx_add_shortcode_dynamictext() {
39
- wpcf7_add_shortcode(
40
  array( 'dynamictext' , 'dynamictext*' , 'dynamichidden' ),
41
  'wpcf7dtx_dynamictext_shortcode_handler', true );
42
  }
43
  function wpcf7dtx_dynamictext_shortcode_handler( $tag ) {
44
- $tag = new WPCF7_Shortcode( $tag );
45
 
46
  if ( empty( $tag->name ) )
47
  return '';
@@ -120,7 +120,7 @@ function wpcf7dtx_dynamictext_shortcode_handler( $tag ) {
120
 
121
  //add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 ); // in init
122
  function wpcf7dtx_dynamictext_validation_filter( $result, $tag ) {
123
- $tag = new WPCF7_Shortcode( $tag );
124
 
125
  $name = $tag->name;
126
 
@@ -379,17 +379,17 @@ add_shortcode('CF7_get_custom_field', 'cf7_get_custom_field');
379
 
380
  /* Insert information about the current user
381
  * New in 1.0.4
382
- * See http://codex.wordpress.org/Function_Reference/get_currentuserinfo
383
  */
384
  function cf7_get_current_user($atts){
385
  extract(shortcode_atts(array(
386
  'key' => 'user_login',
387
  ), $atts));
388
-
389
- global $current_user;
390
- get_currentuserinfo();
391
-
392
- $val = $current_user->$key;
393
  return $val;
394
  }
395
  add_shortcode('CF7_get_current_user', 'cf7_get_current_user');
4
  Plugin Name: Contact Form 7 - Dynamic Text Extension
5
  Plugin URI: http://sevenspark.com/wordpress-plugins/contact-form-7-dynamic-text-extension
6
  Description: Provides a dynamic text field that accepts any shortcode to generate the content. Requires Contact Form 7
7
+ Version: 2.0.2
8
  Author: Chris Mavricos, SevenSpark
9
  Author URI: http://sevenspark.com
10
  License: GPL2
11
  */
12
 
13
+ /* Copyright 2010-2017 Chris Mavricos, SevenSpark http://sevenspark.com
14
 
15
  This program is free software; you can redistribute it and/or modify
16
  it under the terms of the GNU General Public License, version 2, as
36
 
37
 
38
  function wpcf7dtx_add_shortcode_dynamictext() {
39
+ wpcf7_add_form_tag(
40
  array( 'dynamictext' , 'dynamictext*' , 'dynamichidden' ),
41
  'wpcf7dtx_dynamictext_shortcode_handler', true );
42
  }
43
  function wpcf7dtx_dynamictext_shortcode_handler( $tag ) {
44
+ $tag = new WPCF7_FormTag( $tag );
45
 
46
  if ( empty( $tag->name ) )
47
  return '';
120
 
121
  //add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 ); // in init
122
  function wpcf7dtx_dynamictext_validation_filter( $result, $tag ) {
123
+ $tag = new WPCF7_FormTag( $tag );
124
 
125
  $name = $tag->name;
126
 
379
 
380
  /* Insert information about the current user
381
  * New in 1.0.4
382
+ * See https://codex.wordpress.org/Function_Reference/wp_get_current_user
383
  */
384
  function cf7_get_current_user($atts){
385
  extract(shortcode_atts(array(
386
  'key' => 'user_login',
387
  ), $atts));
388
+ $val = '';
389
+ if( is_user_logged_in() ) {
390
+ $current_user = wp_get_current_user();
391
+ $val = $current_user->$key;
392
+ }
393
  return $val;
394
  }
395
  add_shortcode('CF7_get_current_user', 'cf7_get_current_user');
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: sevenspark
3
  Donate link: http://bit.ly/bVogDN
4
  Tags: Contact Form 7, Contact, Contact Form, dynamic, text, input, GET, POST, title, slug
5
- Requires at least: 4.0
6
- Tested up to: 4.4.1
7
- Stable tag: 2.0.1
8
 
9
  This plugin provides 2 new tag types for the Contact Form 7 Plugin. It allows the dynamic generation of content for a text input box via any shortcode.
10
  It also offers dynamic hidden field functionality, which can be utilized to dynamically set the Email Recipient (To:) address.
@@ -25,7 +25,7 @@ While default values in Contact Form 7 are static. CF7 DTX lets you create pre-p
25
 
26
  There are many more case-specific examples. I searched for a solution, and there are some decent hacks out there. Many of them are
27
  explored in this forum topic:
28
- [Contact Form 7 Input Fields Values as PHP Get-Viarables](http://wordpress.org/support/topic/contact-form-7-input-fields-values-as-php-get-viarables).
29
  However, they all involved hacking the current Contact Form 7 code, which means next time the plugin is updated their edits will be
30
  overwritten. That's bad.
31
 
@@ -37,6 +37,8 @@ This plugin provides a new tag type for the Contact Form 7 Plugin. It allows the
37
  For example, it comes with several built-in shortcodes that will allow the Contact Form to be populated from any $_GET PHP variable or any info from the
38
  get_bloginfo() function, among others. See below for included shortcodes.
39
 
 
 
40
  = HOW TO USE IT =
41
 
42
  After installing and activating the plugin, the Contact Form 7 tag generator will have 2 new tag types: Dynamic Text Field and Dynamic Hidden Field. Most of the options will be
2
  Contributors: sevenspark
3
  Donate link: http://bit.ly/bVogDN
4
  Tags: Contact Form 7, Contact, Contact Form, dynamic, text, input, GET, POST, title, slug
5
+ Requires at least: 4.7
6
+ Tested up to: 4.7.1
7
+ Stable tag: 2.0.2
8
 
9
  This plugin provides 2 new tag types for the Contact Form 7 Plugin. It allows the dynamic generation of content for a text input box via any shortcode.
10
  It also offers dynamic hidden field functionality, which can be utilized to dynamically set the Email Recipient (To:) address.
25
 
26
  There are many more case-specific examples. I searched for a solution, and there are some decent hacks out there. Many of them are
27
  explored in this forum topic:
28
+ [Contact Form 7 Input Fields Values as PHP Get-Variables](http://wordpress.org/support/topic/contact-form-7-input-fields-values-as-php-get-viarables).
29
  However, they all involved hacking the current Contact Form 7 code, which means next time the plugin is updated their edits will be
30
  overwritten. That's bad.
31
 
37
  For example, it comes with several built-in shortcodes that will allow the Contact Form to be populated from any $_GET PHP variable or any info from the
38
  get_bloginfo() function, among others. See below for included shortcodes.
39
 
40
+ Don't see the shortcode you need on the list? You can write a custom one! Any shortcode that returns a string value can be used here. The included shortcodes just cover the most common scenarios, but the plugin provides the flexibility for you to grab any value you have access to programmatically.
41
+
42
  = HOW TO USE IT =
43
 
44
  After installing and activating the plugin, the Contact Form 7 tag generator will have 2 new tag types: Dynamic Text Field and Dynamic Hidden Field. Most of the options will be
trunk/contact-form-7-dynamic-text-extension.php ADDED
@@ -0,0 +1,438 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ Plugin Name: Contact Form 7 - Dynamic Text Extension
5
+ Plugin URI: http://sevenspark.com/wordpress-plugins/contact-form-7-dynamic-text-extension
6
+ Description: Provides a dynamic text field that accepts any shortcode to generate the content. Requires Contact Form 7
7
+ Version: 2.0.2
8
+ Author: Chris Mavricos, SevenSpark
9
+ Author URI: http://sevenspark.com
10
+ License: GPL2
11
+ */
12
+
13
+ /* Copyright 2010-2017 Chris Mavricos, SevenSpark http://sevenspark.com
14
+
15
+ This program is free software; you can redistribute it and/or modify
16
+ it under the terms of the GNU General Public License, version 2, as
17
+ published by the Free Software Foundation.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+
29
+
30
+ add_action( 'plugins_loaded', 'wpcf7dtx_init' , 20 );
31
+ function wpcf7dtx_init(){
32
+ add_action( 'wpcf7_init', 'wpcf7dtx_add_shortcode_dynamictext' );
33
+ add_filter( 'wpcf7_validate_dynamictext*', 'wpcf7dtx_dynamictext_validation_filter', 10, 2 );
34
+ }
35
+
36
+
37
+
38
+ function wpcf7dtx_add_shortcode_dynamictext() {
39
+ wpcf7_add_form_tag(
40
+ array( 'dynamictext' , 'dynamictext*' , 'dynamichidden' ),
41
+ 'wpcf7dtx_dynamictext_shortcode_handler', true );
42
+ }
43
+ function wpcf7dtx_dynamictext_shortcode_handler( $tag ) {
44
+ $tag = new WPCF7_FormTag( $tag );
45
+
46
+ if ( empty( $tag->name ) )
47
+ return '';
48
+
49
+ $validation_error = wpcf7_get_validation_error( $tag->name );
50
+
51
+ $class = wpcf7_form_controls_class( $tag->type, 'wpcf7dtx-dynamictext' );
52
+
53
+
54
+ if ( $validation_error )
55
+ $class .= ' wpcf7-not-valid';
56
+
57
+ $atts = array();
58
+
59
+ $atts['size'] = $tag->get_size_option( '40' );
60
+ $atts['maxlength'] = $tag->get_maxlength_option();
61
+ $atts['minlength'] = $tag->get_minlength_option();
62
+
63
+ if ( $atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength'] ) {
64
+ unset( $atts['maxlength'], $atts['minlength'] );
65
+ }
66
+
67
+ $atts['class'] = $tag->get_class_option( $class );
68
+ $atts['id'] = $tag->get_id_option();
69
+ $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
70
+
71
+ if ( $tag->has_option( 'readonly' ) )
72
+ $atts['readonly'] = 'readonly';
73
+
74
+ if ( $tag->is_required() )
75
+ $atts['aria-required'] = 'true';
76
+
77
+ $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
78
+
79
+ $value = (string) reset( $tag->values );
80
+
81
+ if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
82
+ $atts['placeholder'] = $value;
83
+ $value = '';
84
+ }
85
+
86
+ $value = $tag->get_default_option( $value );
87
+
88
+ $value = wpcf7_get_hangover( $tag->name, $value );
89
+
90
+ $scval = do_shortcode('['.$value.']');
91
+ if( $scval != '['.$value.']' ){
92
+ $value = esc_attr( $scval );
93
+ }
94
+
95
+ $atts['value'] = $value;
96
+
97
+ //echo '<pre>'; print_r( $tag ); echo '</pre>';
98
+ switch( $tag->basetype ){
99
+ case 'dynamictext':
100
+ $atts['type'] = 'text';
101
+ break;
102
+ case 'dynamichidden':
103
+ $atts['type'] = 'hidden';
104
+ break;
105
+ default:
106
+ $atts['type'] = 'text';
107
+ break;
108
+ }
109
+
110
+ $atts['name'] = $tag->name;
111
+
112
+ $atts = wpcf7_format_atts( $atts );
113
+
114
+ $html = sprintf(
115
+ '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
116
+ sanitize_html_class( $tag->name ), $atts, $validation_error );
117
+
118
+ return $html;
119
+ }
120
+
121
+ //add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 ); // in init
122
+ function wpcf7dtx_dynamictext_validation_filter( $result, $tag ) {
123
+ $tag = new WPCF7_FormTag( $tag );
124
+
125
+ $name = $tag->name;
126
+
127
+ $value = isset( $_POST[$name] )
128
+ ? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) )
129
+ : '';
130
+
131
+ if ( 'dynamictext' == $tag->basetype ) {
132
+ if ( $tag->is_required() && '' == $value ) {
133
+ $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
134
+ }
135
+ }
136
+
137
+ if ( ! empty( $value ) ) {
138
+ $maxlength = $tag->get_maxlength_option();
139
+ $minlength = $tag->get_minlength_option();
140
+
141
+ if ( $maxlength && $minlength && $maxlength < $minlength ) {
142
+ $maxlength = $minlength = null;
143
+ }
144
+
145
+ $code_units = wpcf7_count_code_units( $value );
146
+
147
+ if ( false !== $code_units ) {
148
+ if ( $maxlength && $maxlength < $code_units ) {
149
+ $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) );
150
+ } elseif ( $minlength && $code_units < $minlength ) {
151
+ $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) );
152
+ }
153
+ }
154
+ }
155
+
156
+ return $result;
157
+ }
158
+
159
+
160
+
161
+
162
+ if ( is_admin() ) {
163
+ //add_action( 'admin_init', 'wpcf7dtx_add_tag_generator_dynamictext', 25 );
164
+ add_action( 'wpcf7_admin_init' , 'wpcf7dtx_add_tag_generator_dynamictext' , 100 );
165
+ }
166
+
167
+ function wpcf7dtx_add_tag_generator_dynamictext() {
168
+
169
+ if ( ! class_exists( 'WPCF7_TagGenerator' ) ) return;
170
+
171
+ $tag_generator = WPCF7_TagGenerator::get_instance();
172
+ $tag_generator->add( 'dynamictext', __( 'dynamic text', 'contact-form-7' ),
173
+ 'wpcf7dtx_tag_generator_dynamictext' );
174
+
175
+ $tag_generator->add( 'dynamichidden', __( 'dynamic hidden', 'contact-form-7' ),
176
+ 'wpcf7dtx_tag_generator_dynamictext' );
177
+ }
178
+
179
+
180
+ function wpcf7dtx_tag_generator_dynamictext( $contact_form , $args = '' ){
181
+ $args = wp_parse_args( $args, array() );
182
+ $type = $args['id'];
183
+
184
+ $description;
185
+
186
+
187
+ switch( $type ){
188
+ case 'dynamictext':
189
+ $description = __( "Generate a form-tag for a single-line plain text input field, with a dynamically generated default value.", 'contact-form-7' );
190
+ //$type = 'text';
191
+ break;
192
+ case 'dynamichidden':
193
+ $description = __( "Generate a form-tag for a hidden input field, with a dynamically generated default value.", 'contact-form-7' );
194
+ //$type = 'hidden';
195
+ break;
196
+ default:
197
+ //$type = 'text';
198
+ break;
199
+ }
200
+
201
+
202
+
203
+
204
+
205
+ ?>
206
+ <div class="control-box">
207
+ <fieldset>
208
+ <legend><?php echo $description; ?></legend>
209
+
210
+ <table class="form-table">
211
+ <tbody>
212
+ <tr>
213
+ <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
214
+ <td>
215
+ <fieldset>
216
+ <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
217
+ <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
218
+ </fieldset>
219
+ </td>
220
+ </tr>
221
+
222
+ <tr>
223
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
224
+ <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
225
+ </tr>
226
+
227
+ <tr>
228
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Dynamic value', 'contact-form-7' ) ); ?></label></th>
229
+ <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
230
+ <?php _e( 'You can enter any short code. Just leave out the square brackets (<code>[]</code>) and only use single quotes (<code>\'</code> not <code>"</code>). <br/>So <code>[shortcode attribute="value"]</code> becomes <code>shortcode attribute=\'value\'</code>', 'contact-form-7' ); ?></td>
231
+ </tr>
232
+
233
+ <tr>
234
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
235
+ <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
236
+ </tr>
237
+
238
+ <tr>
239
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
240
+ <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
241
+ </tr>
242
+
243
+ </tbody>
244
+ </table>
245
+ </fieldset>
246
+ </div>
247
+
248
+ <div class="insert-box">
249
+ <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
250
+
251
+ <div class="submitbox">
252
+ <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
253
+ </div>
254
+
255
+ <br class="clear" />
256
+
257
+ </div>
258
+ <?php
259
+ }
260
+
261
+
262
+
263
+
264
+
265
+
266
+ /*****************************************************
267
+ * CF7 DTX Included Shortcodes
268
+ *
269
+ * Used like this:
270
+ *
271
+ * CF7_GET val='value'
272
+ *
273
+ * No [] and single quotes ' rather than double "
274
+ *
275
+ *****************************************************/
276
+
277
+ /* Insert a $_GET variable */
278
+ function cf7_get($atts){
279
+ extract(shortcode_atts(array(
280
+ 'key' => 0,
281
+ ), $atts));
282
+ $value = '';
283
+ if( isset( $_GET[$key] ) ){
284
+ $value = urldecode($_GET[$key]);
285
+ }
286
+ return $value;
287
+ }
288
+ add_shortcode('CF7_GET', 'cf7_get');
289
+
290
+ /* See http://codex.wordpress.org/Function_Reference/get_bloginfo */
291
+ function cf7_bloginfo($atts){
292
+ extract(shortcode_atts(array(
293
+ 'show' => 'name'
294
+ ), $atts));
295
+
296
+ return get_bloginfo($show);
297
+ }
298
+ add_shortcode('CF7_bloginfo', 'cf7_bloginfo');
299
+
300
+ /* Insert a $_POST variable (submitted form value)*/
301
+ function cf7_post($atts){
302
+ extract(shortcode_atts(array(
303
+ 'key' => -1,
304
+ ), $atts));
305
+ if($key == -1) return '';
306
+ $val = '';
307
+ if( isset( $_POST[$key] ) ){
308
+ $val = $_POST[$key];
309
+ }
310
+ return $val;
311
+ }
312
+ add_shortcode('CF7_POST', 'cf7_post');
313
+
314
+ /* Insert a $post (Blog Post) Variable */
315
+ function cf7_get_post_var($atts){
316
+ extract(shortcode_atts(array(
317
+ 'key' => 'post_title',
318
+ ), $atts));
319
+
320
+ switch($key){
321
+ case 'slug':
322
+ $key = 'post_name';
323
+ break;
324
+ case 'title':
325
+ $key = 'post_title';
326
+ break;
327
+ }
328
+
329
+ global $post;
330
+ //echo '<pre>'; print_r($post); echo '</pre>';
331
+ $val = $post->$key;
332
+ return $val;
333
+ }
334
+ add_shortcode('CF7_get_post_var', 'cf7_get_post_var');
335
+
336
+ /* Insert the current URL */
337
+ function cf7_url(){
338
+ $pageURL = 'http';
339
+ if( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on"){ $pageURL .= "s"; }
340
+
341
+ $pageURL .= "://";
342
+
343
+ if( isset( $_SERVER["SERVER_PORT"] ) && $_SERVER["SERVER_PORT"] != "80" ){
344
+ $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
345
+ } else {
346
+ $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
347
+ }
348
+ return $pageURL;
349
+ }
350
+ add_shortcode('CF7_URL', 'cf7_url');
351
+
352
+ /* Insert a Custom Post Field
353
+ * New in 1.0.4
354
+ */
355
+ function cf7_get_custom_field($atts){
356
+ extract(shortcode_atts(array(
357
+ 'key' => '',
358
+ 'post_id' => -1,
359
+ 'obfuscate' => 'off'
360
+ ), $atts));
361
+
362
+ if($post_id < 0){
363
+ global $post;
364
+ if(isset($post)) $post_id = $post->ID;
365
+ }
366
+
367
+ if($post_id < 0 || empty($key)) return '';
368
+
369
+ $val = get_post_meta($post_id, $key, true);
370
+
371
+ if($obfuscate == 'on'){
372
+ $val = cf7dtx_obfuscate($val);
373
+ }
374
+
375
+ return $val;
376
+
377
+ }
378
+ add_shortcode('CF7_get_custom_field', 'cf7_get_custom_field');
379
+
380
+ /* Insert information about the current user
381
+ * New in 1.0.4
382
+ * See https://codex.wordpress.org/Function_Reference/wp_get_current_user
383
+ */
384
+ function cf7_get_current_user($atts){
385
+ extract(shortcode_atts(array(
386
+ 'key' => 'user_login',
387
+ ), $atts));
388
+ $val = '';
389
+ if( is_user_logged_in() ) {
390
+ $current_user = wp_get_current_user();
391
+ $val = $current_user->$key;
392
+ }
393
+ return $val;
394
+ }
395
+ add_shortcode('CF7_get_current_user', 'cf7_get_current_user');
396
+
397
+
398
+
399
+ function cf7_get_referrer( $atts ){
400
+ return isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '';
401
+ }
402
+ add_shortcode( 'CF7_referrer' , 'cf7_get_referrer' );
403
+
404
+
405
+ function cf7dtx_obfuscate($val){
406
+ $link = '';
407
+ foreach(str_split($val) as $letter)
408
+ $link .= '&#'.ord($letter).';';
409
+ return $link;
410
+ }
411
+
412
+ function cf7dtx_cf7com_links() {
413
+ $links = '<div class="cf7com-links">'
414
+ . '<a href="' . esc_url_raw( __( 'http://contactform7.com/', 'wpcf7' ) ) . '" target="_blank">'
415
+ . esc_html( __( 'Contactform7.com', 'wpcf7' ) ) . '</a>&ensp;'
416
+ . '<a href="' . esc_url_raw( __( 'http://contactform7.com/docs/', 'wpcf7' ) ) . '" target="_blank">'
417
+ . esc_html( __( 'Docs', 'wpcf7' ) ) . '</a> - '
418
+ . '<a href="' . esc_url_raw( __( 'http://contactform7.com/faq/', 'wpcf7' ) ) . '" target="_blank">'
419
+ . esc_html( __( 'FAQ', 'wpcf7' ) ) . '</a> - '
420
+ . '<a href="' . esc_url_raw( __( 'http://contactform7.com/support/', 'wpcf7' ) ) . '" target="_blank">'
421
+ . esc_html( __( 'Support', 'wpcf7' ) ) . '</a>'
422
+ . ' - <a href="'. esc_url_raw( __( 'http://sevenspark.com/wordpress-plugins/contact-form-7-dynamic-text-extension', 'wpcf7') )
423
+ . '" target="_blank">'.__( 'Dynamic Text Extension' , 'wpcf7').'</a> by <a href="' . esc_url_raw( __( 'http://sevenspark.com', 'wpcf7') ).'" target="_blank">'
424
+ . esc_html( __( 'SevenSpark', 'wpcf7' ) ). '</a> <a href="'.esc_url_raw( __('http://bit.ly/bVogDN')).'" target="_blank">'
425
+ . esc_html( __( '[Donate]')).'</a>'
426
+ . '</div>';
427
+ return $links;
428
+ }
429
+ add_filter('wpcf7_cf7com_links', 'cf7dtx_cf7com_links');
430
+
431
+ /*function obf($atts){
432
+ extract(shortcode_atts(array(
433
+ 'val' => ''
434
+ ), $atts));
435
+ return $val.' : '. cf7dtx_obfuscate($val);
436
+ }
437
+ add_shortcode('obf', 'obf');*/
438
+
trunk/readme.txt ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Contact Form 7 Dynamic Text Extension ===
2
+ Contributors: sevenspark
3
+ Donate link: http://bit.ly/bVogDN
4
+ Tags: Contact Form 7, Contact, Contact Form, dynamic, text, input, GET, POST, title, slug
5
+ Requires at least: 4.7
6
+ Tested up to: 4.7.1
7
+ Stable tag: 2.0.2
8
+
9
+ This plugin provides 2 new tag types for the Contact Form 7 Plugin. It allows the dynamic generation of content for a text input box via any shortcode.
10
+ It also offers dynamic hidden field functionality, which can be utilized to dynamically set the Email Recipient (To:) address.
11
+
12
+ == Description ==
13
+
14
+ Contact Form 7 is an excellent WordPress plugin, and the CF7 DTX Plugin makes it even more awesome by adding dynamic content capabilities.
15
+ While default values in Contact Form 7 are static. CF7 DTX lets you create pre-populated fields based on other values. Some examples might include:
16
+
17
+ * Auto-filling a URL
18
+ * Auto-filling a Post ID, title, or slug
19
+ * Pre-populating a Product Number
20
+ * Referencing other content on the site
21
+ * Populating with post info
22
+ * Populating with user info
23
+ * Populating with custom fields
24
+ * Any value you can write a shortcode for
25
+
26
+ There are many more case-specific examples. I searched for a solution, and there are some decent hacks out there. Many of them are
27
+ explored in this forum topic:
28
+ [Contact Form 7 Input Fields Values as PHP Get-Variables](http://wordpress.org/support/topic/contact-form-7-input-fields-values-as-php-get-viarables).
29
+ However, they all involved hacking the current Contact Form 7 code, which means next time the plugin is updated their edits will be
30
+ overwritten. That's bad.
31
+
32
+ This Dynamic Text Extension plugin provides a more elegant solution that leaves the Contact Form 7 Plugin intact.
33
+
34
+ = WHAT DOES IT DO? =
35
+
36
+ This plugin provides a new tag type for the Contact Form 7 Plugin. It allows the dynamic generation of content for a text input box via any shortcode.
37
+ For example, it comes with several built-in shortcodes that will allow the Contact Form to be populated from any $_GET PHP variable or any info from the
38
+ get_bloginfo() function, among others. See below for included shortcodes.
39
+
40
+ Don't see the shortcode you need on the list? You can write a custom one! Any shortcode that returns a string value can be used here. The included shortcodes just cover the most common scenarios, but the plugin provides the flexibility for you to grab any value you have access to programmatically.
41
+
42
+ = HOW TO USE IT =
43
+
44
+ After installing and activating the plugin, the Contact Form 7 tag generator will have 2 new tag types: Dynamic Text Field and Dynamic Hidden Field. Most of the options will be
45
+ familiar to Contact Form 7 users. There are two important fields:
46
+
47
+ **Dynamic Value**
48
+
49
+ This field takes a shortcode, with two important provisions:
50
+
51
+ 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' .
52
+ 2. Any parameters in the shortcode must use single quotes. That is: CF7_GET key='value' and not CF7_GET key="value"
53
+
54
+
55
+ **Uneditable Option**
56
+
57
+ As these types of fields should often remain uneditable by the user, there is a checkbox to turn this option on (Not applicable for hidden fields).
58
+
59
+
60
+ = INCLUDED SHORTCODES =
61
+
62
+ The plugin includes 2 basic shortcodes for use with the Dynamic Text extension. You can write your own as well - any shortcode will work
63
+
64
+ **PHP GET Variables**
65
+
66
+ 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
67
+ http://mysite.com?foo=bar
68
+
69
+ Enter the following into the "Dynamic Value" input
70
+
71
+ CF7_GET key='foo'
72
+
73
+ Your Content Form 7 Tag will look something like this:
74
+
75
+ [dynamictext dynamicname "CF7_GET key='foo'"]
76
+
77
+ Your form's dynamicname text input will then be pre-populated with the value of foo, in this case, bar
78
+
79
+
80
+ **PHP POST Variables**
81
+
82
+ New in version 1.0.3!
83
+
84
+ Grab variables from the $_POST array. The shortcode is much like the GET shortcode:
85
+
86
+ CF7_POST key='foo'
87
+
88
+ Your Content Form 7 Tag will look something like this:
89
+
90
+ [dynamictext dynamicname "CF7_POST key='foo'"]
91
+
92
+
93
+ **Blog Info**
94
+
95
+ Want to grab some information from your blog like the URL or the sitename? Use the CF7_bloginfo shortcode. For example, to get the site's URL:
96
+
97
+ Enter the following into the "Dynamic Value" input
98
+
99
+ CF7_bloginfo show='url'
100
+
101
+ Your Content Form 7 Tag will look something like this:
102
+
103
+ [dynamictext dynamicname "CF7_bloginfo show='url'"]
104
+
105
+ Your form's dynamicname text input will then be pre-populated with your site's URL
106
+
107
+
108
+ **Post Info**
109
+
110
+ New in version 1.0.3!
111
+
112
+ Retrieve information about the current post/page (that the contact form is displayed on). The shortcode works as follows:
113
+
114
+ CF7_get_post_var key='title' <-- retrieves the Post's Title
115
+ CF7_get_post_var key='slug' <-- retrieves the Post's Slug
116
+
117
+ You can also retrieve any parameter from the $post object. Just set that as the key value, for example 'post_date'
118
+
119
+ The Contact Form 7 Tag would look like:
120
+
121
+ [dynamictext dynamicname "CF7_get_post_var key='title'"]
122
+
123
+ **Current URL**
124
+
125
+ New in version 1.0.3!
126
+
127
+ Retrieve the current URL. The shortcode takes no parameters:
128
+
129
+ CF7_URL
130
+
131
+ So your Contact Form 7 Tag would look like:
132
+
133
+ [dynamictext dynamicname "CF7_URL"]
134
+
135
+ **Custom Fields**
136
+
137
+ New in version 1.0.4!
138
+
139
+ Retrieve custom fields from the current post/page. Just set the custom field as the key in the shortcode.
140
+
141
+ The dynamic value input becomes:
142
+
143
+ CF7_get_custom_field key='my_custom_field'
144
+
145
+ And the tag looks like this:
146
+
147
+ [dynamictext dynamicname "CF7_get_custom_field key='my_custom_field'"]
148
+
149
+ For the purposes of including an email address, you can obfuscate the custom field value by setting obfuscate='on' in the shortcode.
150
+
151
+ **Current User Info**
152
+
153
+ Get data about the current user - assuming they are logged in. Defaults to user name, but you can set the key to any valid value in
154
+ http://codex.wordpress.org/Function_Reference/get_currentuserinfo
155
+
156
+ CF7_get_current_user
157
+
158
+ [dynamictext dynamicname "CF7_get_current_user"]
159
+
160
+ **Referrer URL**
161
+
162
+ Get the referral URL, if it exists. Note that this is not necessarily reliable as not all browsers send this data.
163
+
164
+ [dynamictext dynamicname "CF7_referrer"]
165
+
166
+
167
+ Like the Dynamic Text Extension? Please consider supporting its development by [Donating](http://bit.ly/bVogDN).
168
+
169
+ Or check out my upcoming premium plugin, [UberMenu - WordPress Mega Menu Plugin](http://wpmegamenu.com)
170
+
171
+
172
+ == Installation ==
173
+
174
+ This section describes how to install the plugin and get it working.
175
+
176
+ 1. Download and install the Contact Form 7 Plugin located at http://wordpress.org/extend/plugins/contact-form-7/
177
+ 1. Upload the plugin folder to the '/wp-content/plugins/' directory
178
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
179
+ 1. You will now have a "Dynamic Text" tag option in the Contact Form 7 tag generator
180
+
181
+
182
+ == Frequently Asked Questions ==
183
+
184
+ None. Yet.
185
+
186
+
187
+ == Screenshots ==
188
+
189
+ 1. The new Dynamic Text Field options.
190
+
191
+
192
+ == Changelog ==
193
+
194
+ = 2.0.2 =
195
+
196
+ * Update deprecated get_currentuserinfo() function to wp_get_current_user()
197
+ * 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
198
+
199
+ = 2.0.1 =
200
+
201
+ * 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)
202
+
203
+ = 2.0 =
204
+
205
+ * Complete rewrite for Compatibility with Contact Form 7 v4
206
+
207
+ = 1.2 =
208
+ * Compatibility update for Contact Form 7 v3.9
209
+
210
+ = 1.1.0.2 =
211
+ * Updated to work with Contact Form 7 v3.7.x
212
+
213
+ = 1.1.0.1 =
214
+ * Removed undefined variable warning
215
+
216
+ = 1.1 =
217
+ * Updated for compatibility with Contact Form 7 v3.6
218
+ * Added Referrer shortcode
219
+
220
+ = 1.0.4.2 =
221
+ * Fixed a bug that created repeating square brackets around dynamic text values in cases where the form doesn't validate and JavaScript is deactivated.
222
+
223
+ = 1.0.4.1 =
224
+ * Removed trailing whitespace to fix "Headers already sent" errors
225
+
226
+ = 1.0.4 =
227
+ * Added Current User Info shortcode
228
+ * Added Post Custom Field shortcode (with obfuscation support)
229
+ * Added Hidden Field capability
230
+
231
+ = 1.0.3 =
232
+ * Added $_POST shortcode
233
+ * Added current post/page variable shortcode
234
+ * Added current URL shortcode
235
+
236
+ = 1.0.2 =
237
+ * Fixed administrative control panel dependency issue
238
+
239
+ = 1.0.1 =
240
+ * Fixed dependency issue.
241
+
242
+
243
+ == Upgrade Notice ==
244
+
245
+ 2.0 complete rewrite for compatibility with latest Contact Form 7
trunk/screenshot-1.jpg ADDED
Binary file