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 ); } add_action('wpcf7_admin_init', 'wpcf7dtx_add_tag_generator_dynamictext', 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 = '') { $options = wp_parse_args($options); $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; } $utm_source = urlencode(home_url()); $description .= sprintf( ' %s %s.', __('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') ); //Open Form-Tag Generator printf( '
%s', wp_kses($description, 'a') //Tag generator description ); //Input field - Required checkbox (not available for hidden fields) if ($type != 'dynamichidden') { printf( '', esc_attr($options['content'] . '-required'), // field id esc_html__('Field type', 'contact-form-7-dynamic-text-extension'), // field Label wpcf7_format_atts(array( 'type' => 'checkbox', 'name' => 'required', 'id' => $options['content'] . '-required' )), esc_html__('Required field', 'contact-form-7-dynamic-text-extension') // checkbox label ); } //Input field - Field Name printf( '', 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 - Dynamic value printf( '', esc_attr($options['content'] . '-values'), // field id esc_html__('Dynamic value', 'contact-form-7-dynamic-text-extension'), // field label wpcf7_format_atts(array( 'type' => 'text', 'name' => 'values', 'id' => $options['content'] . '-values', 'class' => 'oneline', 'placeholder' => "CF7_GET key='foo'" )), 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 ); //Input field - Dynamic placeholder (not available for hidden fields) if ($type != 'dynamichidden') { printf( '', esc_attr($options['content'] . '-placeholder'), // field id esc_html__('Dynamic placeholder', 'contact-form-7-dynamic-text-extension'), // 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\'' )), 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 placeholder documentation', 'contact-form-7-dynamic-text-extension') //Link label ); } //Input field - ID attribute printf( '', esc_attr($options['content'] . '-id'), // field id esc_html__('Id attribute', 'contact-form-7-dynamic-text-extension'), // field label wpcf7_format_atts(array( 'type' => 'text', 'name' => 'id', 'id' => $options['content'] . '-id', // field id 'class' => 'idvalue oneline option' )) ); //Input field - Class attribute printf( '', esc_attr($options['content'] . '-class'), // field id esc_html__('Class attribute', 'contact-form-7-dynamic-text-extension'), // field label wpcf7_format_atts(array( 'type' => 'text', 'name' => 'class', 'id' => $options['content'] . '-class', // field id 'class' => 'classvalue oneline option' )) ); //Input field - Readonly attribute (not available for hidden fields) if ($type != 'dynamichidden') { printf( '', esc_attr($options['content'] . '-readonly'), // field id esc_html__('Read only attribute', 'contact-form-7-dynamic-text-extension'), // field Label wpcf7_format_atts(array( 'type' => 'checkbox', 'name' => 'readonly', 'id' => $options['content'] . '-readonly', 'class' => 'readonlyvalue option' )), esc_html__('Do not let users edit this field', 'contact-form-7-dynamic-text-extension') // checkbox label ); } //Close Form-Tag Generator printf( '

%s %s

%s %s

', esc_attr($type), esc_html__('Insert Tag', 'contact-form-7-dynamic-text-extension') ); }